1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-08-31 22:54:11 +00:00

Add setting library history

This commit is contained in:
Daniel Pan
2016-01-20 15:21:29 +08:00
committed by llj
parent 54a29bc743
commit adf9837337
6 changed files with 143 additions and 41 deletions

View File

@@ -317,6 +317,7 @@ p { margin:0.5em 0; }
.vh { visibility:hidden; } .vh { visibility:hidden; }
.vam { vertical-align:middle; } .vam { vertical-align:middle; }
.tip { color:#808080; font-size:12px; } .tip { color:#808080; font-size:12px; }
.outstanding-tip { color:red; }
.label { color:#333; font-size:12px; font-style:normal; } .label { color:#333; font-size:12px; font-style:normal; }
.italic { font-style:italic; } .italic { font-style:italic; }
.alc { text-align: center;} .alc { text-align: center;}

View File

@@ -5,10 +5,10 @@
<label>{% trans "Name"%}</label><br/> <label>{% trans "Name"%}</label><br/>
<input type="text" name="repo_name" value="" maxlength="{{max_file_name}}" class="input" /><br /> <input type="text" name="repo_name" value="" maxlength="{{max_file_name}}" class="input" /><br />
<% if (showSharePerm) { %> <% if (showSharePerm) { %>
<label>{% trans "Share Permission"%}</label><br /> <label>{% trans "Share Permission" %}</label><br />
<select name="permission" class="perm"> <select name="permission" class="perm">
<option value="rw" selected="selected">{% trans "Read-Write"%}</option> <option value="rw" selected="selected">{% trans "Read-Write" %}</option>
<option value="r">{% trans "Read-Only"%}</option> <option value="r">{% trans "Read-Only" %}</option>
</select> </select>
<br /> <br />
<% } %> <% } %>
@@ -16,11 +16,11 @@
<div class="repo-create-encryption"> <div class="repo-create-encryption">
<label class="checkbox-label"> <label class="checkbox-label">
<span class="checkbox"><input type="checkbox" name="encryption" id="encrypt-switch" class="checkbox-orig" /></span> <span class="checkbox"><input type="checkbox" name="encryption" id="encrypt-switch" class="checkbox-orig" /></span>
<span class="checkbox-option">{% trans "Encrypt"%}</span> <span class="checkbox-option">{% trans "Encrypt" %}</span>
</label> </label>
<label>{% trans "Password"%}</label><span class="tip">{% blocktrans %}(at least {{repo_password_min_length}} characters){% endblocktrans %}</span><br /> <label>{% trans "Password" %}</label><span class="tip">{% blocktrans %}(at least {{repo_password_min_length}} characters){% endblocktrans %}</span><br />
<input type="password" name="passwd" disabled="disabled" class="input input-disabled" /><br /> <input type="password" name="passwd" disabled="disabled" class="input input-disabled" /><br />
<label>{% trans "Password again"%}</label><br /> <label>{% trans "Password again" %}</label><br />
<input type="password" name="passwd_again" disabled="disabled" class="input input-disabled" /> <input type="password" name="passwd_again" disabled="disabled" class="input input-disabled" />
</div> </div>
<% } %> <% } %>
@@ -50,9 +50,7 @@
<li><a class="op js-repo-rename" href="#">{% trans "Rename" %}</a></li> <li><a class="op js-repo-rename" href="#">{% trans "Rename" %}</a></li>
<li><a class="op js-repo-transfer" href="#">{% trans "Transfer" %}</a></li> <li><a class="op js-repo-transfer" href="#">{% trans "Transfer" %}</a></li>
<li><a class="op js-popup-permission-settings" href="#">{% trans "Permissions" %}</a></li> <li><a class="op js-popup-permission-settings" href="#">{% trans "Permissions" %}</a></li>
<% if (enable_repo_history_setting) { %>
<li><a class="op js-popup-history-settings" href="#">{% trans "History Settings" %}</a></li> <li><a class="op js-popup-history-settings" href="#">{% trans "History Settings" %}</a></li>
<% } %>
<li><a class="op js-popup-share-link-admin" href="#">{% trans "Sharing Links" %}</a></li> <li><a class="op js-popup-share-link-admin" href="#">{% trans "Sharing Links" %}</a></li>
</ul> </ul>
</div> </div>
@@ -1088,23 +1086,26 @@
<script type="text/template" id="history-settings-dialog-tmpl"> <script type="text/template" id="history-settings-dialog-tmpl">
<h3><%= title %></h3> <h3><%= title %></h3>
<form id="repo-basic-info-form" action="" method="post" class="form">{% csrf_token %}
<input type="radio" name="history" value="full_history" <p class="history-settings-notice outstanding-tip hide">{% trans "Setting library history is disabled by Admin" %}</p>
<% if (full_history_checked) { %> checked="checked"{ <% } %>
class="vam" /> <form id="repo-history-settings-form" action="" method="post" class="form">{% csrf_token %}
<span class="vam">{% trans "Keep full history" %}</span><br /> <input type="radio" name="history" value="full_history" class="vam" />
<input type="radio" name="history" value="no_history" <span class="vam">{% trans "Keep full history" %}</span><br />
<% if (no_history_checked) { %>checked="checked"<% } %>
class="vam" /> <input type="radio" name="history" value="no_history" class="vam" />
<span class="vam">{% trans "Don't keep history" %}</span><br /> <span class="vam">{% trans "Don't keep history" %}</span><br />
<input type="radio" name="history" value="partial_history"
<% if (partial_history_checked) { %>checked="checked"<% } %> <input type="radio" name="history" value="partial_history" class="vam" />
class="vam" /> <span calss="vam">{% trans "Only keep a period of history:" %}
<span calss="vam">{% trans "Only keep a period of history:" %} <input type="text" name="days" size="4" disabled="disabled"
<input type="text" name="days" size="4" disabled="disabled" class="input-disabled" value="<%- default_history_limit %>" /> {% trans "days" %}
class="input-disabled" value="<%- history_limit %>" /> {% trans "days" %}</span><br /> </span><br />
<input type="submit" value="{% trans "Submit" %}" class="submit" /> <input type="submit" value="{% trans "Submit" %}" class="submit" />
</form> </form>
<span class="loading-icon loading-tip"></span>
<p class="error hide"></p>
</script> </script>
<script type="text/template" id="repo-permissions-dialog-tmpl"> <script type="text/template" id="repo-permissions-dialog-tmpl">

View File

@@ -18,6 +18,27 @@ define([
this.render(); this.render();
this.$el.modal(); this.$el.modal();
$("#simplemodal-container").css({'height':'auto'}); $("#simplemodal-container").css({'height':'auto'});
this.$loadingTip = this.$('.loading-tip');
this.$error = this.$('.error');
this.$form = this.$('#repo-history-settings-form');
this.$radios = this.$('input:radio[name=history]');
this.$days_input = this.$('input:text[name=days]');
this.$submit = this.$('input[type=submit]');
this.renderHistorySettings();
// only enable setting keep_days when partial history radio is chosen
var _this = this;
this.$radios.change(function() {
var value = $(this).attr('value');
if (value == 'full_history' || value == 'no_history') {
_this.$days_input.prop('disabled', true).addClass('input-disabled');
} else {
_this.$days_input.prop('disabled', false).removeClass('input-disabled');
}
});
}, },
render: function() { render: function() {
@@ -28,18 +49,101 @@ define([
+ Common.HTMLescape(this.repo_name) + '">' + Common.HTMLescape(this.repo_name) + '">'
+ Common.HTMLescape(this.repo_name) + '</span>'), + Common.HTMLescape(this.repo_name) + '</span>'),
repo_id: this.repo_id, repo_id: this.repo_id,
// TODO: get settings from server default_history_limit: 30
full_history_checked: true,
no_history_checked: false,
partial_history_checked: false,
history_limit: 30
})); }));
return this; return this;
}, },
events: { events: {
'submit form': 'formSubmit'
},
renderHistorySettings: function() {
var _this = this;
$.ajax({
url: Common.getUrl({
'name': 'repo_history_limit',
'repo_id': _this.repo_id
}),
type: 'get',
dataType: 'json',
beforeSend: Common.prepareCSRFToken,
success: function(data) { // data: { keep_days: -1 }
_this.$loadingTip.hide();
if (data.keep_days <= -1) {
_this.$radios.filter('[value=full_history]').prop('checked', true);
} else if (data.keep_days == 0) {
_this.$radios.filter('[value=no_history]').prop('checked', true);
} else {
_this.$radios.filter('[value=partial_history]').prop('checked', true);
_this.$days_input.prop('disabled', false).removeClass('input-disabled');
_this.$days_input.attr('value', data.keep_days);
}
if (!app.pageOptions.enable_repo_history_setting) {
_this.$('.history-settings-notice').removeClass('hide');
_this.$radios.prop('disabled', true);
_this.$days_input.prop('disabled', true).addClass('input-disabled');
_this.$submit.prop('disabled', true).addClass('btn-disabled');
}
},
error: function(xhr) {
var err_msg;
if (xhr.responseText) {
err_msg = $.parseJSON(xhr.responseText).error_msg;
} else {
err_msg = gettext("Failed. Please check the network.");
}
_this.$error.html(err_msg).show();
}
});
},
formSubmit: function() {
var days;
var value = this.$radios.filter(':checked').val();
var _this = this;
if (value == 'partial_history') {
days = this.$days_input.val();
} else if (value == 'full_history') {
days = -1;
} else {
days = 0;
}
this.$submit.prop('disabled', true);
$.ajax({
url: Common.getUrl({
'name': 'repo_history_limit',
'repo_id': _this.repo_id
}),
type: 'put',
dataType: 'json',
beforeSend: Common.prepareCSRFToken,
data: {
'keep_days': days
},
success: function(data) {
$.modal.close();
Common.feedback(gettext("Set library history succeeded."), 'success');
},
error: function(xhr) {
var err_msg;
if (xhr.responseText) {
err_msg = $.parseJSON(xhr.responseText).error_msg;
} else {
err_msg = gettext("Failed. Please check the network.");
}
_this.$error.html(err_msg).show();
Common.enableButton(_this.$submit);
}
});
return false;
} }
}); });

View File

@@ -15,8 +15,8 @@ define([
initialize: function(options) { initialize: function(options) {
this.group_id = options.group_id; this.group_id = options.group_id;
this.group_name = options.group_name; this.group_name = options.group_name;
this.is_owner = options.is_owner; this.is_owner = options.is_owner;
this.render(); this.render();
this.$el.modal({ this.$el.modal({
@@ -42,7 +42,7 @@ define([
this.setConMaxHeight(); this.setConMaxHeight();
this.$loadingTip = this.$('.loading-tip'); this.$loadingTip = this.$('.loading-tip');
this.$listContainer = this.$('tbody'); this.$listContainer = this.$('tbody');
this.$error = this.$('.error'); this.$error = this.$('.error');
var _this = this; var _this = this;
@@ -101,7 +101,7 @@ define([
data: {'avatar_size': 40}, data: {'avatar_size': 40},
success: function(collection, response, opts) { success: function(collection, response, opts) {
_this.$loadingTip.hide(); _this.$loadingTip.hide();
}, },
error: function(collection, response, opts) { error: function(collection, response, opts) {
_this.$loadingTip.hide(); _this.$loadingTip.hide();
var err_msg; var err_msg;
@@ -134,7 +134,7 @@ define([
prepend: true, prepend: true,
success: function() { success: function() {
$input.select2('val', ''); $input.select2('val', '');
}, },
error: function(collection, response, options) { error: function(collection, response, options) {
$input.select2('val', ''); $input.select2('val', '');
var err_msg; var err_msg;
@@ -142,9 +142,9 @@ define([
err_msg = response.responseJSON.error_msg; err_msg = response.responseJSON.error_msg;
} else { } else {
err_msg = gettext('Please check the network.'); err_msg = gettext('Please check the network.');
} }
_this.$error.html(err_msg).show(); _this.$error.html(err_msg).show();
} }
}); });
} else { } else {
$.ajax({ $.ajax({

View File

@@ -37,11 +37,7 @@ define([
}, },
render: function() { render: function() {
var obj = this.model.toJSON(); this.$el.html(this.template(this.model.toJSON()));
$.extend(obj, {
enable_repo_history_setting: app.pageOptions.enable_repo_history_setting
});
this.$el.html(this.template(obj));
return this; return this;
}, },

View File

@@ -100,6 +100,7 @@ define([
case 'ajax_unset_inner_pub_repo': return siteRoot + 'ajax/unset-inner-pub-repo/' + options.repo_id + '/'; case 'ajax_unset_inner_pub_repo': return siteRoot + 'ajax/unset-inner-pub-repo/' + options.repo_id + '/';
case 'rename_repo': return siteRoot + 'api2/repos/' + options.repo_id + '/?op=rename'; case 'rename_repo': return siteRoot + 'api2/repos/' + options.repo_id + '/?op=rename';
case 'transfer_repo': return siteRoot + 'api2/repos/' + options.repo_id + '/owner/'; case 'transfer_repo': return siteRoot + 'api2/repos/' + options.repo_id + '/owner/';
case 'repo_history_limit': return siteRoot + 'api2/repos/' + options.repo_id + '/history-limit/';
// Permission // Permission
case 'set_user_folder_perm': return siteRoot + 'ajax/repo/' + options.repo_id + '/set-user-folder-perm/'; case 'set_user_folder_perm': return siteRoot + 'ajax/repo/' + options.repo_id + '/set-user-folder-perm/';
@@ -180,7 +181,6 @@ define([
} }
}, },
// TODO: Change to jquery function like $.disableButtion(btn)
enableButton: function(btn) { enableButton: function(btn) {
btn.removeAttr('disabled').removeClass('btn-disabled'); btn.removeAttr('disabled').removeClass('btn-disabled');
}, },