keep eslint quiet

This commit is contained in:
Aurélien Delobelle 2017-05-16 12:27:39 +02:00
parent 311e0c48bd
commit bc71e1628a
3 changed files with 234 additions and 148 deletions

View file

@ -5,12 +5,53 @@ class KHistory {
static get default_options() {
return {
'templates': {
'purchase': '<div class="ope"><span class="amount"></span><span class="infos1"></span><span class="infos2"></span><span class="addcost"></span><span class="canceled"></span></div>',
'specialope': '<div class="ope"><span class="amount"></span><span class="infos1"></span><span class="infos2"></span><span class="addcost"></span><span class="canceled"></span></div>',
'opegroup': '<div class="opegroup"><span class="time"></span><span class="trigramme"></span><span class="amount"></span><span class="valid_by"></span><span class="comment"></span></div>',
'transfergroup': '<div class="opegroup"><span class="time"></span><span class="infos"></span><span class="valid_by"></span><span class="comment"></span></div>',
'day': '<div class="day"><span class="date"></span></div>',
'transfer': '<div class="ope"><span class="amount"></span><span class="infos1"></span><span class="glyphicon glyphicon-arrow-right"></span><span class="infos2"></span><span class="canceled"></span></div>',
'purchase': `
<div class="ope">
<span class="amount"></span>
<span class="infos1"></span>
<span class="infos2"></span>
<span class="addcost"></span>
<span class="canceled"></span>
</div>
`,
'specialope': `
<div class="ope">
<span class="amount"></span>
<span class="infos1"></span>
<span class="infos2"></span>
<span class="addcost"></span>
<span class="canceled"></span>
</div>
`,
'opegroup': `
<div class="opegroup">
<span class="time"></span>
<span class="trigramme"></span>
<span class="amount"></span>
<span class="valid_by"></span>
<span class="comment"></span>
</div>`,
'transfergroup': `
<div class="opegroup">
<span class="time"></span>
<span class="infos"></span>
<span class="valid_by"></span>
<span class="comment"></span>
</div>
`,
'day': `
<div class="day">
<span class="date"></span>
</div>
`,
'transfer': `
<div class="ope">
<span class="amount"></span>
<span class="infos1"></span>
<span class="glyphicon glyphicon-arrow-right"></span>
<span class="infos2"></span>
<span class="canceled"></span>
</div>`,
},
'api_options': {
@ -35,10 +76,16 @@ class KHistory {
if (!all_options.static)
OperationWebSocket.add_handler(data => this.update_data(data));
var templates = all_options.templates
var templates = all_options.templates;
if (all_options.no_trigramme)
templates['opegroup'] =
'<div class="opegroup"><span class="time"></span><span class="amount"></span><span class="valid_by"></span><span class="comment"></span></div>';
templates['opegroup'] = `
<div class="opegroup">
<span class="time"></span>
<span class="amount"></span>
<span class="valid_by"></span>
<span class="comment"></span>
</div>
`;
this.display = new ForestDisplay(this._$container, templates, this.data);
@ -76,18 +123,18 @@ class KHistory {
}
cancel_operations(to_cancel) {
var that = this ;
var that = this;
var on_success = function() {
if (that.selection)
that.selection.reset() ;
that.selection.reset();
$(that).trigger("cancel_done");
}
};
api_with_auth({
url: Urls['kfet.kpsul.cancel_operations'](),
data: to_cancel,
on_success: on_success,
})
});
}
add_node(data) {
@ -96,7 +143,7 @@ class KHistory {
}
update_node(modelname, id, update_data) {
var updated = this.data.update(modelname, id, update_data)
var updated = this.data.update(modelname, id, update_data);
if (!updated)
return false;
@ -138,7 +185,7 @@ class KHistory {
for (let ope of opes) {
if (ope['cancellation']) {
var update_data = {
let update_data = {
'canceled_at': ope.canceled_at,
'canceled_by': ope.canceled_by,
};
@ -153,7 +200,7 @@ class KHistory {
for (let opegroup of opegroups) {
if (opegroup['cancellation']) {
var update_data = { 'amount': opegroup.amount };
let update_data = { 'amount': opegroup.amount };
this.update_node('opegroup', opegroup.id, update_data);
}

View file

@ -68,7 +68,7 @@ class ModelObject {
* @param {Object} [data={}] - data to store in instance
*/
constructor(data) {
this.from(data || {});
this.from(data || {});
}
/**
@ -210,7 +210,7 @@ class APIModelObject extends ModelObject {
* @param {object} [api_options] Additional data appended to the request.
*/
fromAPI(api_options) {
api_options = api_options || {};
api_options = api_options || {};
api_options['format'] = 'json';
@ -263,8 +263,10 @@ class Account extends APIModelObject {
* @see {@link Models.ModelObject.props|ModelObject.props}
*/
static get props() {
return ['id', 'trigramme', 'name', 'nickname', 'email', 'is_cof',
'promo', 'balance', 'is_frozen', 'departement'];
return [
'id', 'trigramme', 'name', 'nickname', 'email', 'is_cof',
'promo', 'balance', 'is_frozen', 'departement'
];
}
/**
@ -280,7 +282,7 @@ class Account extends APIModelObject {
'is_cof' : false, 'promo': '', 'balance': 0, 'is_frozen': false,
'departement': '',
};
};
}
/**
* @default <tt>django-js-reverse('kfet.account')</tt>
@ -292,7 +294,7 @@ class Account extends APIModelObject {
var url = Urls['kfet.account.create']();
if (trigramme) {
var trigramme_url = encodeURIComponent(trigramme);
url += `?trigramme=${trigramme_url}`
url += `?trigramme=${trigramme_url}`;
}
return url;
}
@ -494,7 +496,7 @@ class ArticleCategory extends ModelObject {
* @see {@link Models.ModelObject.compare|ModelObject.compare}
*/
static compare(a, b) {
return a.name.localeCompare(b.name) ;
return a.name.localeCompare(b.name);
}
}
@ -565,7 +567,7 @@ class Day extends ModelObject {
* @default <tt>['id', 'date']</tt>
* @see {@link Models.ModelObject.props|ModelObject.props}
*/
static get props() { return ['id', 'at', 'opegroups'] }
static get props() { return ['id', 'at', 'opegroups']; }
/**
* Default values for Day model instances
@ -631,8 +633,10 @@ class HistoryGroup extends ModelObject {
* @see {@link Models.ModelObject.default_data|ModelObject.default_data}
*/
static get default_data() {
return {'id': 0, 'at': moment(), 'comment': '',
'valid_by': '', 'day': new Day()};
return {
'id': 0, 'at': moment(), 'comment': '',
'valid_by': '', 'day': new Day()
};
}
/**
@ -675,9 +679,9 @@ class OperationGroup extends HistoryGroup {
* @see {@link Models.ModelObject.default_data|ModelObject.default_data}
*/
static get default_data() {
return $.extend({}, HistoryGroup.default_data,
{'amount': 0, 'is_cof': false, 'trigramme': '',
'opes': []});
return $.extend({}, HistoryGroup.default_data, {
'amount': 0, 'is_cof': false, 'trigramme': '', 'opes': []
});
}
/**
@ -712,8 +716,7 @@ class TransferGroup extends HistoryGroup {
* @see {@link Models.ModelObject.default_data|ModelObject.default_data}
*/
static get default_data() {
return $.extend({}, HistoryGroup.default_data,
{'transfers': []});
return $.extend({}, HistoryGroup.default_data, {'transfers': []});
}
/**
@ -753,8 +756,10 @@ class Operation extends ModelObject {
* @see {@link Models.ModelObject.default_data|ModelObject.default_data}
*/
static get default_data() {
return {'id': '', 'amount': 0, 'canceled_at': undefined, 'canceled_by': '',
'group': new HistoryGroup()};
return {
'id': '', 'amount': 0, 'canceled_at': undefined, 'canceled_by': '',
'group': new HistoryGroup()
};
}
get amount() { return this._amount; }
@ -960,7 +965,7 @@ class ModelForest {
* @param {number} direction
*/
get_or_create(modelname, data, direction) {
var struct = this.constructor.structure ;
var struct = this.constructor.structure;
var struct_data = struct[modelname];
var model = struct_data.model;
@ -985,7 +990,7 @@ class ModelForest {
var parent_modelname, parent_data;
// If index, we create it
if (struct_data.index) {
var new_parent = {}
var new_parent = {};
for (let key of struct_data.index.fields) {
new_parent[key] = data[key];
}
@ -1002,13 +1007,13 @@ class ModelForest {
parent_modelname = related.modelname;
} else {
parent_data = data.parent.content ;
parent_modelname = data.parent.modelname ;
parent_data = data.parent.content;
parent_modelname = data.parent.modelname;
}
var parent = this.get_or_create(parent_modelname, parent_data, -1);
var parent_childname = struct[parent_modelname].children;
node[parent_name] = parent ;
node[parent_name] = parent;
parent[parent_childname].push(node);
}
@ -1024,7 +1029,7 @@ class ModelForest {
}
}
return node ;
return node;
}
/**
@ -1034,7 +1039,7 @@ class ModelForest {
from(data) {
this.roots = [];
if (data.objects) {
this.related = data.related
this.related = data.related;
for (let modelname in data.objects) {
for (let obj_data of data.objects[modelname])
this.get_or_create(modelname, obj_data, 0);
@ -1077,7 +1082,7 @@ class ModelForest {
for (let root of this.roots)
if (recurse(root))
return ;
return;
}
/**
@ -1090,7 +1095,7 @@ class ModelForest {
function callback(node) {
if (node.id == id) {
result = node ;
result = node;
return true;
}
}
@ -1101,13 +1106,13 @@ class ModelForest {
}
update(modelname, id, update_data) {
var updated = null ;
var updated = null;
function callback(node) {
if (node.id == id) {
node.update(update_data);
updated = node ;
return true ;
updated = node;
return true;
}
}
@ -1268,7 +1273,7 @@ class OperationList extends APIModelForest {
class ForestDisplay {
constructor($container, templates, data) {
this._templates = templates ;
this._templates = templates;
this._$container = $container;
this.data = data || new ModelForest();
}
@ -1286,7 +1291,7 @@ class ForestDisplay {
var struct_data = this.data.constructor.structure[modelname];
var template = this._templates[modelname];
var options = options || {} ;
options = options || {};
var $container = $('<div></div>');
$container.attr('id', modelname+'-'+node.id);
@ -1322,7 +1327,7 @@ class ForestDisplay {
*/
add(node, options) {
var struct = this.data.constructor.structure;
var existing = this.data.get_parent(node) ;
var existing = this.data.get_parent(node);
var first_missing = node;
while (existing && !(this._$container.find('#'+existing.modelname+'-'+existing.id))) {
@ -1345,7 +1350,7 @@ class ForestDisplay {
* @param {Object} [options] Options for element render method
*/
render(options) {
var forest = this.data ;
var forest = this.data;
if (forest.is_empty())
return;
@ -1367,7 +1372,7 @@ class ForestDisplay {
* @param {Object} data
*/
update(data) {
var modelname = data.constructor.verbose_name ;
var modelname = data.constructor.verbose_name;
var $new_elt = data.display($(this._templates[modelname]), {});
var $to_replace = this._$container.find('#'+modelname+'-'+data.id+'>:first-child');
@ -1449,8 +1454,8 @@ class Formatter {
* attributes names for container (default: <tt>''</tt>).
*/
static render(object, $container, options) {
options.props = options.props || [];
options.attrs = options.attrs || [];
options.props = options.props || [];
options.attrs = options.attrs || [];
var props = options.override_props ? options.props : this.props.concat(options.props);
var attrs = options.override_attrs ? options.attrs : this.attrs.concat(options.attrs);
@ -1805,14 +1810,14 @@ class OperationFormatter extends Formatter {
cancel += ' par '+a.canceled_by;
cancel += ' le '+a.canceled_at.format('DD/MM/YY à HH:mm:ss');
return cancel ;
return cancel;
} else {
return '';
}
}
static attr_canceled(a) {
return a.canceled_at ? 'true' : 'false' ;
return a.canceled_at ? 'true' : 'false';
}
}
@ -1861,7 +1866,7 @@ class SpecialOpeFormatter extends OperationFormatter {
}
static prop_infos2(a) {
return SpecialOperation.verbose_types[a.type] || '' ;
return SpecialOperation.verbose_types[a.type] || '';
}
}

View file

@ -30,6 +30,8 @@ class KPsulManager {
this.article_manager.reset_data();
this.history.fetch();
}
return this;
}
focus() {
@ -44,11 +46,7 @@ class KPsulManager {
}
_init_events() {
var that = this ;
$(this.history).on("cancel_done", function(e) {
that.reset(true);
that.focus();
});
$(this.history).on("cancel_done", () => this.reset(true).focus());
}
}
@ -66,10 +64,22 @@ class AccountManager {
// buttons: search, read or create
this._$buttons_container = this._$container.find('.buttons');
this._buttons_templates = {
create: template`<a href="${'url'}" class="btn btn-primary" target="_blank" title="Créer ce compte"><span class="glyphicon glyphicon-plus"></span></a>`,
read: template`<a href="${'url'}" class="btn btn-primary" target="_blank" title="Détails du compte"><span class="glyphicon glyphicon-info-sign"></span></a>`,
search: template`<button class="btn btn-primary search" title="Rechercher"><span class="glyphicon glyphicon-search"></span></button>`,
}
create: template`
<a href="${'url'}" class="btn btn-primary" target="_blank" title="Créer ce compte">
<span class="glyphicon glyphicon-plus"></span>
</a>
`,
read: template`
<a href="${'url'}" class="btn btn-primary" target="_blank" title="Détails du compte">
<span class="glyphicon glyphicon-info-sign"></span>
</a>
`,
search: template`
<button class="btn btn-primary search" title="Rechercher">
<span class="glyphicon glyphicon-search"></span>
</button>
`,
};
}
@ -92,13 +102,13 @@ class AccountManager {
if (this.is_empty()) {
var trigramme = this.selection.get();
if (trigramme.isValidTri()) {
var url = Account.url_create(trigramme);
let url = Account.url_create(trigramme);
buttons = this._buttons_templates['create']({url: url});
} else { /* trigramme input is empty or invalid */
buttons = this._buttons_templates['search']();
}
} else { /* an account is loaded */
var url = this.account.url_read;
let url = this.account.url_read;
buttons = this._buttons_templates['read']({url: url});
}
@ -198,7 +208,10 @@ class AccountSearch {
constructor(manager) {
this.manager = manager;
this._content = '<input type="text" name="q" id="search_autocomplete" autocomplete="off" spellcheck="false" autofocus><div id="account_results"></div>' ;
this._content = `
<input type="text" name="q" id="search_autocomplete" autocomplete="off" spellcheck="false" autofocus>
<div id="account_results"></div>
`;
this._input = '#search_autocomplete';
this._results_container = '#account_results';
@ -252,14 +265,15 @@ class AccountSearch {
.on('keydown', function(e) {
if (e.which == 70 && e.ctrlKey) {
that.open();
e.preventDefault() ;
e.preventDefault();
}
});
}
_init_inner_events() {
this._$input.bind('selectChoice',
(e, choice, autocomplete) => this._on_select(e, choice, autocomplete));
(e, choice, autocomplete) => this._on_select(e, choice, autocomplete)
);
return this;
}
@ -291,9 +305,17 @@ class CheckoutManager {
this._$buttons_container = this._$container.find('.buttons');
this._buttons_templates = {
read: template`<a class="btn btn-primary" href="${'url'}" title="En savoir plus" target="_blank"><span class="glyphicon glyphicon-info-sign"></span></a>`,
statement_create: template`<a href="${'url'}" title="Effectuer un relevé" class="btn btn-primary" target="_blank"><span class="glyphicon glyphicon-euro"></span></a>`,
}
read: template`
<a class="btn btn-primary" href="${'url'}" title="En savoir plus" target="_blank">
<span class="glyphicon glyphicon-info-sign"></span>
</a>
`,
statement_create: template`
<a href="${'url'}" title="Effectuer un relevé" class="btn btn-primary" target="_blank">
<span class="glyphicon glyphicon-euro"></span>
</a>
`,
};
}
update(id) {
@ -391,7 +413,9 @@ class CheckoutSelection {
this._init_events();
this.choices = this._$input.find('option[value!=""]').toArray()
this.choices =
this._$input.find('option[value!=""]')
.toArray()
.map(function(opt) {
return parseInt($(opt).attr('value'));
});
@ -429,13 +453,23 @@ class ArticleManager {
this._$nb = $('#article_number');
this._$stock = $('#article_stock');
this.selected = new Article() ;
this.data = new ArticleList() ;
this.selected = new Article();
this.data = new ArticleList();
var $container = $('#articles_data');
var templates = {
'category': '<div class="category"><span class="name"></span></div>',
'article' : '<div class="article"><span class="name"></span><span class="price"></span><span class="stock"></span></div>'
} ;
category: `
<div class="category">
<span class="name"></span>
</div>
`,
article: `
<div class="article">
<span class="name"></span>
<span class="price"></span>
<span class="stock"></span>
</div>
`,
};
this.display = new ForestDisplay($container, templates, this.data);
this.autocomplete = new ArticleAutocomplete(this, $container);
@ -444,7 +478,7 @@ class ArticleManager {
}
get nb() {
return this._$nb.val() ;
return this._$nb.val();
}
display_list() {
@ -452,7 +486,7 @@ class ArticleManager {
}
validate(article) {
this.selected.from(article) ;
this.selected.from(article);
this._$input.val(article.name);
this._$nb.val('1');
this._$stock.text('/'+article.stock);
@ -485,11 +519,11 @@ class ArticleManager {
}
reset() {
this.unset() ;
this.unset();
this._$stock.text('');
this._$nb.val('');
this._$input.val('');
this.autocomplete.showAll() ;
this.autocomplete.showAll();
}
_init_events() {
@ -523,7 +557,7 @@ class ArticleManager {
if (normalKeys.test(e.keyCode) || arrowKeys.test(e.keyCode) || e.ctrlKey) {
if (e.ctrlKey && e.charCode == 65)
that._$nb.val('');
return true ;
return true;
}
if (that.constructor.check_nb(that.nb+e.key))
@ -536,7 +570,7 @@ class ArticleManager {
//Note : this function may not be needed after the whole rework
get_article(id) {
return this.data.find('article', id) ;
return this.data.find('article', id);
}
focus() {
@ -549,7 +583,7 @@ class ArticleManager {
}
static check_nb(nb) {
return /^[0-9]+$/.test(nb) && nb > 0 && nb <= 24 ;
return /^[0-9]+$/.test(nb) && nb > 0 && nb <= 24;
}
}
@ -557,15 +591,15 @@ class ArticleAutocomplete {
constructor(article_manager, $container) {
this.manager = article_manager;
this._$container = $container ;
this._$container = $container;
this._$input = $('#article_autocomplete');
this.showAll() ;
this.showAll();
this._init_events();
}
_init_events() {
var that = this ;
var that = this;
// 8:Backspace|9:Tab|13:Enter|46:DEL|112-117:F1-6|119-123:F8-F12
var normalKeys = /^(8|9|13|46|112|113|114|115|116|117|119|120|121|122|123)$/;
@ -573,17 +607,17 @@ class ArticleAutocomplete {
this._$input
.on('keydown', function(e) {
var text = that._$input.val() ;
var text = that._$input.val();
if (normalKeys.test(e.keyCode) || arrowKeys.test(e.keyCode) || e.ctrlKey) {
// For the backspace key, we suppose the cursor is at the very end
if(e.keyCode == 8) {
that.update(text.substring(0, text.length-1), true);
}
return true ;
return true;
}
that.update(text+e.key, false);
return false ;
return false;
});
@ -592,9 +626,9 @@ class ArticleAutocomplete {
update(prefix, backspace) {
this.resetMatch();
var article_list = this.manager.data ;
var lower = prefix.toLowerCase() ;
var that = this ;
var article_list = this.manager.data;
var lower = prefix.toLowerCase();
var that = this;
article_list.traverse('article', function(article) {
if (article.name.toLowerCase().startsWith(lower))
@ -603,15 +637,15 @@ class ArticleAutocomplete {
if (this.matching.length == 1) {
if (!backspace) {
this.manager.validate(this.matching[0]) ;
this.showAll() ;
this.manager.validate(this.matching[0]);
this.showAll();
} else {
this.manager.unset();
this.updateDisplay();
}
} else if (this.matching.length > 1) {
this.manager.unset();
this.updateDisplay() ;
this.updateDisplay();
if (!backspace)
this.updatePrefix();
}
@ -641,15 +675,15 @@ class ArticleAutocomplete {
updatePrefix() {
var lower = this.matching.map(function (article) {
return article.name.toLowerCase() ;
return article.name.toLowerCase();
});
lower.sort() ;
lower.sort();
var first = lower[0], last = lower[lower.length-1],
length = first.length, i = 0;
while (i < length && first.charAt(i) === last.charAt(i)) i++;
this._$input.val(first.substring(0,i)) ;
this._$input.val(first.substring(0,i));
}
showAll() {