Merge pull request #8088 from owncloud/fix-personal.js

reduce code duplication, fix parse error, prevent page reload on hitting...
This commit is contained in:
Thomas Müller 2014-04-07 16:59:32 +02:00
commit 1e559f7239
5 changed files with 1396 additions and 52 deletions

View File

@ -23,6 +23,7 @@
"beforeEach": true, "beforeEach": true,
"afterEach": true, "afterEach": true,
"sinon": true, "sinon": true,
"fakeServer": true "fakeServer": true,
"_": true
} }
} }

View File

@ -6,7 +6,8 @@
"jquery-showpassword.js", "jquery-showpassword.js",
"jquery.infieldlabel.js", "jquery.infieldlabel.js",
"jquery.placeholder.js", "jquery.placeholder.js",
"jquery-tipsy.js" "jquery-tipsy.js",
"underscore.js"
], ],
"modules": [ "modules": [
"compatibility.js", "compatibility.js",

1344
core/js/underscore.js Normal file

File diff suppressed because it is too large Load Diff

View File

@ -305,6 +305,7 @@ class OC {
OC_Util::addScript("jquery.placeholder"); OC_Util::addScript("jquery.placeholder");
OC_Util::addScript("jquery-tipsy"); OC_Util::addScript("jquery-tipsy");
OC_Util::addScript("compatibility"); OC_Util::addScript("compatibility");
OC_Util::addScript("underscore");
OC_Util::addScript("jquery.ocdialog"); OC_Util::addScript("jquery.ocdialog");
OC_Util::addScript("oc-dialogs"); OC_Util::addScript("oc-dialogs");
OC_Util::addScript("js"); OC_Util::addScript("js");

View File

@ -5,6 +5,36 @@
* See the COPYING-README file. * See the COPYING-README file.
*/ */
/* 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 () {
if (event.keyCode === 13 && that.val() !== '' ){
event.preventDefault();
cb();
}
});
};
/** /**
* Post the email address change to the server. * Post the email address change to the server.
*/ */
@ -42,13 +72,12 @@ function changeDisplayName(){
} }
OC.msg.finishedSaving('#displaynameform .msg', data); OC.msg.finishedSaving('#displaynameform .msg', data);
}); });
return false;
} }
} }
function updateAvatar (hidedefault) { function updateAvatar (hidedefault) {
$headerdiv = $('#header .avatardiv'); var $headerdiv = $('#header .avatardiv');
$displaydiv = $('#displayavatar .avatardiv'); var $displaydiv = $('#displayavatar .avatardiv');
if(hidedefault) { if(hidedefault) {
$headerdiv.hide(); $headerdiv.hide();
@ -65,11 +94,12 @@ function updateAvatar (hidedefault) {
} }
function showAvatarCropper() { function showAvatarCropper() {
$cropper = $('#cropper'); var $cropper = $('#cropper');
$cropper.prepend("<img>"); $cropper.prepend("<img>");
$cropperImage = $('#cropper img'); var $cropperImage = $('#cropper img');
$cropperImage.attr('src', OC.generateUrl('/avatar/tmp')+'?requesttoken='+oc_requesttoken+'#'+Math.floor(Math.random()*1000)); $cropperImage.attr('src',
OC.generateUrl('/avatar/tmp')+'?requesttoken='+oc_requesttoken+'#'+Math.floor(Math.random()*1000));
// Looks weird, but on('load', ...) doesn't work in IE8 // Looks weird, but on('load', ...) doesn't work in IE8
$cropperImage.ready(function(){ $cropperImage.ready(function(){
@ -90,12 +120,12 @@ function showAvatarCropper() {
function sendCropData() { function sendCropData() {
cleanCropper(); cleanCropper();
var cropperdata = $('#cropper').data(); var cropperData = $('#cropper').data();
var data = { var data = {
x: cropperdata.x, x: cropperData.x,
y: cropperdata.y, y: cropperData.y,
w: cropperdata.w, w: cropperData.w,
h: cropperdata.h h: cropperData.h
}; };
$.post(OC.generateUrl('/avatar/cropped'), {crop: data}, avatarResponseHandler); $.post(OC.generateUrl('/avatar/cropped'), {crop: data}, avatarResponseHandler);
} }
@ -105,7 +135,7 @@ function saveCoords(c) {
} }
function cleanCropper() { function cleanCropper() {
$cropper = $('#cropper'); var $cropper = $('#cropper');
$('#displayavatar').show(); $('#displayavatar').show();
$cropper.hide(); $cropper.hide();
$('.jcrop-holder').remove(); $('.jcrop-holder').remove();
@ -114,7 +144,7 @@ function cleanCropper() {
} }
function avatarResponseHandler(data) { function avatarResponseHandler(data) {
$warning = $('#avatar .warning'); var $warning = $('#avatar .warning');
$warning.hide(); $warning.hide();
if (data.status === "success") { if (data.status === "success") {
updateAvatar(); updateAvatar();
@ -157,41 +187,8 @@ $(document).ready(function(){
}); });
$('#displayName').keyup(function(){ $('#displayName').keyUpDelayedOrEnter(changeDisplayName);
if ($('#displayName').val() !== '' ){ $('#email').keyUpDelayedOrEnter(changeEmailAddress);
if(typeof timeout !== 'undefined'){
clearTimeout(timeout);
}
timeout = setTimeout(changeDisplayName, 1000);
}
});
$('#email').keyup(function(event){
if ($('#email').val() !== '' ){
// if this is the enter key changeEmailAddress() is already invoked
// so it doesn't need to be triggered again
if(event.keyCode === 13) {
return;
}
if(typeof timeout !== 'undefined'){
clearTimeout(timeout);
}
timeout = setTimeout(changeEmailAddress, 1000);
}
});
$('#email').keypress(function(event){
// check for enter key and non empty email
if (event.keyCode === 13 && $('#email').val() !== '' ){
event.preventDefault()
// clear timeout of previous keyup event - prevents duplicate changeEmailAddress call
if(typeof timeout !== 'undefined'){
clearTimeout(timeout);
}
changeEmailAddress();
}
});
$("#languageinput").change( function(){ $("#languageinput").change( function(){
// Serialize the data // Serialize the data
@ -256,7 +253,7 @@ $(document).ready(function(){
$.ajax({ $.ajax({
type: 'DELETE', type: 'DELETE',
url: OC.generateUrl('/avatar/'), url: OC.generateUrl('/avatar/'),
success: function(msg) { success: function() {
updateAvatar(true); updateAvatar(true);
$('#removeavatar').hide(); $('#removeavatar').hide();
} }
@ -321,7 +318,7 @@ OC.Encryption.msg={
}, },
finishedDecrypting:function(selector, data){ finishedDecrypting:function(selector, data){
if( data.status === "success" ){ if( data.status === "success" ){
$(selector).html( data.data.message ) $(selector).html( data.data.message )
.addClass('success') .addClass('success')
.stop(true, true) .stop(true, true)
.delay(3000); .delay(3000);