mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-05 17:02:47 +00:00
[backbone] Fix indentation for dirents.js and file-tree.js
This commit is contained in:
@@ -29,253 +29,253 @@ define([
|
|||||||
|
|
||||||
render: function() {
|
render: function() {
|
||||||
var dirent_path = Common.pathJoin([this.dirView.dir.path,
|
var dirent_path = Common.pathJoin([this.dirView.dir.path,
|
||||||
this.model.attributes.obj_name]);
|
this.model.attributes.obj_name]);
|
||||||
//console.log(Common.pathJointhis.dirView.dir.path + "/" + this.model.attributes.obj_name);
|
//console.log(Common.pathJointhis.dirView.dir.path + "/" + this.model.attributes.obj_name);
|
||||||
this.$el.html(this.template({
|
this.$el.html(this.template({
|
||||||
dirent: this.model.attributes,
|
dirent: this.model.attributes,
|
||||||
repo_id: this.dirView.dir.repo_id,
|
repo_id: this.dirView.dir.repo_id,
|
||||||
// dir_path: this.dirView.dir.path,
|
// dir_path: this.dirView.dir.path,
|
||||||
dirent_path: dirent_path,
|
dirent_path: dirent_path,
|
||||||
user_perm: this.dirView.dir.user_perm,
|
user_perm: this.dirView.dir.user_perm,
|
||||||
repo_encrypted: this.dirView.dir.encrypted
|
repo_encrypted: this.dirView.dir.encrypted
|
||||||
}));
|
}));
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
|
|
||||||
events: {
|
events: {
|
||||||
'mouseenter': 'highlight',
|
'mouseenter': 'highlight',
|
||||||
'mouseleave': 'rmHighlight',
|
'mouseleave': 'rmHighlight',
|
||||||
'click .select': 'select',
|
'click .select': 'select',
|
||||||
'click .file-star': 'starFile',
|
'click .file-star': 'starFile',
|
||||||
'click .dir-link': 'visitDir',
|
'click .dir-link': 'visitDir',
|
||||||
'click .more-op-icon': 'togglePopup',
|
'click .more-op-icon': 'togglePopup',
|
||||||
'click .share': 'share',
|
'click .share': 'share',
|
||||||
'click .del': 'delete',
|
'click .del': 'delete',
|
||||||
'click .rename': 'rename',
|
'click .rename': 'rename',
|
||||||
'click .mv': 'mvcp',
|
'click .mv': 'mvcp',
|
||||||
'click .cp': 'mvcp',
|
'click .cp': 'mvcp',
|
||||||
'click .file-update': 'updateFile'
|
'click .file-update': 'updateFile'
|
||||||
},
|
},
|
||||||
|
|
||||||
highlight: function() {
|
highlight: function() {
|
||||||
if (app.globalState.noFileOpPopup) {
|
if (app.globalState.noFileOpPopup) {
|
||||||
this.$el.addClass('hl').find('.repo-file-op').removeClass('vh');
|
this.$el.addClass('hl').find('.repo-file-op').removeClass('vh');
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
rmHighlight: function() {
|
rmHighlight: function() {
|
||||||
if (app.globalState.noFileOpPopup) {
|
if (app.globalState.noFileOpPopup) {
|
||||||
this.$el.removeClass('hl').find('.repo-file-op').addClass('vh');
|
this.$el.removeClass('hl').find('.repo-file-op').addClass('vh');
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
select: function () {
|
select: function () {
|
||||||
var checkbox = this.$('.checkbox');
|
var checkbox = this.$('.checkbox');
|
||||||
checkbox.toggleClass('checkbox-checked');
|
checkbox.toggleClass('checkbox-checked');
|
||||||
if (checkbox.hasClass('checkbox-checked')) {
|
if (checkbox.hasClass('checkbox-checked')) {
|
||||||
this.model.set({'selected':true}, {silent:true}); // do not trigger the 'change' event.
|
this.model.set({'selected':true}, {silent:true}); // do not trigger the 'change' event.
|
||||||
} else {
|
} else {
|
||||||
this.model.set({'selected':false}, {silent:true});
|
this.model.set({'selected':false}, {silent:true});
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
starFile: function() {
|
starFile: function() {
|
||||||
var _this = this;
|
var _this = this;
|
||||||
var dir = this.dirView.dir;
|
var dir = this.dirView.dir;
|
||||||
//var path = dir.path;
|
//var path = dir.path;
|
||||||
//path += (path == '/' ? '' : '/');
|
//path += (path == '/' ? '' : '/');
|
||||||
var starred = this.model.get('starred');
|
var starred = this.model.get('starred');
|
||||||
var options = { repo_id: dir.repo_id };
|
var options = { repo_id: dir.repo_id };
|
||||||
options.name = starred ? 'unstar_file' : 'star_file';
|
options.name = starred ? 'unstar_file' : 'star_file';
|
||||||
var filePath = Common.pathJoin([dir.path, this.model.get('obj_name')]);
|
var filePath = Common.pathJoin([dir.path, this.model.get('obj_name')]);
|
||||||
var url = Common.getUrl(options) + '?file=' + encodeURIComponent(filePath);
|
var url = Common.getUrl(options) + '?file=' + encodeURIComponent(filePath);
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: url,
|
url: url,
|
||||||
dataType: 'json',
|
dataType: 'json',
|
||||||
cache: false,
|
cache: false,
|
||||||
success: function () {
|
success: function () {
|
||||||
if (starred) {
|
if (starred) {
|
||||||
_this.model.set({'starred':false});
|
_this.model.set({'starred':false});
|
||||||
} else {
|
} else {
|
||||||
_this.model.set({'starred':true});
|
_this.model.set({'starred':true});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
error: Common.ajaxErrorHandler
|
error: Common.ajaxErrorHandler
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
visitDir: function () {
|
visitDir: function () {
|
||||||
// show 'loading'
|
// show 'loading'
|
||||||
this.$('.dirent-icon img').attr({
|
this.$('.dirent-icon img').attr({
|
||||||
'src': app.config.mediaURL + 'img/loading-icon.gif',
|
'src': app.config.mediaURL + 'img/loading-icon.gif',
|
||||||
'alt':''
|
'alt':''
|
||||||
});
|
});
|
||||||
// empty all models
|
// empty all models
|
||||||
this.dirView.dir.reset();
|
this.dirView.dir.reset();
|
||||||
// update url & dirents
|
// update url & dirents
|
||||||
var dir_url = this.$('.dir-link').attr("href");
|
var dir_url = this.$('.dir-link').attr("href");
|
||||||
app.router.navigate(dir_url, {trigger: true}); // offer an url fragment
|
app.router.navigate(dir_url, {trigger: true}); // offer an url fragment
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
|
|
||||||
togglePopup: function () {
|
togglePopup: function () {
|
||||||
var icon = this.$('.more-op-icon'),
|
var icon = this.$('.more-op-icon'),
|
||||||
popup = this.$('.hidden-op');
|
popup = this.$('.hidden-op');
|
||||||
|
|
||||||
if (popup.hasClass('hide')) { // the popup is not shown
|
if (popup.hasClass('hide')) { // the popup is not shown
|
||||||
if (icon.position().left + icon.width() + popup.outerWidth() < icon.parent().width()) {
|
if (icon.position().left + icon.width() + popup.outerWidth() < icon.parent().width()) {
|
||||||
popup.css({'left': icon.position().left + icon.width() + 5});
|
popup.css({'left': icon.position().left + icon.width() + 5});
|
||||||
if (icon.offset().top + popup.height() <= $('#main').offset().top + $('#main').height()) {
|
if (icon.offset().top + popup.height() <= $('#main').offset().top + $('#main').height()) {
|
||||||
popup.css('top', 6);
|
popup.css('top', 6);
|
||||||
} else {
|
} else {
|
||||||
popup.css('bottom', 2);
|
popup.css('bottom', 2);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
popup.css({'right':0});
|
||||||
|
if (icon.offset().top + popup.height() <= $('#main').offset().top + $('#main').height()) {
|
||||||
|
popup.css('top', icon.position().top + icon.height() + 3);
|
||||||
|
} else {
|
||||||
|
popup.css('bottom', icon.position().top + icon.height() + 3);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
popup.removeClass('hide');
|
||||||
|
app.globalState.noFileOpPopup = false;
|
||||||
|
app.globalState.popup_tr = icon.parents('tr');
|
||||||
} else {
|
} else {
|
||||||
popup.css({'right':0});
|
popup.addClass('hide');
|
||||||
if (icon.offset().top + popup.height() <= $('#main').offset().top + $('#main').height()) {
|
app.globalState.noFileOpPopup = true;
|
||||||
popup.css('top', icon.position().top + icon.height() + 3);
|
app.globalState.popup_tr = '';
|
||||||
} else {
|
|
||||||
popup.css('bottom', icon.position().top + icon.height() + 3);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
popup.removeClass('hide');
|
|
||||||
app.globalState.noFileOpPopup = false;
|
|
||||||
app.globalState.popup_tr = icon.parents('tr');
|
|
||||||
} else {
|
|
||||||
popup.addClass('hide');
|
|
||||||
app.globalState.noFileOpPopup = true;
|
|
||||||
app.globalState.popup_tr = '';
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
delete: function() {
|
delete: function() {
|
||||||
var dirent_name = this.model.get('obj_name');
|
var dirent_name = this.model.get('obj_name');
|
||||||
var options = {repo_id: this.dirView.dir.repo_id};
|
var options = {repo_id: this.dirView.dir.repo_id};
|
||||||
options.name = this.model.get('is_dir') ? 'del_dir' : 'del_file';
|
options.name = this.model.get('is_dir') ? 'del_dir' : 'del_file';
|
||||||
var url_main = Common.getUrl(options);
|
var url_main = Common.getUrl(options);
|
||||||
var el = this.$el;
|
var el = this.$el;
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: url_main + '?parent_dir=' + encodeURIComponent(this.dirView.dir.path)
|
url: url_main + '?parent_dir=' + encodeURIComponent(this.dirView.dir.path)
|
||||||
+ '&name=' + encodeURIComponent(dirent_name),
|
+ '&name=' + encodeURIComponent(dirent_name),
|
||||||
dataType: 'json',
|
dataType: 'json',
|
||||||
success: function(data) {
|
success: function(data) {
|
||||||
el.remove();
|
el.remove();
|
||||||
app.globalState.noFileOpPopup = true;// make other items can work normally when hover
|
app.globalState.noFileOpPopup = true;// make other items can work normally when hover
|
||||||
var msg = gettext("Successfully deleted %(name)s");
|
var msg = gettext("Successfully deleted %(name)s");
|
||||||
msg = msg.replace('%(name)s', dirent_name);
|
msg = msg.replace('%(name)s', dirent_name);
|
||||||
Common.feedback(msg, 'success');
|
Common.feedback(msg, 'success');
|
||||||
},
|
},
|
||||||
error: Common.ajaxErrorHandler
|
error: Common.ajaxErrorHandler
|
||||||
});
|
});
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
|
|
||||||
rename: function() {
|
rename: function() {
|
||||||
var is_dir = this.model.get('is_dir');
|
var is_dir = this.model.get('is_dir');
|
||||||
//var hd_text = is_dir ? "{% trans "Rename Directory" %}" : "{% trans "Rename File" %}";
|
//var hd_text = is_dir ? "{% trans "Rename Directory" %}" : "{% trans "Rename File" %}";
|
||||||
var title = is_dir ? gettext("Rename Directory") : gettext("Rename File");
|
var title = is_dir ? gettext("Rename Directory") : gettext("Rename File");
|
||||||
//var op_detail = $('.detail', form);
|
//var op_detail = $('.detail', form);
|
||||||
//op_detail.html(op_detail.html().replace('%(name)s', '<span class="op-target">' + dirent_name + '</span>'));
|
//op_detail.html(op_detail.html().replace('%(name)s', '<span class="op-target">' + dirent_name + '</span>'));
|
||||||
var dirent_name = this.model.get('obj_name');
|
var dirent_name = this.model.get('obj_name');
|
||||||
|
|
||||||
var form = $(this.renameTemplate({
|
var form = $(this.renameTemplate({
|
||||||
form_title: title,
|
form_title: title,
|
||||||
dirent_name: dirent_name,
|
dirent_name: dirent_name,
|
||||||
}));
|
}));
|
||||||
form.modal();
|
form.modal();
|
||||||
var form_id = form.attr('id');
|
var form_id = form.attr('id');
|
||||||
$('#simplemodal-container').css({'width':'auto', 'height':'auto'});
|
$('#simplemodal-container').css({'width':'auto', 'height':'auto'});
|
||||||
|
|
||||||
var _this = this;
|
var _this = this;
|
||||||
var dir = this.dirView.dir;
|
var dir = this.dirView.dir;
|
||||||
form.submit(function() {
|
form.submit(function() {
|
||||||
var new_name = $.trim($('[name="newname"]', form).val());
|
var new_name = $.trim($('[name="newname"]', form).val());
|
||||||
if (!new_name) {
|
if (!new_name) {
|
||||||
Common.showFormError(form_id, gettext("It is required."));
|
Common.showFormError(form_id, gettext("It is required."));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (new_name == dirent_name) {
|
if (new_name == dirent_name) {
|
||||||
Common.showFormError(form_id, gettext("You have not renamed it."));
|
Common.showFormError(form_id, gettext("You have not renamed it."));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
var post_data = {'oldname': dirent_name, 'newname':new_name};
|
var post_data = {'oldname': dirent_name, 'newname':new_name};
|
||||||
var options = { repo_id: dir.repo_id };
|
var options = { repo_id: dir.repo_id };
|
||||||
options.name = is_dir ? 'rename_dir' : 'rename_file';
|
options.name = is_dir ? 'rename_dir' : 'rename_file';
|
||||||
var post_url = Common.getUrl(options) + '?parent_dir=' + encodeURIComponent(dir.path);
|
var post_url = Common.getUrl(options) + '?parent_dir=' + encodeURIComponent(dir.path);
|
||||||
var after_op_success = function (data) {
|
var after_op_success = function (data) {
|
||||||
new_name = data['newname'];
|
new_name = data['newname'];
|
||||||
var now = new Date().getTime()/1000;
|
var now = new Date().getTime()/1000;
|
||||||
$.modal.close();
|
$.modal.close();
|
||||||
_this.model.set({ // it will trigger 'change' event
|
_this.model.set({ // it will trigger 'change' event
|
||||||
'obj_name': new_name,
|
'obj_name': new_name,
|
||||||
'last_modified': now,
|
'last_modified': now,
|
||||||
//'last_update': "{% trans "Just now" %}",
|
//'last_update': "{% trans "Just now" %}",
|
||||||
'last_update': "Just now",
|
'last_update': "Just now",
|
||||||
'sharelink': '',
|
'sharelink': '',
|
||||||
'sharetoken': ''
|
'sharetoken': ''
|
||||||
|
});
|
||||||
|
if (is_dir) {
|
||||||
|
|
||||||
|
} else {
|
||||||
|
_this.model.set({
|
||||||
|
'starred': false
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
Common.ajaxPost({
|
||||||
|
'form': form,
|
||||||
|
'post_url': post_url,
|
||||||
|
'post_data': post_data,
|
||||||
|
'after_op_success': after_op_success,
|
||||||
|
'form_id': form_id
|
||||||
|
});
|
||||||
|
return false;
|
||||||
});
|
});
|
||||||
if (is_dir) {
|
return false;
|
||||||
|
},
|
||||||
|
|
||||||
} else {
|
mvcp: function() {
|
||||||
_this.model.set({
|
var el = event.target || event.srcElement,
|
||||||
'starred': false
|
op_type = $(el).hasClass('mv') ? 'mv':'cp',
|
||||||
});
|
op_detail,
|
||||||
|
dirent = this.$el,
|
||||||
|
obj_name = this.model.get('obj_name'),
|
||||||
|
obj_type = this.model.get('is_dir') ? 'dir':'file',
|
||||||
|
form = $('#mv-form'), form_hd;
|
||||||
|
|
||||||
|
form.modal({appendTo:'#main', autoResize:true, focus:false});
|
||||||
|
$('#simplemodal-container').css({'width':'auto', 'height':'auto'});
|
||||||
|
|
||||||
|
if (!this.dirView.dir.encrypted) {
|
||||||
|
$('#other-repos').show();
|
||||||
}
|
}
|
||||||
};
|
|
||||||
Common.ajaxPost({
|
|
||||||
'form': form,
|
|
||||||
'post_url': post_url,
|
|
||||||
'post_data': post_data,
|
|
||||||
'after_op_success': after_op_success,
|
|
||||||
'form_id': form_id
|
|
||||||
});
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
return false;
|
|
||||||
},
|
|
||||||
|
|
||||||
mvcp: function() {
|
if (op_type == 'mv') {
|
||||||
var el = event.target || event.srcElement,
|
//form_hd = obj_type == 'dir'? "{% trans "Move Directory" %}":"{% trans "Move File" %}";
|
||||||
op_type = $(el).hasClass('mv') ? 'mv':'cp',
|
form_hd = obj_type == 'dir' ? "Move Directory" : "Move File";
|
||||||
op_detail,
|
} else {
|
||||||
dirent = this.$el,
|
//form_hd = obj_type == 'dir'? "{% trans "Copy Directory" %}":"{% trans "Copy File" %}";
|
||||||
obj_name = this.model.get('obj_name'),
|
form_hd = obj_type == 'dir' ? "Copy Directory" : "Copy File";
|
||||||
obj_type = this.model.get('is_dir') ? 'dir':'file',
|
}
|
||||||
form = $('#mv-form'), form_hd;
|
|
||||||
|
|
||||||
form.modal({appendTo:'#main', autoResize:true, focus:false});
|
//op_detail = op_type == 'mv' ? "{% trans "Move %(name)s to:" %}" : "{% trans "Copy %(name)s to:" %}";
|
||||||
$('#simplemodal-container').css({'width':'auto', 'height':'auto'});
|
op_detail = op_type == 'mv' ? "Move %(name)s to:" : "Copy %(name)s to:";
|
||||||
|
op_detail = op_detail.replace('%(name)s', '<span class="op-target">' + obj_name + '</span>');
|
||||||
|
form.prepend('<h3>' + form_hd + '</h3><h4>' + op_detail + '</h4>');
|
||||||
|
|
||||||
if (!this.dirView.dir.encrypted) {
|
$('input[name="op"]', form).val(op_type);
|
||||||
$('#other-repos').show();
|
$('input[name="obj_type"]', form).val(obj_type);
|
||||||
}
|
$('input[name="obj_name"]', form).val(obj_name);
|
||||||
|
|
||||||
if (op_type == 'mv') {
|
form.data('op_obj', dirent);
|
||||||
//form_hd = obj_type == 'dir'? "{% trans "Move Directory" %}":"{% trans "Move File" %}";
|
FileTree.renderTreeForPath({
|
||||||
form_hd = obj_type == 'dir'? "Move Directory" : "Move File";
|
repo_name: this.dirView.dir.repo_name,
|
||||||
} else {
|
repo_id: this.dirView.dir.repo_id,
|
||||||
//form_hd = obj_type == 'dir'? "{% trans "Copy Directory" %}":"{% trans "Copy File" %}";
|
path: this.dirView.dir.path,
|
||||||
form_hd = obj_type == 'dir'? "Copy Directory" : "Copy File";
|
});
|
||||||
}
|
return false;
|
||||||
|
},
|
||||||
//op_detail = op_type == 'mv' ? "{% trans "Move %(name)s to:" %}" : "{% trans "Copy %(name)s to:" %}";
|
|
||||||
op_detail = op_type == 'mv' ? "Move %(name)s to:" : "Copy %(name)s to:";
|
|
||||||
op_detail = op_detail.replace('%(name)s', '<span class="op-target">' + obj_name + '</span>');
|
|
||||||
form.prepend('<h3>' + form_hd + '</h3><h4>' + op_detail + '</h4>');
|
|
||||||
|
|
||||||
$('input[name="op"]', form).val(op_type);
|
|
||||||
$('input[name="obj_type"]', form).val(obj_type);
|
|
||||||
$('input[name="obj_name"]', form).val(obj_name);
|
|
||||||
|
|
||||||
form.data('op_obj', dirent);
|
|
||||||
FileTree.render_jstree_for_cur_path({
|
|
||||||
repo_name: this.dirView.dir.repo_name,
|
|
||||||
repo_id: this.dirView.dir.repo_id,
|
|
||||||
path: this.dirView.dir.path,
|
|
||||||
});
|
|
||||||
return false;
|
|
||||||
},
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@@ -10,267 +10,268 @@ define([
|
|||||||
|
|
||||||
var FileTree = {
|
var FileTree = {
|
||||||
|
|
||||||
options: {},
|
options: {},
|
||||||
|
|
||||||
formatRepoData: function(data) {
|
formatRepoData: function(data) {
|
||||||
var repos = [], repo;
|
var repos = [], repo;
|
||||||
for (var i = 0, len = data.length; i < len; i++) {
|
for (var i = 0, len = data.length; i < len; i++) {
|
||||||
repo = {
|
repo = {
|
||||||
'data': data[i].name,
|
'data': data[i].name,
|
||||||
'attr': {'repo_id': data[i].id, 'root_node': true},
|
'attr': {'repo_id': data[i].id, 'root_node': true},
|
||||||
'state': 'closed'
|
|
||||||
}
|
|
||||||
repos.push(repo);
|
|
||||||
}
|
|
||||||
return repos;
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @container(required): container.data('site_root', '{{SITE_ROOT}}')
|
|
||||||
* @options (optional): {'two_state': true}
|
|
||||||
*/
|
|
||||||
renderFileTree: function(container, repo_data, options) {
|
|
||||||
var opts = options || {};
|
|
||||||
container
|
|
||||||
.delegate('.jstree-closed', 'dblclick', function(e) {
|
|
||||||
container.jstree('open_node', $(this));
|
|
||||||
$(this).find('a').removeClass('jstree-clicked');
|
|
||||||
})
|
|
||||||
.bind('select_node.jstree', function(e, data) {
|
|
||||||
$('.jstree-clicked').removeClass('jstree-clicked'); // do not show selected item
|
|
||||||
})
|
|
||||||
.jstree({
|
|
||||||
'json_data': {
|
|
||||||
'data': repo_data,
|
|
||||||
'ajax': {
|
|
||||||
'url': function(data) {
|
|
||||||
var path = this.get_path(data);
|
|
||||||
var repo_id;
|
|
||||||
if (path.length == 1) {
|
|
||||||
path = '/';
|
|
||||||
repo_id = data.attr('repo_id');
|
|
||||||
} else {
|
|
||||||
var root_node = data.parents('[root_node=true]');
|
|
||||||
repo_id = root_node.attr('repo_id');
|
|
||||||
path.shift();
|
|
||||||
path = '/' + path.join('/') + '/';
|
|
||||||
}
|
|
||||||
return container.data('site_root') + 'ajax/repo/' + repo_id + '/dirents/?path=' + e(path);
|
|
||||||
},
|
|
||||||
'success': function(data) {
|
|
||||||
var items = [];
|
|
||||||
var o, item;
|
|
||||||
for (var i = 0, len = data.length; i < len; i++) {
|
|
||||||
o = data[i];
|
|
||||||
if (o.type == 'dir') {
|
|
||||||
item = {
|
|
||||||
'data': o.name,
|
|
||||||
'attr': { 'type': o.type },
|
|
||||||
'state': 'closed'
|
|
||||||
};
|
|
||||||
} else {
|
|
||||||
item = {
|
|
||||||
'data': o.name,
|
|
||||||
'attr': {'type': o.type }
|
|
||||||
};
|
|
||||||
}
|
|
||||||
items.push(item);
|
|
||||||
}
|
|
||||||
return items;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
'core': {
|
|
||||||
'animation': 100
|
|
||||||
},
|
|
||||||
'themes': {
|
|
||||||
'theme':'classic'
|
|
||||||
},
|
|
||||||
'checkbox':{
|
|
||||||
'two_state': opts.two_state, // default: false. when 'true', dir can be checked separately with file
|
|
||||||
// make dir can only be selected
|
|
||||||
//'override_ui':true, // nodes can be checked, or selected to be checked
|
|
||||||
'real_checkboxes': true,
|
|
||||||
'real_checkboxes_names': function(node) {
|
|
||||||
// get the path array consisting of nodes starting from the root node
|
|
||||||
var path_array = this.get_path(node);
|
|
||||||
var repo_id, path;
|
|
||||||
if (path_array.length == 1) {
|
|
||||||
// root node
|
|
||||||
path = '/';
|
|
||||||
repo_id = node.attr('repo_id');
|
|
||||||
} else {
|
|
||||||
path_array.shift();
|
|
||||||
repo_id = node.parents('[root_node=true]').attr('repo_id');
|
|
||||||
if (node.attr('type') == 'dir') {
|
|
||||||
path = '/' + path_array.join('/') + '/';
|
|
||||||
} else {
|
|
||||||
path = '/' + path_array.join('/');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ['selected', repo_id + path];
|
|
||||||
}
|
|
||||||
},
|
|
||||||
'plugins': ['themes', 'json_data', 'ui', 'checkbox']
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
// only list dirs
|
|
||||||
renderDirTree: function(container, form, repo_data) {
|
|
||||||
container
|
|
||||||
.delegate('.jstree-closed', 'dblclick', function(e) {
|
|
||||||
container.jstree('open_node', $(this));
|
|
||||||
$(this).find('a').removeClass('jstree-clicked');
|
|
||||||
})
|
|
||||||
.bind('before.jstree', function(e, data) {
|
|
||||||
if (data.func === 'select_node') { // ensure only one selected dir display in the popup
|
|
||||||
$('.jstree-clicked', form).removeClass('jstree-clicked');
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.bind('select_node.jstree', function(e, data) {
|
|
||||||
var path, repo_id;
|
|
||||||
var path_array = data.inst.get_path(data.rslt.obj);
|
|
||||||
if (path_array.length == 1) {
|
|
||||||
path = '/';
|
|
||||||
repo_id = data.rslt.obj.attr('repo_id');
|
|
||||||
} else {
|
|
||||||
repo_id = data.rslt.obj.parents('[root_node=true]').attr('repo_id');
|
|
||||||
path_array.shift();
|
|
||||||
path = '/' + path_array.join('/') + '/';
|
|
||||||
}
|
|
||||||
$('input[name="dst_repo"]', form).val(repo_id);
|
|
||||||
$('input[name="dst_path"]', form).val(path);
|
|
||||||
})
|
|
||||||
.jstree({
|
|
||||||
'json_data': {
|
|
||||||
'data': repo_data,
|
|
||||||
'ajax': {
|
|
||||||
'url': function(data) {
|
|
||||||
var path = this.get_path(data);
|
|
||||||
var repo_id;
|
|
||||||
if (path.length == 1) {
|
|
||||||
path = '/';
|
|
||||||
repo_id = data.attr('repo_id');
|
|
||||||
} else {
|
|
||||||
repo_id = data.parents('[root_node=true]').attr('repo_id');
|
|
||||||
path.shift();
|
|
||||||
path = '/' + path.join('/') + '/';
|
|
||||||
}
|
|
||||||
return app.config.siteRoot + 'ajax/repo/' + repo_id + '/dirents/?dir_only=true&path=' + encodeURIComponent(path);
|
|
||||||
},
|
|
||||||
'success': function(data) {
|
|
||||||
var items = [];
|
|
||||||
var o, item;
|
|
||||||
for (var i = 0, len = data.length; i < len; i++) {
|
|
||||||
o = data[i];
|
|
||||||
if (o.has_subdir) {
|
|
||||||
item = {
|
|
||||||
'data': o.name,
|
|
||||||
'attr': { 'type': o.type },
|
|
||||||
'state': 'closed'
|
|
||||||
};
|
|
||||||
} else {
|
|
||||||
item = {
|
|
||||||
'data': o.name,
|
|
||||||
'attr': {'type': o.type }
|
|
||||||
};
|
|
||||||
}
|
|
||||||
items.push(item);
|
|
||||||
}
|
|
||||||
return items;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
'core': {
|
|
||||||
'animation': 100
|
|
||||||
},
|
|
||||||
'plugins': ['themes', 'json_data', 'ui']
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
render_jstree_for_cur_path: function(options) {
|
|
||||||
var form = $('#mv-form'),
|
|
||||||
container = $('#current-repo-dirs'),
|
|
||||||
loading_tip = container.prev();
|
|
||||||
|
|
||||||
var repo_name = options.repo_name,
|
|
||||||
repo_id = options.repo_id;
|
|
||||||
var cur_path = options.path;
|
|
||||||
if (cur_path != '/') {
|
|
||||||
cur_path += '/';
|
|
||||||
}
|
|
||||||
var _this = this;
|
|
||||||
// container.data('site_root', '{{SITE_ROOT}}');
|
|
||||||
$.ajax({
|
|
||||||
url: Common.getUrl({name: 'get_dirents', repo_id: options.repo_id})
|
|
||||||
+ '?path=' + encodeURIComponent(cur_path) + '&dir_only=true&all_dir=true',
|
|
||||||
cache: false,
|
|
||||||
dataType: 'json',
|
|
||||||
success: function(data) {
|
|
||||||
var json_data = [];
|
|
||||||
var repo_data = {
|
|
||||||
'data': repo_name,
|
|
||||||
'attr': {'repo_id': repo_id, 'root_node': true},
|
|
||||||
'state': 'open'
|
|
||||||
};
|
|
||||||
|
|
||||||
var path_eles = cur_path.split('/');
|
|
||||||
path_eles.pop();
|
|
||||||
/* e.g.
|
|
||||||
* path: '/xx/'
|
|
||||||
* path_eles: ['', 'xx']
|
|
||||||
* data: [["xxx", "xx", "test1022"], ["lkjj", "kjhkhi"]]
|
|
||||||
* when no dir in '/', data will be [[]];
|
|
||||||
*/
|
|
||||||
var len = data.length;
|
|
||||||
var children = [];
|
|
||||||
for (var i = len - 1; i > -1; i--) {
|
|
||||||
children[i] = [];
|
|
||||||
if (i == len - 1) {
|
|
||||||
for (var j = 0, len_i = data[i].length; j < len_i; j++) {
|
|
||||||
children[i].push({
|
|
||||||
'data': data[i][j],
|
|
||||||
'state': 'closed'
|
'state': 'closed'
|
||||||
});
|
|
||||||
}
|
}
|
||||||
} else {
|
repos.push(repo);
|
||||||
for (var j = 0, len_i = data[i].length; j < len_i; j++) {
|
|
||||||
if (data[i][j] == path_eles[i+1]) {
|
|
||||||
children[i].push({
|
|
||||||
'data': data[i][j],
|
|
||||||
'state': 'open',
|
|
||||||
'children': children[i+1]
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
children[i].push({
|
|
||||||
'data': data[i][j],
|
|
||||||
'state': 'closed'
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (children[0].length > 0) {
|
return repos;
|
||||||
$.extend(repo_data, {'children': children[0]});
|
},
|
||||||
}
|
|
||||||
json_data.push(repo_data);
|
|
||||||
|
|
||||||
loading_tip.hide();
|
/**
|
||||||
_this.renderDirTree(container, form, json_data);
|
* @container(required): container.data('site_root', '{{SITE_ROOT}}')
|
||||||
container.removeClass('hide');
|
* @options (optional): {'two_state': true}
|
||||||
},
|
*/
|
||||||
error: function() {
|
renderFileTree: function(container, repo_data, options) {
|
||||||
var cur_repo = [{
|
var opts = options || {};
|
||||||
'data': repo_name,
|
container
|
||||||
'attr': {'repo_id': repo_id, 'root_node': true},
|
.delegate('.jstree-closed', 'dblclick', function(e) {
|
||||||
'state': 'closed'
|
container.jstree('open_node', $(this));
|
||||||
}];
|
$(this).find('a').removeClass('jstree-clicked');
|
||||||
loading_tip.hide();
|
})
|
||||||
_this.renderDirTree(container, form, cur_repo);
|
.bind('select_node.jstree', function(e, data) {
|
||||||
container.removeClass('hide');
|
$('.jstree-clicked').removeClass('jstree-clicked'); // do not show selected item
|
||||||
}
|
})
|
||||||
});
|
.jstree({
|
||||||
},
|
'json_data': {
|
||||||
|
'data': repo_data,
|
||||||
|
'ajax': {
|
||||||
|
'url': function(data) {
|
||||||
|
var path = this.get_path(data);
|
||||||
|
var repo_id;
|
||||||
|
if (path.length == 1) {
|
||||||
|
path = '/';
|
||||||
|
repo_id = data.attr('repo_id');
|
||||||
|
} else {
|
||||||
|
var root_node = data.parents('[root_node=true]');
|
||||||
|
repo_id = root_node.attr('repo_id');
|
||||||
|
path.shift();
|
||||||
|
path = '/' + path.join('/') + '/';
|
||||||
|
}
|
||||||
|
return app.config.siteRoot + 'ajax/repo/' + repo_id + '/dirents/?path=' + e(path);
|
||||||
|
},
|
||||||
|
'success': function(data) {
|
||||||
|
var items = [];
|
||||||
|
var o, item;
|
||||||
|
for (var i = 0, len = data.length; i < len; i++) {
|
||||||
|
o = data[i];
|
||||||
|
if (o.type == 'dir') {
|
||||||
|
item = {
|
||||||
|
'data': o.name,
|
||||||
|
'attr': { 'type': o.type },
|
||||||
|
'state': 'closed'
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
item = {
|
||||||
|
'data': o.name,
|
||||||
|
'attr': {'type': o.type }
|
||||||
|
};
|
||||||
|
}
|
||||||
|
items.push(item);
|
||||||
|
}
|
||||||
|
return items;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'core': {
|
||||||
|
'animation': 100
|
||||||
|
},
|
||||||
|
'themes': {
|
||||||
|
'theme':'classic'
|
||||||
|
},
|
||||||
|
'checkbox':{
|
||||||
|
'two_state': opts.two_state, // default: false. when 'true', dir can be checked separately with file
|
||||||
|
// make dir can only be selected
|
||||||
|
//'override_ui':true, // nodes can be checked, or selected to be checked
|
||||||
|
'real_checkboxes': true,
|
||||||
|
'real_checkboxes_names': function(node) {
|
||||||
|
// get the path array consisting of nodes starting from the root node
|
||||||
|
var path_array = this.get_path(node);
|
||||||
|
var repo_id, path;
|
||||||
|
if (path_array.length == 1) {
|
||||||
|
// root node
|
||||||
|
path = '/';
|
||||||
|
repo_id = node.attr('repo_id');
|
||||||
|
} else {
|
||||||
|
path_array.shift();
|
||||||
|
repo_id = node.parents('[root_node=true]').attr('repo_id');
|
||||||
|
if (node.attr('type') == 'dir') {
|
||||||
|
path = '/' + path_array.join('/') + '/';
|
||||||
|
} else {
|
||||||
|
path = '/' + path_array.join('/');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ['selected', repo_id + path];
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'plugins': ['themes', 'json_data', 'ui', 'checkbox']
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
// only list dirs
|
||||||
|
renderDirTree: function(container, form, repo_data) {
|
||||||
|
container
|
||||||
|
.delegate('.jstree-closed', 'dblclick', function(e) {
|
||||||
|
container.jstree('open_node', $(this));
|
||||||
|
$(this).find('a').removeClass('jstree-clicked');
|
||||||
|
})
|
||||||
|
.bind('before.jstree', function(e, data) {
|
||||||
|
if (data.func === 'select_node') { // ensure only one selected dir display in the popup
|
||||||
|
$('.jstree-clicked', form).removeClass('jstree-clicked');
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.bind('select_node.jstree', function(e, data) {
|
||||||
|
var path, repo_id;
|
||||||
|
var path_array = data.inst.get_path(data.rslt.obj);
|
||||||
|
if (path_array.length == 1) {
|
||||||
|
path = '/';
|
||||||
|
repo_id = data.rslt.obj.attr('repo_id');
|
||||||
|
} else {
|
||||||
|
repo_id = data.rslt.obj.parents('[root_node=true]').attr('repo_id');
|
||||||
|
path_array.shift();
|
||||||
|
path = '/' + path_array.join('/') + '/';
|
||||||
|
}
|
||||||
|
$('input[name="dst_repo"]', form).val(repo_id);
|
||||||
|
$('input[name="dst_path"]', form).val(path);
|
||||||
|
})
|
||||||
|
.jstree({
|
||||||
|
'json_data': {
|
||||||
|
'data': repo_data,
|
||||||
|
'ajax': {
|
||||||
|
'url': function(data) {
|
||||||
|
var path = this.get_path(data);
|
||||||
|
var repo_id;
|
||||||
|
if (path.length == 1) {
|
||||||
|
path = '/';
|
||||||
|
repo_id = data.attr('repo_id');
|
||||||
|
} else {
|
||||||
|
repo_id = data.parents('[root_node=true]').attr('repo_id');
|
||||||
|
path.shift();
|
||||||
|
path = '/' + path.join('/') + '/';
|
||||||
|
}
|
||||||
|
return app.config.siteRoot + 'ajax/repo/' + repo_id + '/dirents/?dir_only=true&path=' + encodeURIComponent(path);
|
||||||
|
},
|
||||||
|
'success': function(data) {
|
||||||
|
var items = [];
|
||||||
|
var o, item;
|
||||||
|
for (var i = 0, len = data.length; i < len; i++) {
|
||||||
|
o = data[i];
|
||||||
|
if (o.has_subdir) {
|
||||||
|
item = {
|
||||||
|
'data': o.name,
|
||||||
|
'attr': { 'type': o.type },
|
||||||
|
'state': 'closed'
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
item = {
|
||||||
|
'data': o.name,
|
||||||
|
'attr': {'type': o.type }
|
||||||
|
};
|
||||||
|
}
|
||||||
|
items.push(item);
|
||||||
|
}
|
||||||
|
return items;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'core': {
|
||||||
|
'animation': 100
|
||||||
|
},
|
||||||
|
'plugins': ['themes', 'json_data', 'ui']
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
renderTreeForPath: function(options) {
|
||||||
|
// check templates/snippets/lib_op_popups.html for the template
|
||||||
|
var form = $('#mv-form'),
|
||||||
|
container = $('#current-repo-dirs'),
|
||||||
|
loading_tip = container.prev();
|
||||||
|
|
||||||
|
var repo_name = options.repo_name,
|
||||||
|
repo_id = options.repo_id;
|
||||||
|
var cur_path = options.path;
|
||||||
|
if (cur_path != '/') {
|
||||||
|
cur_path += '/';
|
||||||
|
}
|
||||||
|
var _this = this;
|
||||||
|
// container.data('site_root', '{{SITE_ROOT}}');
|
||||||
|
$.ajax({
|
||||||
|
url: Common.getUrl({name: 'get_dirents', repo_id: options.repo_id})
|
||||||
|
+ '?path=' + encodeURIComponent(cur_path) + '&dir_only=true&all_dir=true',
|
||||||
|
cache: false,
|
||||||
|
dataType: 'json',
|
||||||
|
success: function(data) {
|
||||||
|
var json_data = [];
|
||||||
|
var repo_data = {
|
||||||
|
'data': repo_name,
|
||||||
|
'attr': {'repo_id': repo_id, 'root_node': true},
|
||||||
|
'state': 'open'
|
||||||
|
};
|
||||||
|
|
||||||
|
var path_eles = cur_path.split('/');
|
||||||
|
path_eles.pop();
|
||||||
|
/* e.g.
|
||||||
|
* path: '/xx/'
|
||||||
|
* path_eles: ['', 'xx']
|
||||||
|
* data: [["xxx", "xx", "test1022"], ["lkjj", "kjhkhi"]]
|
||||||
|
* when no dir in '/', data will be [[]];
|
||||||
|
*/
|
||||||
|
var len = data.length;
|
||||||
|
var children = [];
|
||||||
|
for (var i = len - 1; i > -1; i--) {
|
||||||
|
children[i] = [];
|
||||||
|
if (i == len - 1) {
|
||||||
|
for (var j = 0, len_i = data[i].length; j < len_i; j++) {
|
||||||
|
children[i].push({
|
||||||
|
'data': data[i][j],
|
||||||
|
'state': 'closed'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (var j = 0, len_i = data[i].length; j < len_i; j++) {
|
||||||
|
if (data[i][j] == path_eles[i+1]) {
|
||||||
|
children[i].push({
|
||||||
|
'data': data[i][j],
|
||||||
|
'state': 'open',
|
||||||
|
'children': children[i+1]
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
children[i].push({
|
||||||
|
'data': data[i][j],
|
||||||
|
'state': 'closed'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (children[0].length > 0) {
|
||||||
|
$.extend(repo_data, {'children': children[0]});
|
||||||
|
}
|
||||||
|
json_data.push(repo_data);
|
||||||
|
|
||||||
|
loading_tip.hide();
|
||||||
|
_this.renderDirTree(container, form, json_data);
|
||||||
|
container.removeClass('hide');
|
||||||
|
},
|
||||||
|
error: function() {
|
||||||
|
var cur_repo = [{
|
||||||
|
'data': repo_name,
|
||||||
|
'attr': {'repo_id': repo_id, 'root_node': true},
|
||||||
|
'state': 'closed'
|
||||||
|
}];
|
||||||
|
loading_tip.hide();
|
||||||
|
_this.renderDirTree(container, form, cur_repo);
|
||||||
|
container.removeClass('hide');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user