1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-07-03 18:26:36 +00:00
seahub/static/scripts/app/views/dialogs/repo-history-settings.js

153 lines
5.4 KiB
JavaScript
Raw Normal View History

2015-12-27 14:09:52 +00:00
define([
'jquery',
'underscore',
'backbone',
'common'
], function($, _, Backbone, Common) {
'use strict';
var HistorySettingsDialog = Backbone.View.extend({
2016-01-28 06:33:17 +00:00
2015-12-27 14:09:52 +00:00
template: _.template($('#history-settings-dialog-tmpl').html()),
initialize: function(options) {
this.repo_name = options.repo_name;
this.repo_id = options.repo_id;
this.render();
2016-01-28 06:33:17 +00:00
this.$('.op-target').css({'max-width':280}); // for long repo name
2015-12-27 14:09:52 +00:00
this.$el.modal();
$("#simplemodal-container").css({'height':'auto'});
2016-01-20 07:21:29 +00:00
this.$loadingTip = this.$('.loading-tip');
this.$error = this.$('.error');
2016-01-28 06:33:17 +00:00
this.$form = this.$('form');
2016-01-20 07:21:29 +00:00
this.$radios = this.$('input:radio[name=history]');
this.$days_input = this.$('input:text[name=days]');
2016-01-28 06:33:17 +00:00
this.$submit = this.$('[type=submit]');
2016-01-20 07:21:29 +00:00
this.renderHistorySettings();
2015-12-27 14:09:52 +00:00
},
render: function() {
2016-01-28 06:33:17 +00:00
var repo_name = this.repo_name;
2015-12-27 14:09:52 +00:00
this.$el.html(this.template({
2016-02-07 09:29:49 +00:00
title: gettext("{placeholder} History Setting")
2015-12-27 14:09:52 +00:00
.replace('{placeholder}',
'<span class="op-target ellipsis ellipsis-op-target" title="'
2016-01-28 06:33:17 +00:00
+ Common.HTMLescape(repo_name) + '">'
+ Common.HTMLescape(repo_name) + '</span>'),
2016-01-20 07:21:29 +00:00
default_history_limit: 30
2015-12-27 14:09:52 +00:00
}));
return this;
},
2016-01-20 07:21:29 +00:00
renderHistorySettings: function() {
var _this = this;
$.ajax({
url: Common.getUrl({
'name': 'repo_history_limit',
2016-01-28 06:33:17 +00:00
'repo_id': this.repo_id
2016-01-20 07:21:29 +00:00
}),
type: 'get',
dataType: 'json',
2016-01-28 06:33:17 +00:00
success: function(data) {
2016-01-20 07:21:29 +00:00
_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();
}
});
},
2016-01-28 06:33:17 +00:00
events: {
'change [name="history"]': 'changeHistorySetting',
'submit form': 'formSubmit'
},
// only enable setting keep_days when partial history radio is chosen
changeHistorySetting: function(e) {
var value = $(e.currentTarget).val();
var $days_input = this.$days_input;
if (value == 'full_history' || value == 'no_history') {
$days_input.prop('disabled', true).addClass('input-disabled');
} else {
$days_input.prop('disabled', false).removeClass('input-disabled');
}
},
2016-01-20 07:21:29 +00:00
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);
2015-12-27 14:09:52 +00:00
2016-01-20 07:21:29 +00:00
$.ajax({
url: Common.getUrl({
'name': 'repo_history_limit',
2016-01-28 06:33:17 +00:00
'repo_id': this.repo_id
2016-01-20 07:21:29 +00:00
}),
type: 'put',
dataType: 'json',
beforeSend: Common.prepareCSRFToken,
data: {
'keep_days': days
},
2016-01-28 06:33:17 +00:00
success: function() {
2016-01-20 07:21:29 +00:00
$.modal.close();
2016-01-28 06:33:17 +00:00
Common.feedback(gettext("Successfully set library history."), 'success');
2016-01-20 07:21:29 +00:00
},
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;
2015-12-27 14:09:52 +00:00
}
});
return HistorySettingsDialog;
});