mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-04 08:28:11 +00:00
Add lock/unlock function and fix a bug in DirentGridView menu event binding
This commit is contained in:
@@ -3833,6 +3833,7 @@ img.thumbnail {
|
|||||||
position:relative;
|
position:relative;
|
||||||
}
|
}
|
||||||
.grid-item .img-link {
|
.grid-item .img-link {
|
||||||
|
position:relative; /* for locked icon */
|
||||||
display:block;
|
display:block;
|
||||||
text-align:center;
|
text-align:center;
|
||||||
height:100px;
|
height:100px;
|
||||||
@@ -3880,6 +3881,11 @@ img.thumbnail {
|
|||||||
border-radius:3px;
|
border-radius:3px;
|
||||||
margin:0;
|
margin:0;
|
||||||
}
|
}
|
||||||
|
.grid-file-locked-icon {
|
||||||
|
position:absolute;
|
||||||
|
bottom:0px;
|
||||||
|
right:10px;
|
||||||
|
}
|
||||||
.grid-item-op {
|
.grid-item-op {
|
||||||
position:fixed;
|
position:fixed;
|
||||||
}
|
}
|
||||||
|
@@ -348,6 +348,9 @@
|
|||||||
<script type="text/template" id="grid-view-file-item-tmpl">
|
<script type="text/template" id="grid-view-file-item-tmpl">
|
||||||
<a href="<%= url %>" class="img-link" target="_blank">
|
<a href="<%= url %>" class="img-link" target="_blank">
|
||||||
<img src="<%= icon_url %>" alt="" width="96" class="vam" />
|
<img src="<%= icon_url %>" alt="" width="96" class="vam" />
|
||||||
|
<% if (is_pro && dirent.is_locked) { %>
|
||||||
|
<img class="grid-file-locked-icon" width="16" src="{{ MEDIA_URL }}img/file-locked-32.png" alt="{% trans "locked" %}" />
|
||||||
|
<% } %>
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
<a href="<%= url %>" class="ellipsis text-link normal" target="_blank">
|
<a href="<%= url %>" class="ellipsis text-link normal" target="_blank">
|
||||||
|
@@ -126,7 +126,74 @@ define([
|
|||||||
options.error(xhr);
|
options.error(xhr);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
},
|
||||||
|
|
||||||
|
lockOrUnlockFile: function(options) {
|
||||||
|
var dir = this.collection,
|
||||||
|
filepath = this.getPath();
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: Common.getUrl({name: 'lock_or_unlock_file', repo_id: dir.repo_id}),
|
||||||
|
type: 'PUT',
|
||||||
|
dataType: 'json',
|
||||||
|
data: {
|
||||||
|
'operation': options.op,
|
||||||
|
'p': filepath
|
||||||
|
},
|
||||||
|
cache: false,
|
||||||
|
beforeSend: Common.prepareCSRFToken,
|
||||||
|
success: function() {
|
||||||
|
options.success();
|
||||||
|
},
|
||||||
|
error: function(xhr) {
|
||||||
|
options.error(xhr);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
lockFile: function(options) {
|
||||||
|
var _this = this;
|
||||||
|
this.lockOrUnlockFile({
|
||||||
|
op: 'lock',
|
||||||
|
success: function() {
|
||||||
|
_this.set({
|
||||||
|
'is_locked': true,
|
||||||
|
'locked_by_me': true,
|
||||||
|
'lock_owner_name': app.pageOptions.name
|
||||||
|
});
|
||||||
|
if (options.success) {
|
||||||
|
options.success();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
error: function(xhr) {
|
||||||
|
if (options.error) {
|
||||||
|
options.error(xhr)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return false;
|
||||||
|
},
|
||||||
|
|
||||||
|
unlockFile: function(options) {
|
||||||
|
var _this = this;
|
||||||
|
this.lockOrUnlockFile({
|
||||||
|
op: 'unlock',
|
||||||
|
success: function() {
|
||||||
|
_this.set({
|
||||||
|
'is_locked': false
|
||||||
|
});
|
||||||
|
if (options.success) {
|
||||||
|
options.success();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
error: function(xhr) {
|
||||||
|
if (options.error) {
|
||||||
|
options.error(xhr)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return false;
|
||||||
|
},
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@@ -128,21 +128,24 @@ define([
|
|||||||
|
|
||||||
// Using _.bind(function, object) to make that whenever the function is
|
// Using _.bind(function, object) to make that whenever the function is
|
||||||
// called, the value of this will be the object.
|
// called, the value of this will be the object.
|
||||||
this.$el.on('click', '.delete', _.bind(this.del, this));
|
this.$('.delete').on('click', _.bind(this.del, this));
|
||||||
this.$el.on('click', '.share', _.bind(this.share, this));
|
this.$('.share').on('click', _.bind(this.share, this));
|
||||||
this.$el.on('click', '.mv', _.bind(this.mvcp, this));
|
this.$('.mv').on('click', _.bind(this.mvcp, this));
|
||||||
this.$el.on('click', '.cp', _.bind(this.mvcp, this));
|
this.$('.cp').on('click', _.bind(this.mvcp, this));
|
||||||
this.$el.on('click', '.rename', _.bind(this.rename, this));
|
this.$('.rename').on('click', _.bind(this.rename, this));
|
||||||
this.$el.on('click', '.open-via-client', _.bind(this.open_via_client, this));
|
this.$('.open-via-client').on('click', _.bind(this.open_via_client, this));
|
||||||
|
this.$('.lock-file').on('click', _.bind(this.lockFile, this));
|
||||||
|
this.$('.unlock-file').on('click', _.bind(this.unlockFile, this));
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
|
|
||||||
_closeMenu: function() {
|
closeMenu: function() {
|
||||||
this.$('.grid-item-op').remove();
|
this.$('.grid-item-op').remove();
|
||||||
},
|
},
|
||||||
|
|
||||||
del: function(event) {
|
del: function(event) {
|
||||||
|
this.closeMenu();
|
||||||
var dirent_name = this.model.get('obj_name');
|
var dirent_name = this.model.get('obj_name');
|
||||||
this.model.deleteFromServer({
|
this.model.deleteFromServer({
|
||||||
success: function(data) {
|
success: function(data) {
|
||||||
@@ -173,7 +176,7 @@ define([
|
|||||||
'obj_name': obj_name
|
'obj_name': obj_name
|
||||||
};
|
};
|
||||||
new ShareView(options);
|
new ShareView(options);
|
||||||
this._closeMenu();
|
this.closeMenu();
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -186,12 +189,12 @@ define([
|
|||||||
};
|
};
|
||||||
|
|
||||||
new DirentMvcpDialog(options);
|
new DirentMvcpDialog(options);
|
||||||
this._closeMenu();
|
this.closeMenu();
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
|
|
||||||
rename: function() {
|
rename: function() {
|
||||||
this._closeMenu();
|
this.closeMenu();
|
||||||
var options = {
|
var options = {
|
||||||
'dir': this.dir,
|
'dir': this.dir,
|
||||||
'dirent': this.model
|
'dirent': this.model
|
||||||
@@ -200,8 +203,32 @@ define([
|
|||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
lockFile: function() {
|
||||||
|
this.closeMenu();
|
||||||
|
this.model.lockFile({
|
||||||
|
success: function() {
|
||||||
|
},
|
||||||
|
error: function(xhr) {
|
||||||
|
Common.ajaxErrorHandler(xhr);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return false;
|
||||||
|
},
|
||||||
|
|
||||||
|
unlockFile: function() {
|
||||||
|
this.closeMenu();
|
||||||
|
this.model.unlockFile({
|
||||||
|
success: function() {
|
||||||
|
},
|
||||||
|
error: function(xhr) {
|
||||||
|
Common.ajaxErrorHandler(xhr);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return false;
|
||||||
|
},
|
||||||
|
|
||||||
open_via_client: function() {
|
open_via_client: function() {
|
||||||
this._closeMenu();
|
this.closeMenu();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -456,41 +456,14 @@ define([
|
|||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
|
|
||||||
lockOrUnlockFile: function(params) {
|
|
||||||
var dir = this.dir,
|
|
||||||
filepath = Common.pathJoin([dir.path, this.model.get('obj_name')]),
|
|
||||||
callback = params.after_success;
|
|
||||||
|
|
||||||
$.ajax({
|
|
||||||
url: Common.getUrl({name: 'lock_or_unlock_file', repo_id: dir.repo_id}),
|
|
||||||
type: 'PUT',
|
|
||||||
dataType: 'json',
|
|
||||||
data: {
|
|
||||||
'operation': params.op,
|
|
||||||
'p': filepath
|
|
||||||
},
|
|
||||||
cache: false,
|
|
||||||
beforeSend: Common.prepareCSRFToken,
|
|
||||||
success: function() {
|
|
||||||
callback();
|
|
||||||
},
|
|
||||||
error: function (xhr) {
|
|
||||||
Common.ajaxErrorHandler(xhr);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
lockFile: function() {
|
lockFile: function() {
|
||||||
var _this = this;
|
var _this = this;
|
||||||
this.lockOrUnlockFile({
|
this.model.lockFile({
|
||||||
'op': 'lock',
|
success: function() {
|
||||||
'after_success': function() {
|
|
||||||
_this.model.set({
|
|
||||||
'is_locked': true,
|
|
||||||
'locked_by_me': true,
|
|
||||||
'lock_owner_name': app.pageOptions.name
|
|
||||||
});
|
|
||||||
_this.$el.removeClass('hl');
|
_this.$el.removeClass('hl');
|
||||||
|
},
|
||||||
|
error: function(xhr) {
|
||||||
|
Common.ajaxErrorHandler(xhr);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return false;
|
return false;
|
||||||
@@ -498,13 +471,12 @@ define([
|
|||||||
|
|
||||||
unlockFile: function() {
|
unlockFile: function() {
|
||||||
var _this = this;
|
var _this = this;
|
||||||
this.lockOrUnlockFile({
|
this.model.unlockFile({
|
||||||
'op': 'unlock',
|
success: function() {
|
||||||
'after_success': function() {
|
|
||||||
_this.model.set({
|
|
||||||
'is_locked': false
|
|
||||||
});
|
|
||||||
_this.$el.removeClass('hl');
|
_this.$el.removeClass('hl');
|
||||||
|
},
|
||||||
|
error: function(xhr) {
|
||||||
|
Common.ajaxErrorHandler(xhr);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return false;
|
return false;
|
||||||
|
Reference in New Issue
Block a user