personal.js 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. /**
  2. * Copyright (c) 2011, Robin Appelman <icewind1991@gmail.com>
  3. * This file is licensed under the Affero General Public License version 3 or later.
  4. * See the COPYING-README file.
  5. */
  6. /**
  7. * Post the email address change to the server.
  8. */
  9. function changeEmailAddress(){
  10. var emailInfo = $('#email');
  11. if (emailInfo.val() === emailInfo.defaultValue){
  12. return;
  13. }
  14. emailInfo.defaultValue = emailInfo.val();
  15. OC.msg.startSaving('#lostpassword .msg');
  16. var post = $( "#lostpassword" ).serialize();
  17. $.post( 'ajax/lostpassword.php', post, function(data){
  18. OC.msg.finishedSaving('#lostpassword .msg', data);
  19. });
  20. }
  21. /**
  22. * Post the display name change to the server.
  23. */
  24. function changeDisplayName(){
  25. if ($('#displayName').val() !== '' ) {
  26. OC.msg.startSaving('#displaynameform .msg');
  27. // Serialize the data
  28. var post = $( "#displaynameform" ).serialize();
  29. // Ajax foo
  30. $.post( 'ajax/changedisplayname.php', post, function(data){
  31. if( data.status === "success" ){
  32. $('#oldDisplayName').val($('#displayName').val());
  33. // update displayName on the top right expand button
  34. $('#expandDisplayName').text($('#displayName').val());
  35. updateAvatar();
  36. }
  37. else{
  38. $('#newdisplayname').val(data.data.displayName);
  39. }
  40. OC.msg.finishedSaving('#displaynameform .msg', data);
  41. });
  42. return false;
  43. }
  44. }
  45. function updateAvatar (hidedefault) {
  46. $headerdiv = $('#header .avatardiv');
  47. $displaydiv = $('#displayavatar .avatardiv');
  48. if(hidedefault) {
  49. $headerdiv.hide();
  50. } else {
  51. $headerdiv.css({'background-color': ''});
  52. $headerdiv.avatar(OC.currentUser, 32, true);
  53. }
  54. $displaydiv.css({'background-color': ''});
  55. $displaydiv.avatar(OC.currentUser, 128, true);
  56. }
  57. function showAvatarCropper() {
  58. $cropper = $('#cropper');
  59. $cropper.prepend("<img>");
  60. $cropperImage = $('#cropper img');
  61. $cropperImage.attr('src', OC.Router.generate('core_avatar_get_tmp')+'?requesttoken='+oc_requesttoken+'#'+Math.floor(Math.random()*1000));
  62. // Looks weird, but on('load', ...) doesn't work in IE8
  63. $cropperImage.ready(function(){
  64. $('#displayavatar').hide();
  65. $cropper.show();
  66. $cropperImage.Jcrop({
  67. onChange: saveCoords,
  68. onSelect: saveCoords,
  69. aspectRatio: 1,
  70. boxHeight: 500,
  71. boxWidth: 500,
  72. setSelect: [0, 0, 300, 300]
  73. });
  74. });
  75. }
  76. function sendCropData() {
  77. cleanCropper();
  78. var cropperdata = $('#cropper').data();
  79. var data = {
  80. x: cropperdata.x,
  81. y: cropperdata.y,
  82. w: cropperdata.w,
  83. h: cropperdata.h
  84. };
  85. $.post(OC.Router.generate('core_avatar_post_cropped'), {crop: data}, avatarResponseHandler);
  86. }
  87. function saveCoords(c) {
  88. $('#cropper').data(c);
  89. }
  90. function cleanCropper() {
  91. $cropper = $('#cropper');
  92. $('#displayavatar').show();
  93. $cropper.hide();
  94. $('.jcrop-holder').remove();
  95. $('#cropper img').removeData('Jcrop').removeAttr('style').removeAttr('src');
  96. $('#cropper img').remove();
  97. }
  98. function avatarResponseHandler(data) {
  99. $warning = $('#avatar .warning');
  100. $warning.hide();
  101. if (data.status === "success") {
  102. updateAvatar();
  103. } else if (data.data === "notsquare") {
  104. showAvatarCropper();
  105. } else {
  106. $warning.show();
  107. $warning.text(data.data.message);
  108. }
  109. }
  110. $(document).ready(function(){
  111. $("#passwordbutton").click( function(){
  112. if ($('#pass1').val() !== '' && $('#pass2').val() !== '') {
  113. // Serialize the data
  114. var post = $( "#passwordform" ).serialize();
  115. $('#passwordchanged').hide();
  116. $('#passworderror').hide();
  117. // Ajax foo
  118. $.post(OC.Router.generate('settings_personal_changepassword'), post, function(data){
  119. if( data.status === "success" ){
  120. $('#pass1').val('');
  121. $('#pass2').val('');
  122. $('#passwordchanged').show();
  123. } else{
  124. if (typeof(data.data) !== "undefined") {
  125. $('#passworderror').html(data.data.message);
  126. } else {
  127. $('#passworderror').html(t('Unable to change password'));
  128. }
  129. $('#passworderror').show();
  130. }
  131. });
  132. return false;
  133. } else {
  134. $('#passwordchanged').hide();
  135. $('#passworderror').show();
  136. return false;
  137. }
  138. });
  139. $('#displayName').keyup(function(){
  140. if ($('#displayName').val() !== '' ){
  141. if(typeof timeout !== 'undefined'){
  142. clearTimeout(timeout);
  143. }
  144. timeout = setTimeout('changeDisplayName()',1000);
  145. }
  146. });
  147. $('#email').keyup(function(){
  148. if ($('#email').val() !== '' ){
  149. if(typeof timeout !== 'undefined'){
  150. clearTimeout(timeout);
  151. }
  152. timeout = setTimeout('changeEmailAddress()',1000);
  153. }
  154. });
  155. $("#languageinput").change( function(){
  156. // Serialize the data
  157. var post = $( "#languageinput" ).serialize();
  158. // Ajax foo
  159. $.post( 'ajax/setlanguage.php', post, function(data){
  160. if( data.status === "success" ){
  161. location.reload();
  162. }
  163. else{
  164. $('#passworderror').html( data.data.message );
  165. }
  166. });
  167. return false;
  168. });
  169. $('button:button[name="submitDecryptAll"]').click(function() {
  170. var privateKeyPassword = $('#decryptAll input:password[id="privateKeyPassword"]').val();
  171. OC.Encryption.decryptAll(privateKeyPassword);
  172. });
  173. $('#decryptAll input:password[name="privateKeyPassword"]').keyup(function(event) {
  174. var privateKeyPassword = $('#decryptAll input:password[id="privateKeyPassword"]').val();
  175. if (privateKeyPassword !== '' ) {
  176. $('#decryptAll button:button[name="submitDecryptAll"]').removeAttr("disabled");
  177. if(event.which === 13) {
  178. OC.Encryption.decryptAll(privateKeyPassword);
  179. }
  180. } else {
  181. $('#decryptAll button:button[name="submitDecryptAll"]').attr("disabled", "true");
  182. }
  183. });
  184. var uploadparms = {
  185. done: function(e, data) {
  186. avatarResponseHandler(data.result);
  187. }
  188. };
  189. $('#uploadavatarbutton').click(function(){
  190. $('#uploadavatar').click();
  191. });
  192. $('#uploadavatar').fileupload(uploadparms);
  193. $('#selectavatar').click(function(){
  194. OC.dialogs.filepicker(
  195. t('settings', "Select a profile picture"),
  196. function(path){
  197. $.post(OC.Router.generate('core_avatar_post'), {path: path}, avatarResponseHandler);
  198. },
  199. false,
  200. ["image/png", "image/jpeg"]
  201. );
  202. });
  203. $('#removeavatar').click(function(){
  204. $.ajax({
  205. type: 'DELETE',
  206. url: OC.Router.generate('core_avatar_delete'),
  207. success: function(msg) {
  208. updateAvatar(true);
  209. }
  210. });
  211. });
  212. $('#abortcropperbutton').click(function(){
  213. cleanCropper();
  214. });
  215. $('#sendcropperbutton').click(function(){
  216. sendCropData();
  217. });
  218. } );
  219. OC.Encryption = {
  220. decryptAll: function(password) {
  221. OC.Encryption.msg.startDecrypting('#decryptAll .msg');
  222. $.post('ajax/decryptall.php', {password:password}, function(data) {
  223. if (data.status === "error") {
  224. OC.Encryption.msg.finishedDecrypting('#decryptAll .msg', data);
  225. } else {
  226. OC.Encryption.msg.finishedDecrypting('#decryptAll .msg', data);
  227. }
  228. }
  229. );
  230. }
  231. }
  232. OC.Encryption.msg={
  233. startDecrypting:function(selector){
  234. $(selector)
  235. .html( t('files_encryption', 'Decrypting files... Please wait, this can take some time.') )
  236. .removeClass('success')
  237. .removeClass('error')
  238. .stop(true, true)
  239. .show();
  240. },
  241. finishedDecrypting:function(selector, data){
  242. if( data.status === "success" ){
  243. $(selector).html( data.data.message )
  244. .addClass('success')
  245. .stop(true, true)
  246. .delay(3000)
  247. .fadeOut(900);
  248. }else{
  249. $(selector).html( data.data.message ).addClass('error');
  250. }
  251. }
  252. };
  253. OC.msg={
  254. startSaving:function(selector){
  255. $(selector)
  256. .html( t('settings', 'Saving...') )
  257. .removeClass('success')
  258. .removeClass('error')
  259. .stop(true, true)
  260. .show();
  261. },
  262. finishedSaving:function(selector, data){
  263. if( data.status === "success" ){
  264. $(selector).html( data.data.message )
  265. .addClass('success')
  266. .stop(true, true)
  267. .delay(3000)
  268. .fadeOut(900);
  269. }else{
  270. $(selector).html( data.data.message ).addClass('error');
  271. }
  272. }
  273. };