mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-16 07:08:55 +00:00
[backbone] Several small interface improvements
This commit is contained in:
@@ -142,7 +142,7 @@ define([
|
||||
|
||||
/* only need a token for non-get requests */
|
||||
if (method == 'create' || method == 'update' || method == 'delete') {
|
||||
// CSRF token value is in an embedded meta tag
|
||||
// CSRF token value is in an embedded meta tag
|
||||
// var csrfToken = $("meta[name='csrf_token']").attr('content');
|
||||
var csrfToken = app.pageOptions.csrfToken;
|
||||
|
||||
@@ -154,8 +154,8 @@ define([
|
||||
/* proxy the call to the old sync method */
|
||||
return Backbone._sync(method, model, options);
|
||||
};
|
||||
},
|
||||
|
||||
},
|
||||
|
||||
prepareCSRFToken: function(xhr, settings) {
|
||||
function getCookie(name) {
|
||||
var cookieValue = null;
|
||||
@@ -216,7 +216,7 @@ define([
|
||||
.parentNode
|
||||
.innerHTML;
|
||||
},
|
||||
|
||||
|
||||
pathJoin: function(array) {
|
||||
var result = array[0];
|
||||
for (var i = 1; i < array.length; i++) {
|
||||
@@ -228,33 +228,80 @@ define([
|
||||
return result;
|
||||
},
|
||||
|
||||
fileSizeFormat: function (bytes, precision) {
|
||||
var kilobyte = 1024;
|
||||
var megabyte = kilobyte * 1024;
|
||||
var gigabyte = megabyte * 1024;
|
||||
var terabyte = gigabyte * 1024;
|
||||
closePopup: function(e, popup, popup_switch) {
|
||||
var target = e.target || event.srcElement;
|
||||
if (!popup.hasClass('hide') && !popup.is(target) && !popup.find('*').is(target) && !popup_switch.is(target) && !popup_switch.find('*').is(target) ) {
|
||||
popup.addClass('hide');
|
||||
}
|
||||
},
|
||||
|
||||
var precision = precision || 0;
|
||||
initAccountPopup: function() {
|
||||
// TODO: need improving
|
||||
$('#my-info').click(function() {
|
||||
var popup = $('#user-info-popup');
|
||||
popup.toggleClass('hide');
|
||||
if (!popup.hasClass('hide')) {
|
||||
var loading_tip = $('.loading-tip', popup),
|
||||
space_traffic = $('#space-traffic');
|
||||
loading_tip.show();
|
||||
space_traffic.addClass('hide');
|
||||
$('.error', popup).addClass('hide');
|
||||
$.ajax({
|
||||
url: space_traffic.data('url'),
|
||||
dataType: 'json',
|
||||
cache: false,
|
||||
success: function(data) {
|
||||
loading_tip.hide();
|
||||
space_traffic.html(data['html']).removeClass('hide');
|
||||
},
|
||||
error: function (xhr, textStatus, errorThrown) {
|
||||
if (xhr.responseText) {
|
||||
var error = $.parseJSON(xhr.responseText).error;
|
||||
loading_tip.hide();
|
||||
if ($('.error', popup).length == 0) {
|
||||
loading_tip.after('<p class="error alc">' + error + '</p>');
|
||||
} else {
|
||||
$('.error', popup).removeClass('hide');
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
if ((bytes >= 0) && (bytes < kilobyte)) {
|
||||
return bytes + ' B';
|
||||
_this = this;
|
||||
$(document).click(function(e) {
|
||||
_this.closePopup(e, $('#user-info-popup'), $('#my-info'));
|
||||
});
|
||||
},
|
||||
|
||||
} else if ((bytes >= kilobyte) && (bytes < megabyte)) {
|
||||
return (bytes / kilobyte).toFixed(precision) + ' KB';
|
||||
fileSizeFormat: function(bytes, precision) {
|
||||
var kilobyte = 1024;
|
||||
var megabyte = kilobyte * 1024;
|
||||
var gigabyte = megabyte * 1024;
|
||||
var terabyte = gigabyte * 1024;
|
||||
|
||||
} else if ((bytes >= megabyte) && (bytes < gigabyte)) {
|
||||
return (bytes / megabyte).toFixed(precision) + ' MB';
|
||||
var precision = precision || 0;
|
||||
|
||||
} else if ((bytes >= gigabyte) && (bytes < terabyte)) {
|
||||
return (bytes / gigabyte).toFixed(precision) + ' GB';
|
||||
if ((bytes >= 0) && (bytes < kilobyte)) {
|
||||
return bytes + ' B';
|
||||
|
||||
} else if (bytes >= terabyte) {
|
||||
return (bytes / terabyte).toFixed(precision) + ' TB';
|
||||
} else if ((bytes >= kilobyte) && (bytes < megabyte)) {
|
||||
return (bytes / kilobyte).toFixed(precision) + ' KB';
|
||||
|
||||
} else {
|
||||
return bytes + ' B';
|
||||
}
|
||||
}
|
||||
} else if ((bytes >= megabyte) && (bytes < gigabyte)) {
|
||||
return (bytes / megabyte).toFixed(precision) + ' MB';
|
||||
|
||||
} else if ((bytes >= gigabyte) && (bytes < terabyte)) {
|
||||
return (bytes / gigabyte).toFixed(precision) + ' GB';
|
||||
|
||||
} else if (bytes >= terabyte) {
|
||||
return (bytes / terabyte).toFixed(precision) + ' TB';
|
||||
|
||||
} else {
|
||||
return bytes + ' B';
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
|
Reference in New Issue
Block a user