From a13ae8e9c13a0b9b4d7ee2c972fec50532dad432 Mon Sep 17 00:00:00 2001 From: Gabriela Rivero Date: Sat, 26 Jan 2019 12:47:24 -0300 Subject: [PATCH] [IMP] pos_access_right: lint improvements --- .../static/src/js/pos_access_right.js | 171 +++++++++--------- 1 file changed, 88 insertions(+), 83 deletions(-) diff --git a/pos_access_right/static/src/js/pos_access_right.js b/pos_access_right/static/src/js/pos_access_right.js index 57e3ac5c..e2d202db 100644 --- a/pos_access_right/static/src/js/pos_access_right.js +++ b/pos_access_right/static/src/js/pos_access_right.js @@ -16,39 +16,40 @@ odoo.define('pos_access_right.pos_access_right', function (require) { var core = require('web.core'); var _t = core._t; -/* ******************************************************** -point_of_sale.gui -******************************************************** */ + /* ******************************************************** + Point_of_sale.gui + ******************************************************** */ // New function 'display_access_right' to display disabled functions - gui.Gui.prototype.display_access_right = function(user){ + gui.Gui.prototype.display_access_right = function (user) { var records = new Model('res.users') - .query(['groups_id']) - .filter([['id', '=', user['id']]]) - .all() + .query(['groups_id']) + .filter([['id', '=', user.id]]) + .all(); var groups_id = []; var group_negative_qty_id = this.pos.config.group_negative_qty_id[0]; var group_discount_id = this.pos.config.group_discount_id[0]; - var group_change_unit_price_id = this.pos.config.group_change_unit_price_id[0]; - records.then(function(result){ - groups_id = result[0]['groups_id']; - if (groups_id.indexOf(group_negative_qty_id) != -1){ - $('.numpad-minus').removeClass('pos-disabled-mode'); - } - else{ + var group_price_id = this.pos.config.group_change_unit_price_id[0]; + records.then (function(result) { + groups_id = result[0].groups_id; + if (groups_id.indexOf(group_negative_qty_id) === -1) { $('.numpad-minus').addClass('pos-disabled-mode'); + } else { + $('.numpad-minus').removeClass('pos-disabled-mode'); } - if (groups_id.indexOf(group_discount_id) != -1){ - $(".mode-button[data-mode='discount']").removeClass('pos-disabled-mode'); - } - else{ - $(".mode-button[data-mode='discount']").addClass('pos-disabled-mode'); - } - if (groups_id.indexOf(group_change_unit_price_id) != -1){ - $(".mode-button[data-mode='price']").removeClass('pos-disabled-mode'); + if (groups_id.indexOf(group_discount_id) === -1) { + $(".mode-button[data-mode='discount']"). + addClass('pos-disabled-mode'); + } else { + $(".mode-button[data-mode='discount']"). + removeClass('pos-disabled-mode'); } - else{ - $(".mode-button[data-mode='price']").addClass('pos-disabled-mode'); + if (groups_id.indexOf(group_price_id) === -1) { + $(".mode-button[data-mode='price']"). + addClass('pos-disabled-mode'); + } else { + $(".mode-button[data-mode='price']"). + removeClass('pos-disabled-mode'); } } ); @@ -56,9 +57,9 @@ point_of_sale.gui }; -/* ******************************************************** -point_of_sale.models -******************************************************** */ + /* ******************************************************** + Point_of_sale.models + ******************************************************** */ // load extra data from 'pos_config' (ids of new groups) models.load_fields("pos.config", "group_negative_qty_id"); @@ -70,29 +71,29 @@ point_of_sale.models // Overload 'set_cashier' function to display correctly // unauthorized function after cashier changed var _set_cashier_ = models.PosModel.prototype.set_cashier; - models.PosModel.prototype.set_cashier = function(user){ + models.PosModel.prototype.set_cashier = function (user) { this.gui.display_access_right(user); _set_cashier_.call(this, user); }; -/* ******************************************************** -chrome.OrderSelectorWidget -******************************************************** */ + /* ******************************************************** + Chrome.OrderSelectorWidget + ******************************************************** */ chrome.OrderSelectorWidget.include({ - neworder_click_handler: function(event, $el) { - var user = this.pos.get_cashier() + neworder_click_handler: function (event, $el) { + var user = this.pos.get_cashier(); var records = new Model('res.users') - .query(['groups_id']) - .filter([['id', '=', user['id']]]) - .all() + .query(['groups_id']) + .filter([['id', '=', user.id]]) + .all(); var groups_id = []; var group_multi_order_id = this.pos.config.group_multi_order_id[0]; var gui = this.gui; - records.then(function(result){ - groups_id = result[0]['groups_id']; - if (groups_id.indexOf(group_multi_order_id) == -1) { - gui.show_popup('error',{ + records.then (function(result) { + groups_id = result[0].groups_id; + if (groups_id.indexOf(group_multi_order_id) === -1) { + gui.show_popup('error', { 'title': _t('Many Orders - Unauthorized function'), 'body': _t('Please ask your manager to do it.'), }); @@ -101,19 +102,19 @@ chrome.OrderSelectorWidget ); return this._super(); }, - deleteorder_click_handler: function(event, $el) { - var user = this.pos.get_cashier() + deleteorder_click_handler: function (event, $el) { + var user = this.pos.get_cashier(); var records = new Model('res.users') - .query(['groups_id']) - .filter([['id', '=', user['id']]]) - .all() + .query(['groups_id']) + .filter([['id', '=', user.id]]) + .all(); var groups_id = []; - var group_delete_order_id = this.pos.config.group_delete_order_id[0]; + var group_del_order_id = this.pos.config.group_delete_order_id[0]; var gui = this.gui; - records.then(function(result){ - groups_id = result[0]['groups_id']; - if (groups_id.indexOf(group_delete_order_id) == -1) { - gui.show_popup('error',{ + records.then (function(result) { + groups_id = result[0].groups_id; + if (groups_id.indexOf(group_del_order_id) === -1) { + gui.show_popup('error', { 'title': _t('Delete Order - Unauthorized function'), 'body': _t('Please ask your manager to do it.'), }); @@ -125,33 +126,34 @@ chrome.OrderSelectorWidget }); -/* ******************************************************** -screens.NumpadWidget -******************************************************** */ + /* ******************************************************** + Screens.NumpadWidget + ******************************************************** */ screens.NumpadWidget.include({ // Overload 'start' function to display correctly unauthorized function // at the beginning of the session, based on current user - start: function() { + start: function () { this._super(); this.gui.display_access_right(this.pos.get_cashier()); }, - // block '+/-' button if user doesn't belong to the correct group - clickSwitchSign: function() { - var user = this.pos.get_cashier() + // Block '+/-' button if user doesn't belong to the correct group + clickSwitchSign: function () { + var user = this.pos.get_cashier(); var records = new Model('res.users') - .query(['groups_id']) - .filter([['id', '=', user['id']]]) - .all() + .query(['groups_id']) + .filter([['id', '=', user.id]]) + .all(); var groups_id = []; - var group_negative_qty_id = this.pos.config.group_negative_qty_id[0]; + var group_neg_qty_id = this.pos.config.group_negative_qty_id[0]; var gui = this.gui; - records.then(function(result){ - groups_id = result[0]['groups_id']; - if (groups_id.indexOf(group_negative_qty_id) == -1) { - gui.show_popup('error',{ - 'title': _t('Negative Quantity - Unauthorized function'), + records.then (function(result) { + groups_id = result[0].groups_id; + if (groups_id.indexOf(group_neg_qty_id) === -1) { + gui.show_popup('error', { + 'title': + _t('Negative Quantity - \Unauthorized function'), 'body': _t('Please ask your manager to do it.'), }); } @@ -160,30 +162,33 @@ screens.NumpadWidget return this._super(); }, - // block 'discount' or 'price' button if user doesn't belong to the correct group - clickChangeMode: function(event) { - var user = this.pos.get_cashier() + // Block 'discount' or 'price' button if user doesn't belong to the + //correct group + clickChangeMode: function (event) { + var user = this.pos.get_cashier(); var records = new Model('res.users') - .query(['groups_id']) - .filter([['id', '=', user['id']]]) - .all() + .query(['groups_id']) + .filter([['id', '=', user.id]]) + .all(); var groups_id = []; var group_discount_id = this.pos.config.group_discount_id[0]; - var group_change_unit_price_id = this.pos.config.group_change_unit_price_id[0]; + var group_price_id = this.pos.config.group_change_unit_price_id[0]; var gui = this.gui; - records.then(function(result){ - groups_id = result[0]['groups_id']; - if (event.currentTarget.attributes['data-mode'].nodeValue == 'discount' && - groups_id.indexOf(group_discount_id) == -1) { - gui.show_popup('error',{ + records.then (function(result) { + groups_id = result[0].groups_id; + if (event.currentTarget.attributes['data-mode'].nodeValue === + 'discount' && + groups_id.indexOf(group_discount_id) === -1) { + gui.show_popup('error', { 'title': _t('Discount - Unauthorized function'), 'body': _t('Please ask your manager to do it.'), }); - } - else if (event.currentTarget.attributes['data-mode'].nodeValue == 'price' && - groups_id.indexOf(group_change_unit_price_id) == -1) { - gui.show_popup('error',{ - 'title': _t('Change Unit Price - Unauthorized function'), + } else if (event.currentTarget.attributes['data-mode'].nodeValue + === 'price' && + groups_id.indexOf(group_price_id) === -1) { + gui.show_popup('error', { + 'title': + _t('Change Unit Price - Unauthorized function'), 'body': _t('Please ask your manager to do it.'), }); }