1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-18 08:16:07 +00:00

[dir view] bugfix for 'magnificPopup' & 'grid-item download'

This commit is contained in:
llj
2017-02-25 17:36:07 +08:00
parent 8a113bf1eb
commit acc1ebb6eb
6 changed files with 143 additions and 13 deletions

View File

@@ -17,6 +17,9 @@ define([
this.dir = options.dir;
this.op_type = options.op_type;
this.dirView = options.dirView;
this.imgIndex = options.imgIndex;
// only show current repo if current repo is read-write
this.show_cur_repo = this.dirent.get('perm') == 'rw' ? true : false;
@@ -64,6 +67,15 @@ define([
return this;
},
removeImgItem: function() {
if (this.dirent.get('is_img')) {
this.dirView.updateMagnificPopupOptions({
'op': 'delete-item',
'index': this.imgIndex
});
}
},
events: {
'submit form': 'formSubmit'
},
@@ -112,6 +124,7 @@ define([
$.modal.close();
if (op == 'mv') {
_this.dir.remove(_this.dirent);
_this.removeImgItem();
}
Common.feedback(msg, 'success');
} else { // failed or canceled
@@ -206,6 +219,7 @@ define([
if (!data['task_id']) { // no progress
if (_this.op_type == 'mv') {
_this.dir.remove(_this.dirent);
_this.removeImgItem();
}
Common.feedback(msg, 'success');
} else {

View File

@@ -14,6 +14,9 @@ define([
this.dirent = options.dirent;
this.dir = options.dir;
this.dirView = options.dirView;
this.imgIndex = options.imgIndex;
this.render();
this.$el.modal({appendTo:'#main', focus: false});
$('#simplemodal-container').css({'width':'auto', 'height':'auto'});
@@ -65,6 +68,14 @@ define([
newname: new_name,
success: function() {
$.modal.close();
if (_this.dirent.get('is_img')) {
_this.dirView.updateMagnificPopupOptions({
'op': 'update-item',
'index': _this.imgIndex,
'model': _this.dirent
});
}
},
error: function(xhr, textStatus, errorThrown) {
var err;

View File

@@ -185,22 +185,61 @@ define([
this.getImageThumbnail();
},
updateMagnificPopupOptions: function() {
var imgs = this.dir.where({is_img: true});
var items = [];
updateMagnificPopupOptions: function(options) {
var repo_id = this.dir.repo_id,
path = this.dir.path;
$(imgs).each(function(index, model) {
var genItem = function(model) {
var name = model.get('obj_name');
var dirent_path = Common.pathJoin([path, name]);
items.push({
var item = {
'name': name,
'url': model.getWebUrl(),
'src': app.config.siteRoot + 'repo/' + repo_id + '/raw' + Common.encodePath(dirent_path)
});
});
};
return item;
};
this.magnificPopupOptions.items = items;
var _this = this;
var getItems = function() {
var imgs = _this.dir.where({is_img: true});
var items = [];
$(imgs).each(function(index, model) {
var item = genItem(model);
items.push(item);
});
_this.magnificPopupOptions.items = items;
};
var addNewItem = function(model) {
var item = genItem(model);
// add the new item as the first
_this.magnificPopupOptions.items.unshift(item);
};
var updateItem = function(index, model) {
var item = genItem(model);
_this.magnificPopupOptions.items[index] = item;
};
var deleteItem = function(index) {
_this.magnificPopupOptions.items.splice(index, 1);
};
var op = options ? options.op : 'get-items';
switch (op) {
case 'get-items':
getItems();
break;
case 'add-new-item':
addNewItem(options.model);
break;
case 'update-item':
updateItem(options.index, options.model);
break;
case 'delete-item':
deleteItem(options.index);
break;
}
},
// for fileupload
@@ -632,6 +671,10 @@ define([
}
}
}
if (new_dirent.get('is_img')) {
this.updateMagnificPopupOptions({'op':'add-new-item', 'model':new_dirent});
}
},
addNewDir: function(new_dirent) {
@@ -828,7 +871,7 @@ define([
data: {
'dirents_names': selected_names
},
success: function(data) {
success: function(data) { // data['deleted']: [name,]
var del_len = data['deleted'].length,
not_del_len = data['undeleted'].length,
msg_s, msg_f;
@@ -855,6 +898,8 @@ define([
}
msg_s = msg_s.replace('%(name)s', data['deleted'][0]).replace('%(amount)s', del_len - 1);
Common.feedback(msg_s, 'success');
_this.updateMagnificPopupOptions(); // after Successfully deleting some items
}
if (not_del_len > 0) {
if (not_del_len == 1) {
@@ -1000,6 +1045,7 @@ define([
} else {
msg_s = gettext("Successfully moved %(name)s and %(amount)s other items.");
}
_this.updateMagnificPopupOptions(); // after moving items in the same library
} else { // cp
if (success_len == 1) {
msg_s = gettext("Successfully copied %(name)s.");
@@ -1148,12 +1194,18 @@ define([
var endOrContinue = function () {
if (i == op_objs.length - 1) {
setTimeout(function () { $.modal.close(); }, 500);
if (op == 'mv') {
_this.updateMagnificPopupOptions();
}
} else {
mvcpDirent(++i);
}
};
var end = function () {
setTimeout(function () { $.modal.close(); }, 500);
if (op == 'mv') {
_this.updateMagnificPopupOptions();
}
};
mvcpDirent();
cancel_btn.click(function() {

View File

@@ -64,6 +64,7 @@ define([
if (this.model.get('is_img')) {
// use specific links such as .img-link, .text-link, in order to make 'open by index' work
this.$('.img-link, .text-link').magnificPopup(this.dirView.magnificPopupOptions);
this.$el.addClass('img-grid-item');
}
return this;
@@ -107,6 +108,7 @@ define([
var op = template({
dirent: this.model.attributes,
dirent_path: this.model.getPath(),
download_url: this.model.getDownloadUrl(),
category: dir.category,
repo_id: dir.repo_id,
is_repo_owner: dir.is_repo_owner,
@@ -126,7 +128,7 @@ define([
// Using _.bind(function, object) to make that whenever the function is
// called, the value of this will be the object.
this.$('.download').on('click', _.bind(this.download, this));
this.$('.download-dir').on('click', _.bind(this.download, this));
this.$('.delete').on('click', _.bind(this.del, this));
this.$('.share').on('click', _.bind(this.share, this));
this.$('.mv').on('click', _.bind(this.mvcp, this));
@@ -142,7 +144,7 @@ define([
viewImageWithPopup: function() {
if (this.model.get('is_img')) {
var index = _.indexOf(this.dir.where({'is_img': true}), this.model);
var index = $('.img-grid-item', this.dirView.$dirent_grid).index(this.$el);
$.magnificPopup.open(this.dirView.magnificPopupOptions, index); // open by index
}
},
@@ -159,7 +161,12 @@ define([
return false;
},
del: function(event) {
del: function() {
var _this = this;
if (this.model.get('is_img')) {
var index = $('.img-grid-item', this.dirView.$dirent_grid).index(this.$el);
}
this.closeMenu();
var dirent_name = this.model.get('obj_name');
this.model.deleteFromServer({
@@ -167,6 +174,10 @@ define([
var msg = gettext("Successfully deleted %(name)s")
.replace('%(name)s', dirent_name);
Common.feedback(msg, 'success');
if (_this.model.get('is_img')) {
_this.dirView.updateMagnificPopupOptions({'op':'delete-item', 'index':index});
}
},
error: function(xhr) {
Common.ajaxErrorHandler(xhr);
@@ -203,6 +214,14 @@ define([
'op_type': op_type
};
if (this.model.get('is_img') && op_type == 'mv') {
var index = $('.img-grid-item', this.dirView.$dirent_grid).index(this.$el);
$.extend(options, {
'dirView': this.dirView,
'imgIndex': index
});
}
new DirentMvcpDialog(options);
this.closeMenu();
return false;
@@ -214,6 +233,14 @@ define([
'dir': this.dir,
'dirent': this.model
};
if (this.model.get('is_img')) {
var index = $('.img-grid-item', this.dirView.$dirent_grid).index(this.$el);
$.extend(options, {
'dirView': this.dirView,
'imgIndex': index
});
}
new DirentRenameDialog(options);
return false;
},

View File

@@ -201,12 +201,21 @@ define([
},
del: function() {
var _this = this;
if (this.model.get('is_img')) {
var index = $('.img-name-link', this.dirView.$dirent_list).index(this.$('.img-name-link'));
}
var dirent_name = this.model.get('obj_name');
this.model.deleteFromServer({
success: function(data) {
var msg = gettext("Successfully deleted %(name)s")
.replace('%(name)s', dirent_name);
Common.feedback(msg, 'success');
if (_this.model.get('is_img')) {
_this.dirView.updateMagnificPopupOptions({'op':'delete-item', 'index':index});
}
},
error: function(xhr) {
Common.ajaxErrorHandler(xhr);
@@ -216,6 +225,7 @@ define([
},
rename: function() {
var _this = this;
var dirent_name = this.model.get('obj_name');
var form = $(this.renameTemplate({
@@ -248,6 +258,15 @@ define([
if (app.ui.currentHighlightedItem) {
app.ui.currentHighlightedItem.rmHighlight();
}
if (_this.model.get('is_img')) {
var index = $('.img-name-link', _this.dirView.$dirent_list).index(_this.$('.img-name-link'));
_this.dirView.updateMagnificPopupOptions({
'op': 'update-item',
'index': index,
'model': _this.model
}); // update the item
}
};
var cancelRename = function() {
app.ui.freezeItemHightlight = false;
@@ -305,6 +324,13 @@ define([
'dirent': this.model,
'op_type': op_type
};
if (this.model.get('is_img') && op_type == 'mv') {
var index = $('.img-name-link', this.dirView.$dirent_list).index(this.$('.img-name-link'));
$.extend(options, {
'dirView': this.dirView,
'imgIndex': index
});
}
this._hideMenu();
new DirentMvcpDialog(options);