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:
@@ -317,6 +317,7 @@ p { margin:0.5em 0; }
|
||||
.vh { visibility:hidden; }
|
||||
.vam { vertical-align:middle; }
|
||||
.tip { color:#808080; font-size:12px; }
|
||||
.outstanding-tip { color:red; }
|
||||
.label { color:#333; font-size:12px; font-style:normal; }
|
||||
.italic { font-style:italic; }
|
||||
.alc { text-align: center;}
|
||||
|
@@ -50,9 +50,7 @@
|
||||
<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-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-share-link-admin" href="#">{% trans "Sharing Links" %}</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
@@ -1088,23 +1086,26 @@
|
||||
|
||||
<script type="text/template" id="history-settings-dialog-tmpl">
|
||||
<h3><%= title %></h3>
|
||||
<form id="repo-basic-info-form" action="" method="post" class="form">{% csrf_token %}
|
||||
<input type="radio" name="history" value="full_history"
|
||||
<% if (full_history_checked) { %> checked="checked"{ <% } %>
|
||||
class="vam" />
|
||||
|
||||
<p class="history-settings-notice outstanding-tip hide">{% trans "Setting library history is disabled by Admin" %}</p>
|
||||
|
||||
<form id="repo-history-settings-form" action="" method="post" class="form">{% csrf_token %}
|
||||
<input type="radio" name="history" value="full_history" class="vam" />
|
||||
<span class="vam">{% trans "Keep full history" %}</span><br />
|
||||
<input type="radio" name="history" value="no_history"
|
||||
<% 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 />
|
||||
<input type="radio" name="history" value="partial_history"
|
||||
<% if (partial_history_checked) { %>checked="checked"<% } %>
|
||||
class="vam" />
|
||||
|
||||
<input type="radio" name="history" value="partial_history" class="vam" />
|
||||
<span calss="vam">{% trans "Only keep a period of history:" %}
|
||||
<input type="text" name="days" size="4" disabled="disabled"
|
||||
class="input-disabled" value="<%- history_limit %>" /> {% trans "days" %}</span><br />
|
||||
class="input-disabled" value="<%- default_history_limit %>" /> {% trans "days" %}
|
||||
</span><br />
|
||||
|
||||
<input type="submit" value="{% trans "Submit" %}" class="submit" />
|
||||
</form>
|
||||
<span class="loading-icon loading-tip"></span>
|
||||
<p class="error hide"></p>
|
||||
</script>
|
||||
|
||||
<script type="text/template" id="repo-permissions-dialog-tmpl">
|
||||
|
@@ -18,6 +18,27 @@ define([
|
||||
this.render();
|
||||
this.$el.modal();
|
||||
$("#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() {
|
||||
@@ -28,18 +49,101 @@ define([
|
||||
+ Common.HTMLescape(this.repo_name) + '">'
|
||||
+ Common.HTMLescape(this.repo_name) + '</span>'),
|
||||
repo_id: this.repo_id,
|
||||
// TODO: get settings from server
|
||||
full_history_checked: true,
|
||||
no_history_checked: false,
|
||||
partial_history_checked: false,
|
||||
history_limit: 30
|
||||
default_history_limit: 30
|
||||
}));
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
});
|
||||
|
@@ -37,11 +37,7 @@ define([
|
||||
},
|
||||
|
||||
render: function() {
|
||||
var obj = this.model.toJSON();
|
||||
$.extend(obj, {
|
||||
enable_repo_history_setting: app.pageOptions.enable_repo_history_setting
|
||||
});
|
||||
this.$el.html(this.template(obj));
|
||||
this.$el.html(this.template(this.model.toJSON()));
|
||||
return this;
|
||||
},
|
||||
|
||||
|
@@ -100,6 +100,7 @@ define([
|
||||
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 'transfer_repo': return siteRoot + 'api2/repos/' + options.repo_id + '/owner/';
|
||||
case 'repo_history_limit': return siteRoot + 'api2/repos/' + options.repo_id + '/history-limit/';
|
||||
|
||||
// Permission
|
||||
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) {
|
||||
btn.removeAttr('disabled').removeClass('btn-disabled');
|
||||
},
|
||||
|
Reference in New Issue
Block a user