mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-18 08:16:07 +00:00
Add setting library history
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
});
|
||||
|
@@ -15,8 +15,8 @@ define([
|
||||
initialize: function(options) {
|
||||
|
||||
this.group_id = options.group_id;
|
||||
this.group_name = options.group_name;
|
||||
this.is_owner = options.is_owner;
|
||||
this.group_name = options.group_name;
|
||||
this.is_owner = options.is_owner;
|
||||
|
||||
this.render();
|
||||
this.$el.modal({
|
||||
@@ -42,7 +42,7 @@ define([
|
||||
this.setConMaxHeight();
|
||||
|
||||
this.$loadingTip = this.$('.loading-tip');
|
||||
this.$listContainer = this.$('tbody');
|
||||
this.$listContainer = this.$('tbody');
|
||||
this.$error = this.$('.error');
|
||||
|
||||
var _this = this;
|
||||
@@ -101,7 +101,7 @@ define([
|
||||
data: {'avatar_size': 40},
|
||||
success: function(collection, response, opts) {
|
||||
_this.$loadingTip.hide();
|
||||
},
|
||||
},
|
||||
error: function(collection, response, opts) {
|
||||
_this.$loadingTip.hide();
|
||||
var err_msg;
|
||||
@@ -134,7 +134,7 @@ define([
|
||||
prepend: true,
|
||||
success: function() {
|
||||
$input.select2('val', '');
|
||||
},
|
||||
},
|
||||
error: function(collection, response, options) {
|
||||
$input.select2('val', '');
|
||||
var err_msg;
|
||||
@@ -142,9 +142,9 @@ define([
|
||||
err_msg = response.responseJSON.error_msg;
|
||||
} else {
|
||||
err_msg = gettext('Please check the network.');
|
||||
}
|
||||
}
|
||||
_this.$error.html(err_msg).show();
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
$.ajax({
|
||||
|
@@ -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;
|
||||
},
|
||||
|
||||
|
Reference in New Issue
Block a user