diff --git a/kfet/static/kfet/js/history.js b/kfet/static/kfet/js/history.js index 008eb8d1..607b8147 100644 --- a/kfet/static/kfet/js/history.js +++ b/kfet/static/kfet/js/history.js @@ -16,171 +16,94 @@ class History { this.api_options = { 'from': moment().subtract(3, 'days').format('YYYY-MM-DD HH:mm:ss'), }; - } -} + this.display_options = {} ; -function KHistory(options={}) { - $.extend(this, KHistory.default_options, options); - - this.$container = $(this.container); - - this.reset = function() { - this.$container.html(''); - }; - - this.addOpeGroup = function(opegroup) { - var $day = this._getOrCreateDay(opegroup['at']); - var $opegroup = this._opeGroupHtml(opegroup); - - $day.after($opegroup); - - var trigramme = opegroup['on_acc_trigramme']; - var is_cof = opegroup['is_cof']; - var type = opegroup['type'] - switch (type) { - case 'opegroup': - for (var i=0; i 0) + that.cancel_operations(to_cancel); + } + }); + } + + //TODO: permission management in another class ? + cancel_operations(to_cancel, password='') { + if (kpsul.lock == 1) + return false; + kpsul.lock = 1; + + var data = { 'operations': to_cancel }; + + $.ajax({ + dataType: "json", + url : Urls['kfet.kpsul.cancel_operations'](), + method : "POST", + data : data, + beforeSend: function ($xhr) { + $xhr.setRequestHeader("X-CSRFToken", csrftoken); + if (password != '') + $xhr.setRequestHeader("KFetPassword", password); + }, + }) + .done(function(data) { + kpsul._env.coolReset(); + kpsul.lock = 0; + }) + .fail(function($xhr) { + var data = $xhr.responseJSON; + switch ($xhr.status) { + case 403: + requestAuth(data, function(password) { + cancelOperations(to_cancel, password); + }, kpsul.account_manager._$input_trigramme); + break; + case 400: + displayErrors(getErrorsHtml(data)); + break; + } + kpsul.lock = 0; }); }