Blame view
sources/settings/js/personal.js
10.5 KB
|
03e52840d
|
1 2 |
/** * Copyright (c) 2011, Robin Appelman <icewind1991@gmail.com> |
|
6d9380f96
|
3 |
* 2013, Morris Jobke <morris.jobke@gmail.com> |
|
03e52840d
|
4 5 6 |
* This file is licensed under the Affero General Public License version 3 or later. * See the COPYING-README file. */ |
|
6d9380f96
|
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
/* global OC, t */
/**
* The callback will be fired as soon as enter is pressed by the
* user or 1 second after the last data entry
*
* @param callback
*/
jQuery.fn.keyUpDelayedOrEnter = function(callback){
var cb = callback;
var that = this;
this.keyup(_.debounce(function (event) {
// enter is already handled in keypress
if(event.keyCode === 13) {
return;
}
if (that.val() !== '') {
cb();
}
}, 1000));
this.keypress(function (event) {
if (event.keyCode === 13 && that.val() !== '' ){
event.preventDefault();
cb();
}
});
};
|
|
31b7f2792
|
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
/**
* Post the email address change to the server.
*/
function changeEmailAddress(){
var emailInfo = $('#email');
if (emailInfo.val() === emailInfo.defaultValue){
return;
}
emailInfo.defaultValue = emailInfo.val();
OC.msg.startSaving('#lostpassword .msg');
var post = $( "#lostpassword" ).serialize();
$.post( 'ajax/lostpassword.php', post, function(data){
OC.msg.finishedSaving('#lostpassword .msg', data);
});
}
/**
* Post the display name change to the server.
*/
function changeDisplayName(){
if ($('#displayName').val() !== '' ) {
OC.msg.startSaving('#displaynameform .msg');
// Serialize the data
var post = $( "#displaynameform" ).serialize();
// Ajax foo
$.post( 'ajax/changedisplayname.php', post, function(data){
if( data.status === "success" ){
$('#oldDisplayName').val($('#displayName').val());
// update displayName on the top right expand button
$('#expandDisplayName').text($('#displayName').val());
updateAvatar();
}
else{
$('#newdisplayname').val(data.data.displayName);
}
OC.msg.finishedSaving('#displaynameform .msg', data);
});
|
|
31b7f2792
|
72 73 74 75 |
}
}
function updateAvatar (hidedefault) {
|
|
6d9380f96
|
76 77 |
var $headerdiv = $('#header .avatardiv');
var $displaydiv = $('#displayavatar .avatardiv');
|
|
31b7f2792
|
78 79 80 |
if(hidedefault) {
$headerdiv.hide();
|
|
6d9380f96
|
81 |
$('#header .avatardiv').removeClass('avatardiv-shown');
|
|
31b7f2792
|
82 83 84 |
} else {
$headerdiv.css({'background-color': ''});
$headerdiv.avatar(OC.currentUser, 32, true);
|
|
6d9380f96
|
85 |
$('#header .avatardiv').addClass('avatardiv-shown');
|
|
31b7f2792
|
86 87 88 |
}
$displaydiv.css({'background-color': ''});
$displaydiv.avatar(OC.currentUser, 128, true);
|
|
6d9380f96
|
89 90 |
$('#removeavatar').show();
|
|
31b7f2792
|
91 92 93 |
}
function showAvatarCropper() {
|
|
6d9380f96
|
94 |
var $cropper = $('#cropper');
|
|
31b7f2792
|
95 |
$cropper.prepend("<img>");
|
|
6d9380f96
|
96 |
var $cropperImage = $('#cropper img');
|
|
31b7f2792
|
97 |
|
|
6d9380f96
|
98 99 |
$cropperImage.attr('src',
OC.generateUrl('/avatar/tmp')+'?requesttoken='+oc_requesttoken+'#'+Math.floor(Math.random()*1000));
|
|
31b7f2792
|
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
// Looks weird, but on('load', ...) doesn't work in IE8
$cropperImage.ready(function(){
$('#displayavatar').hide();
$cropper.show();
$cropperImage.Jcrop({
onChange: saveCoords,
onSelect: saveCoords,
aspectRatio: 1,
boxHeight: 500,
boxWidth: 500,
setSelect: [0, 0, 300, 300]
});
});
}
function sendCropData() {
cleanCropper();
|
|
6d9380f96
|
119 |
var cropperData = $('#cropper').data();
|
|
31b7f2792
|
120 |
var data = {
|
|
6d9380f96
|
121 122 123 124 |
x: cropperData.x, y: cropperData.y, w: cropperData.w, h: cropperData.h |
|
31b7f2792
|
125 |
}; |
|
6d9380f96
|
126 |
$.post(OC.generateUrl('/avatar/cropped'), {crop: data}, avatarResponseHandler);
|
|
31b7f2792
|
127 128 129 130 131 132 133 |
}
function saveCoords(c) {
$('#cropper').data(c);
}
function cleanCropper() {
|
|
6d9380f96
|
134 |
var $cropper = $('#cropper');
|
|
31b7f2792
|
135 136 137 138 139 140 141 142 |
$('#displayavatar').show();
$cropper.hide();
$('.jcrop-holder').remove();
$('#cropper img').removeData('Jcrop').removeAttr('style').removeAttr('src');
$('#cropper img').remove();
}
function avatarResponseHandler(data) {
|
|
6d9380f96
|
143 |
var $warning = $('#avatar .warning');
|
|
31b7f2792
|
144 145 146 147 148 149 150 151 152 153 |
$warning.hide();
if (data.status === "success") {
updateAvatar();
} else if (data.data === "notsquare") {
showAvatarCropper();
} else {
$warning.show();
$warning.text(data.data.message);
}
}
|
|
03e52840d
|
154 155 |
$(document).ready(function(){
$("#passwordbutton").click( function(){
|
|
31b7f2792
|
156 |
if ($('#pass1').val() !== '' && $('#pass2').val() !== '') {
|
|
03e52840d
|
157 158 159 160 161 |
// Serialize the data
var post = $( "#passwordform" ).serialize();
$('#passwordchanged').hide();
$('#passworderror').hide();
// Ajax foo
|
|
6d9380f96
|
162 |
$.post(OC.generateUrl('/settings/personal/changepassword'), post, function(data){
|
|
31b7f2792
|
163 |
if( data.status === "success" ){
|
|
03e52840d
|
164 165 166 |
$('#pass1').val('');
$('#pass2').val('');
$('#passwordchanged').show();
|
|
31b7f2792
|
167 168 169 170 171 172 |
} else{
if (typeof(data.data) !== "undefined") {
$('#passworderror').html(data.data.message);
} else {
$('#passworderror').html(t('Unable to change password'));
}
|
|
03e52840d
|
173 174 175 176 177 178 179 180 181 182 183 |
$('#passworderror').show();
}
});
return false;
} else {
$('#passwordchanged').hide();
$('#passworderror').show();
return false;
}
});
|
|
6d9380f96
|
184 185 |
$('#displayName').keyUpDelayedOrEnter(changeDisplayName);
$('#email').keyUpDelayedOrEnter(changeEmailAddress);
|
|
03e52840d
|
186 187 188 189 190 191 |
$("#languageinput").change( function(){
// Serialize the data
var post = $( "#languageinput" ).serialize();
// Ajax foo
$.post( 'ajax/setlanguage.php', post, function(data){
|
|
31b7f2792
|
192 |
if( data.status === "success" ){
|
|
03e52840d
|
193 194 195 196 197 198 199 200 |
location.reload();
}
else{
$('#passworderror').html( data.data.message );
}
});
return false;
});
|
|
31b7f2792
|
201 202 203 |
$('button:button[name="submitDecryptAll"]').click(function() {
var privateKeyPassword = $('#decryptAll input:password[id="privateKeyPassword"]').val();
|
|
a293d369c
|
204 205 |
$('#decryptAll button:button[name="submitDecryptAll"]').prop("disabled", true);
$('#decryptAll input:password[name="privateKeyPassword"]').prop("disabled", true);
|
|
31b7f2792
|
206 207 |
OC.Encryption.decryptAll(privateKeyPassword); }); |
|
6d9380f96
|
208 209 210 211 212 213 214 215 216 217 218 219 |
$('button:button[name="submitRestoreKeys"]').click(function() {
$('#restoreBackupKeys button:button[name="submitDeleteKeys"]').prop("disabled", true);
$('#restoreBackupKeys button:button[name="submitRestoreKeys"]').prop("disabled", true);
OC.Encryption.restoreKeys();
});
$('button:button[name="submitDeleteKeys"]').click(function() {
$('#restoreBackupKeys button:button[name="submitDeleteKeys"]').prop("disabled", true);
$('#restoreBackupKeys button:button[name="submitRestoreKeys"]').prop("disabled", true);
OC.Encryption.deleteKeys();
});
|
|
31b7f2792
|
220 221 222 |
$('#decryptAll input:password[name="privateKeyPassword"]').keyup(function(event) {
var privateKeyPassword = $('#decryptAll input:password[id="privateKeyPassword"]').val();
if (privateKeyPassword !== '' ) {
|
|
6d9380f96
|
223 |
$('#decryptAll button:button[name="submitDecryptAll"]').prop("disabled", false);
|
|
31b7f2792
|
224 |
if(event.which === 13) {
|
|
a293d369c
|
225 226 |
$('#decryptAll button:button[name="submitDecryptAll"]').prop("disabled", true);
$('#decryptAll input:password[name="privateKeyPassword"]').prop("disabled", true);
|
|
31b7f2792
|
227 228 229 |
OC.Encryption.decryptAll(privateKeyPassword);
}
} else {
|
|
6d9380f96
|
230 |
$('#decryptAll button:button[name="submitDecryptAll"]').prop("disabled", true);
|
|
31b7f2792
|
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 |
}
});
var uploadparms = {
done: function(e, data) {
avatarResponseHandler(data.result);
}
};
$('#uploadavatarbutton').click(function(){
$('#uploadavatar').click();
});
$('#uploadavatar').fileupload(uploadparms);
$('#selectavatar').click(function(){
OC.dialogs.filepicker(
t('settings', "Select a profile picture"),
function(path){
|
|
6d9380f96
|
250 |
$.post(OC.generateUrl('/avatar/'), {path: path}, avatarResponseHandler);
|
|
31b7f2792
|
251 252 253 254 255 256 257 258 259 |
},
false,
["image/png", "image/jpeg"]
);
});
$('#removeavatar').click(function(){
$.ajax({
type: 'DELETE',
|
|
6d9380f96
|
260 261 |
url: OC.generateUrl('/avatar/'),
success: function() {
|
|
31b7f2792
|
262 |
updateAvatar(true); |
|
6d9380f96
|
263 |
$('#removeavatar').hide();
|
|
31b7f2792
|
264 265 266 267 268 269 270 271 272 273 274 |
}
});
});
$('#abortcropperbutton').click(function(){
cleanCropper();
});
$('#sendcropperbutton').click(function(){
sendCropData();
});
|
|
6d9380f96
|
275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 |
$('#pass2').strengthify({
zxcvbn: OC.linkTo('3rdparty','zxcvbn/js/zxcvbn.js'),
titles: [
t('core', 'Very weak password'),
t('core', 'Weak password'),
t('core', 'So-so password'),
t('core', 'Good password'),
t('core', 'Strong password')
]
});
// does the user have a custom avatar? if he does hide #removeavatar
// needs to be this complicated because we can't check yet if an avatar has been loaded, because it's async
var url = OC.generateUrl(
'/avatar/{user}/{size}',
{user: OC.currentUser, size: 1}
) + '?requesttoken=' + oc_requesttoken;
$.get(url, function(result) {
if (typeof(result) === 'object') {
$('#removeavatar').hide();
}
});
|
|
03e52840d
|
298 |
} ); |
|
31b7f2792
|
299 300 |
OC.Encryption = {
decryptAll: function(password) {
|
|
6d9380f96
|
301 302 |
var message = t('settings', 'Decrypting files... Please wait, this can take some time.');
OC.Encryption.msg.start('#decryptAll .msg', message);
|
|
31b7f2792
|
303 304 |
$.post('ajax/decryptall.php', {password:password}, function(data) {
if (data.status === "error") {
|
|
6d9380f96
|
305 306 |
OC.Encryption.msg.finished('#decryptAll .msg', data);
$('#decryptAll input:password[name="privateKeyPassword"]').prop("disabled", false);
|
|
31b7f2792
|
307 |
} else {
|
|
6d9380f96
|
308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 |
OC.Encryption.msg.finished('#decryptAll .msg', data);
}
$('#restoreBackupKeys').removeClass('hidden');
});
},
deleteKeys: function() {
var message = t('settings', 'Delete encryption keys permanently.');
OC.Encryption.msg.start('#restoreBackupKeys .msg', message);
$.post('ajax/deletekeys.php', null, function(data) {
if (data.status === "error") {
OC.Encryption.msg.finished('#restoreBackupKeys .msg', data);
$('#restoreBackupKeys button:button[name="submitDeleteKeys"]').prop("disabled", false);
$('#restoreBackupKeys button:button[name="submitRestoreKeys"]').prop("disabled", false);
} else {
OC.Encryption.msg.finished('#restoreBackupKeys .msg', data);
}
});
},
restoreKeys: function() {
var message = t('settings', 'Restore encryption keys.');
OC.Encryption.msg.start('#restoreBackupKeys .msg', message);
$.post('ajax/restorekeys.php', {}, function(data) {
if (data.status === "error") {
OC.Encryption.msg.finished('#restoreBackupKeys .msg', data);
$('#restoreBackupKeys button:button[name="submitDeleteKeys"]').prop("disabled", false);
$('#restoreBackupKeys button:button[name="submitRestoreKeys"]').prop("disabled", false);
} else {
OC.Encryption.msg.finished('#restoreBackupKeys .msg', data);
|
|
31b7f2792
|
338 |
} |
|
a293d369c
|
339 |
}); |
|
31b7f2792
|
340 |
} |
|
a293d369c
|
341 |
}; |
|
31b7f2792
|
342 343 |
OC.Encryption.msg={
|
|
6d9380f96
|
344 |
start:function(selector, msg){
|
|
31b7f2792
|
345 346 |
var spinner = '<img src="'+ OC.imagePath('core', 'loading-small.gif') +'">';
$(selector)
|
|
6d9380f96
|
347 |
.html( msg + ' ' + spinner ) |
|
31b7f2792
|
348 349 350 351 352 |
.removeClass('success')
.removeClass('error')
.stop(true, true)
.show();
},
|
|
6d9380f96
|
353 |
finished:function(selector, data){
|
|
31b7f2792
|
354 |
if( data.status === "success" ){
|
|
6d9380f96
|
355 |
$(selector).html( data.data.message ) |
|
31b7f2792
|
356 357 358 359 360 361 362 363 |
.addClass('success')
.stop(true, true)
.delay(3000);
}else{
$(selector).html( data.data.message ).addClass('error');
}
}
};
|