account.html 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426
  1. <html xmlns:th="http://www.thymeleaf.org">
  2. <script type="text/javascript">
  3. // USER: name
  4. $("#nameInput").keyup(function() {
  5. $("#updateNameButton").attr("disabled", false);
  6. });
  7. $("#updateNameButton").click(function() {
  8. var jsonData = { name: $("#nameInput").val() };
  9. var jsonString = JSON.stringify(jsonData);
  10. var success = function() {
  11. $("#nameInputDiv").removeClass("error");
  12. $("#updateUsernameButton").attr("disabled", true);
  13. $("#nameInput").transition("glow");
  14. };
  15. var error = function() {
  16. $("#nameInputDiv").addClass("error");
  17. };
  18. postJsonAjax("/user/preferences/update/name/", jsonString, success, error);
  19. });
  20. // USER: username
  21. $("#usernameInput").keyup(function() {
  22. $("#updateUsernameButton").attr("disabled", false);
  23. });
  24. $("#updateUsernameButton").click(function() {
  25. var jsonData = { username: $("#usernameInput").val() };
  26. var jsonString = JSON.stringify(jsonData);
  27. var success = function() {
  28. $("#usernameInputDiv").removeClass("error");
  29. $("#updateUsernameButton").attr("disabled", true);
  30. $("#usernameInput").transition("glow");
  31. };
  32. var error = function() {
  33. $("#usernameInputDiv").addClass("error");
  34. };
  35. postJsonAjax("/user/preferences/update/name/", jsonString, success, error);
  36. });
  37. // utility functions
  38. function postJsonAjax(serverUrl, jsonData, successFunction, errorFunction) {
  39. $.ajax({
  40. url: serverUrl,
  41. type: "POST",
  42. contentType: "application/json; charset=utf-8",
  43. data: jsonData,
  44. cache: false,
  45. processData: false,
  46. success: successFunction,
  47. error: errorFunction
  48. });
  49. }
  50. // popups
  51. $("#usernameInput").popup();
  52. $("#changeEmailButton").popup();
  53. $("#changePasswordButton").popup();
  54. </script>
  55. <div>
  56. <h1 class="ui header">Account</h1>
  57. <div class="ui divider"></div>
  58. <table class="ui compact celled very basic table">
  59. <tbody>
  60. <tr>
  61. <td class="collapsing">Name</td>
  62. <td class="collapsing">
  63. <div id="nameInputDiv" class="ui input">
  64. <input id="nameInput" type="text" th:value="${user.name}" />
  65. </div>
  66. </td>
  67. <td>
  68. <button id="updateNameButton" class="tiny ui button" disabled><i class="pencil alternate icon"></i>Change</button>
  69. </td>
  70. </tr>
  71. <tr>
  72. <td class="collapsing">Username</td>
  73. <td class="collapsing">
  74. <div id="usernameInputDiv" class="ui input">
  75. <input
  76. id="usernameInput"
  77. type="text"
  78. th:value="${user.username}"
  79. th:attr="data-content='People can mention you as @' + ${user.username}"
  80. />
  81. </div>
  82. </td>
  83. <td>
  84. <button id="updateUsernameButton" class="tiny ui button" disabled><i class="pencil alternate icon"></i>Change</button>
  85. </td>
  86. </tr>
  87. <tr>
  88. <td class="collapsing">Email</td>
  89. <td class="collapsing">
  90. <div class="ui input">
  91. <input id="usernameInput" type="text" th:value="${user.email}" />
  92. </div>
  93. </td>
  94. <td>
  95. <button id="changeEmailButton" data-content="We'll send you an email to confirm this change." class="tiny ui button">
  96. <i class="envelope outline icon"></i>Send Request
  97. </button>
  98. </td>
  99. </tr>
  100. <tr>
  101. <td class="collapsing">Password</td>
  102. <td>
  103. <button
  104. id="changePasswordButton"
  105. data-content="We'll send you an email with a link to change your password."
  106. class="tiny orange ui button"
  107. >
  108. <i class="key icon"></i>Send Request
  109. </button>
  110. </td>
  111. </tr>
  112. </tbody>
  113. </table>
  114. <div class="ui divider"></div>
  115. <h2 class="ui header">Profile Picture</h2>
  116. <img class="ui middle aligned circular image" th:src="@{|/image/${user.avatarId}}" />
  117. <div class="ui small buttons">
  118. <button id="systemManagedAvatarButton" class="ui button black">System Managed</button>
  119. <div class="or"></div>
  120. <button id="gravatarAvatarButton" class="ui button blue">Gravatar</button>
  121. <div class="or"></div>
  122. <button id="customImageAvatarButton" class="ui button purple">Custom Image</button>
  123. </div>
  124. <div class="ui modal small" id="changeAvatarModal">
  125. <div class="header"><i class="user circle outline icon"></i>Change Avatar</div>
  126. <div class="ui content">
  127. <div class="ui list">
  128. <div class="item">
  129. <img class="ui avatar image" th:src="${avatar}" />
  130. <div class="content">
  131. <a class="header systemAssignedAvatarLink">System Assigned</a>
  132. <div class="description">Create an avatar using your initials from your name or username.</div>
  133. </div>
  134. </div>
  135. <div class="item">
  136. <img class="ui avatar image" src="/images/icons/gravatar-32x32.png" />
  137. <div class="content">
  138. <a class="header gravatarAvatarLink">Gravatar</a>
  139. <div class="description">Use gravatar based on your email address.</div>
  140. </div>
  141. </div>
  142. <div class="item">
  143. <img class="ui avatar image" th:src="@{|/image/${user.avatarId}}" />
  144. <div class="content">
  145. <a class="header customAvatarLink">Custom</a>
  146. <div class="description">Upload a custom image.</div>
  147. </div>
  148. </div>
  149. </div>
  150. </div>
  151. <div class="actions">
  152. <div class="ui red cancel button">
  153. <i class="remove icon"></i>
  154. Cancel
  155. </div>
  156. </div>
  157. </div>
  158. <div class="ui modal small" id="systemAssignedAvatarModal">
  159. <div class="header"><i class="user circle outline icon"></i>Change Avatar > System Assigned Avatar</div>
  160. <div class="ui content">
  161. <div class="ui grid">
  162. <div class="four wide column">
  163. <table class="ui compact very basic table">
  164. <tbody>
  165. <tr>
  166. <td class="collapsing">
  167. <div id="backgroundColorSelector" class="colorSelector"><div style="background-color: #dddddd"></div></div>
  168. </td>
  169. <td><i class="eye dropper icon"></i></td>
  170. </tr>
  171. <tr>
  172. <td class="collapsing">
  173. <div id="fontColorSelector" class="colorSelector"><div style="background-color: #222222"></div></div>
  174. </td>
  175. <td><i class="font icon"></i></td>
  176. </tr>
  177. <tr>
  178. <td class="collapsing">
  179. <div class="ui fitted slider checkbox" style="vertical-align: middle;">
  180. <input id="uppercaseSystemAvatar" type="checkbox" /> <label></label>
  181. </div>
  182. </td>
  183. <td><i class="arrow alternate circle up outline icon"></i></td>
  184. </tr>
  185. <tr>
  186. <td class="collapsing">
  187. <div class="ui fitted slider checkbox" style="vertical-align: middle;">
  188. <input id="boldSystemAvatar" type="checkbox" /> <label></label>
  189. </div>
  190. </td>
  191. <td><i class="bold icon"></i></td>
  192. </tr>
  193. </tbody>
  194. </table>
  195. </div>
  196. <div class="twelve wide column">
  197. <img id="systemAssignedPreview" class="ui image" th:src="@{|/image/${user.avatarId}}" />
  198. <br />
  199. <button id="updateSystemAssignedAvatar" class="ui button">Preview Changes</button>
  200. </div>
  201. </div>
  202. </div>
  203. <style type="text/css">
  204. .colorSelector {
  205. position: relative;
  206. width: 36px;
  207. height: 36px;
  208. /*background: url(/libs/colorpicker/images/select.png);*/
  209. float: left;
  210. }
  211. .colorSelector div {
  212. position: absolute;
  213. top: 3px;
  214. left: 3px;
  215. width: 30px;
  216. height: 30px;
  217. background: url(/libs/colorpicker/images/select.png) center;
  218. }
  219. .colorpicker {
  220. z-index: 9999;
  221. }
  222. </style>
  223. <script type="text/javascript" th:inline="javascript">
  224. var bgColor = "";
  225. var fgColor = "";
  226. var useBold = false;
  227. var useUppercase = true;
  228. var user_name = /*[[${user.name}]]*/ "";
  229. var user_username = /*[[${user.username}]]*/ "";
  230. var usedName = !user_name || user_name.length == 0 ? user_username : user_name;
  231. usedName = encodeURIComponent(usedName);
  232. function updateSystemAssignedAvatar() {
  233. var url = "https://ui-avatars.com/api/" + "?name=" + usedName + "&size=128";
  234. if (bgColor.length > 0) url += "&background=" + bgColor;
  235. if (fgColor.length > 0) url += "&color=" + fgColor;
  236. url += "&bold=" + useBold;
  237. url += "&uppercase=" + useUppercase;
  238. $("#systemAssignedPreview").attr("src", url);
  239. }
  240. $("#backgroundColorSelector").ColorPicker({
  241. color: "#dddddd",
  242. onShow: function(colpkr) {
  243. $(colpkr).fadeIn(100);
  244. return false;
  245. },
  246. onHide: function(colpkr) {
  247. $(colpkr).fadeOut(100);
  248. return false;
  249. },
  250. onChange: function(hsb, hex, rgb) {
  251. $("#backgroundColorSelector div").css("backgroundColor", "#" + hex);
  252. bgColor = hex;
  253. //updateSystemAssignedAvatar();
  254. }
  255. });
  256. $("#fontColorSelector").ColorPicker({
  257. color: "#222222",
  258. onShow: function(colpkr) {
  259. $(colpkr).fadeIn(100);
  260. return false;
  261. },
  262. onHide: function(colpkr) {
  263. $(colpkr).fadeOut(100);
  264. return false;
  265. },
  266. onChange: function(hsb, hex, rgb) {
  267. $("#fontColorSelector div").css("backgroundColor", "#" + hex);
  268. fgColor = hex;
  269. //updateSystemAssignedAvatar();
  270. }
  271. });
  272. $("#uppercaseSystemAvatar").click(function() {
  273. useUppercase = $(this).is(":checked");
  274. });
  275. $("#boldSystemAvatar").click(function() {
  276. useBold = $(this).is(":checked");
  277. });
  278. $("#updateSystemAssignedAvatar").click(function() {
  279. updateSystemAssignedAvatar();
  280. });
  281. </script>
  282. <div class="actions">
  283. <div class="ui red cancel button">
  284. <i class="remove icon"></i>
  285. Cancel
  286. </div>
  287. <div class="ui green ok button">
  288. <i class="check icon"></i>
  289. Save Changes
  290. </div>
  291. </div>
  292. </div>
  293. <div class="ui modal small" id="gravatarAvatarModal">
  294. <div class="header"><i class="user circle outline icon"></i>Change Avatar > Gravatar</div>
  295. <div class="ui content">
  296. Gravatar Modal
  297. </div>
  298. <div class="actions">
  299. <div class="ui red cancel button">
  300. <i class="remove icon"></i>
  301. Cancel
  302. </div>
  303. <div class="ui green ok button">
  304. <i class="check icon"></i>
  305. Ok
  306. </div>
  307. </div>
  308. </div>
  309. <div class="ui modal small" id="customAvatarModal">
  310. <div class="header"><i class="user circle outline icon"></i>Change Avatar > Custom</div>
  311. <div class="ui content">
  312. Custom Modal
  313. </div>
  314. <div class="actions">
  315. <div class="ui red cancel button">
  316. <i class="remove icon"></i>
  317. Cancel
  318. </div>
  319. <div class="ui green ok button">
  320. <i class="check icon"></i>
  321. Ok
  322. </div>
  323. </div>
  324. </div>
  325. <script type="text/javascript">
  326. $("#systemAssignedAvatarModal ,#gravatarAvatarModal, #customAvatarModal")
  327. .modal({ blurring: true })
  328. .modal("setting", "transition", "scale");
  329. $("#systemManagedAvatarButton").click(function() {
  330. $("#systemAssignedAvatarModal").modal("show");
  331. });
  332. $("#gravatarAvatarButton").click(function() {
  333. $("#gravatarAvatarModal").modal("show");
  334. });
  335. $("#customImageAvatarButton").click(function() {
  336. $("#customAvatarModal").modal("show");
  337. });
  338. $("#systemAssignedAvatarModal").modal({
  339. onApprove: function() {
  340. var extUrl = $("#systemAssignedPreview").prop("src");
  341. var data = {
  342. backgroundColor: bgColor,
  343. foregroundColor: fgColor,
  344. bold: useBold,
  345. uppercase: useUppercase
  346. };
  347. var jsonString = JSON.stringify(data);
  348. $.ajax({
  349. url: "/avatar/system-managed/",
  350. type: "POST",
  351. contentType: "application/json; charset=utf-8",
  352. data: jsonString,
  353. cache: false,
  354. processData: false,
  355. success: function() {
  356. window.alert("Success");
  357. }
  358. });
  359. }
  360. });
  361. </script>
  362. </div>
  363. </html>