diff --git a/ajax/activate.php b/ajax/activate.php index 05f3390c5b964be137008789ddd700a2b76af0ad..c26bb1318d916d4559f61dd8309df96a3dae58eb 100644 --- a/ajax/activate.php +++ b/ajax/activate.php @@ -15,6 +15,7 @@ function ($discountId) { $Handler = new QUI\ERP\Discount\Handler(); $Discount = $Handler->getChild($discountId); + /* @var $Discount \QUI\ERP\Discount\Discount */ $Discount->setAttribute('active', 1); $Discount->update(); diff --git a/ajax/deactivate.php b/ajax/deactivate.php index 23c7c6507d36140eb840a600a4353401c6eb35ca..142c5538c1d71a5d8fc02e0d632bd9e4dd2ff481 100644 --- a/ajax/deactivate.php +++ b/ajax/deactivate.php @@ -15,6 +15,7 @@ function ($discountId) { $Handler = new QUI\ERP\Discount\Handler(); $Discount = $Handler->getChild($discountId); + /* @var $Discount \QUI\ERP\Discount\Discount */ $Discount->setAttribute('active', 0); $Discount->update(); diff --git a/ajax/get.php b/ajax/get.php index 9a337549f2a09d24ef9ccaa9f4c40c566964703c..fdb588e83d6ce02c2da27f6e6ff03eb8c3087bcd 100644 --- a/ajax/get.php +++ b/ajax/get.php @@ -5,7 +5,7 @@ */ /** - * Returns a discount + * Return a discount * * @param string $id - Discount-ID * @@ -14,10 +14,11 @@ QUI::$Ajax->registerFunction( 'package_quiqqer_discount_ajax_get', function ($id) { - $Discounts = new QUI\ERP\Discount\Handler(); - $Discount = $Discounts->getChild($id); + $Discounts = new QUI\ERP\Discount\Handler(); + $Discount = $Discounts->getChild($id); $attributes = $Discount->getAttributes(); + /* @var $Discount \QUI\ERP\Discount\Discount */ $attributes['title'] = $Discount->getTitle(); return $attributes; diff --git a/ajax/search.php b/ajax/search.php index 0e6f90986921a4b9199f8d3e6d097568d04424e9..c9027b9587df8e68861a6acd70d98997fc1b6c76 100644 --- a/ajax/search.php +++ b/ajax/search.php @@ -5,7 +5,7 @@ */ /** - * Returns discount list + * Search for discounts * * @param string $params - JSON query params * @@ -44,7 +44,7 @@ function ($fields, $params) { } $query['where_or'][$field] = array( - 'type' => '%LIKE%', + 'type' => '%LIKE%', 'value' => $value ); } diff --git a/ajax/toggle.php b/ajax/toggle.php index 680659a036d797e9a90e0f4c061449a9d2612b8c..ddfc0ebd7651e34b941cc2aa57b84ddde6f13b2e 100644 --- a/ajax/toggle.php +++ b/ajax/toggle.php @@ -15,7 +15,7 @@ function ($discountId) { $Handler = new QUI\ERP\Discount\Handler(); $Discount = $Handler->getChild($discountId); - /* @var $Tax \QUI\ERP\Tax\TaxEntry */ + /* @var $Discount \QUI\ERP\Discount\Discount */ if ($Discount->isActive()) { $Discount->setAttribute('active', 0); } else { diff --git a/ajax/update.php b/ajax/update.php index a4fae401f56b736b3e623c04265241db962a1391..d13deae70f4f49eccfc3f24479ed4b5cfb06fb4d 100644 --- a/ajax/update.php +++ b/ajax/update.php @@ -5,7 +5,7 @@ */ /** - * Returns discount list + * Update a discount * * @param string|int $discountId - Discount-ID * @param string $params - JSON Discount attributes diff --git a/bin/controls/Select.css b/bin/controls/Select.css deleted file mode 100644 index 3c2d727cfb20cfefef237404c0e8197f53cfb12a..0000000000000000000000000000000000000000 --- a/bin/controls/Select.css +++ /dev/null @@ -1,79 +0,0 @@ -@CHARSET "UTF-8"; - -.qui-discount-list { - float: left; - max-width: 400px; - padding: 2px; - position: relative; - width: 100%; -} - -.field-container > .qui-discount-list { - max-width: none; - padding: 0; -} - -.qui-discount-list-list { - position: relative; - z-index: 2; -} - -.qui-discount-list-list { - background: #fff; - border: 1px solid #dedede; - border-radius: 3px; - float: left; - height: 100px; - overflow: auto; - width: 100%; -} - -.qui-discount-list-search { - clear: both; - float: left; - width: calc(100% - 50px); -} - -.field-container-field > .qui-discount-list { - max-width: none; - padding: 0; -} - -.field-container-field > .qui-discount-list .qui-discount-list-list { - border-radius: 0; - border-width: 0 0 1px 0; -} - -.field-container-field > .qui-discount-list .qui-discount-list-search { - border: none; -} - -/** DropDown - ======================================================= */ - -.qui-discount-list-dropdown { - background: #fff; - border: 1px solid #dedede; - padding: 5px; - position: absolute; - width: 200px; - z-index: 10; -} - -.qui-discount-list-dropdown .mark { - color: red; - font-weight: bold; -} - -.qui-discount-list-dropdown-entry { - clear: both; - cursor: pointer; - float: left; - padding: 5px; - width: 100%; -} - -.qui-discount-list-dropdown-entry-hover { - background: #2F8FC6; - color: #FFFFFF; -} diff --git a/bin/controls/Select.js b/bin/controls/Select.js index 390a12ad860e6763dbcff4df36f1adc88335fb8d..633d33bc2c798d0ac4f52be3a99395e7d8b16e48 100644 --- a/bin/controls/Select.js +++ b/bin/controls/Select.js @@ -6,24 +6,19 @@ * * @require qui/controls/Control * @require qui/controls/buttons/Button + * @require qui/controls/elements/Select * @require package/quiqqer/discount/bin/controls/SelectItem * @require package/quiqqer/discount/bin/classes/Handler * @require Locale - * @require css!package/quiqqer/discount/bin/controls/Select.css - * - * @event onAddDiscount [ this, id ] */ define('package/quiqqer/discount/bin/controls/Select', [ - 'qui/controls/Control', - 'qui/controls/buttons/Button', + 'qui/controls/elements/Select', 'package/quiqqer/discount/bin/controls/SelectItem', 'package/quiqqer/discount/bin/classes/Handler', - 'Locale', - - 'css!package/quiqqer/discount/bin/controls/Select.css' + 'Locale' -], function (QUIControl, QUIButton, SelectItem, Handler, QUILocale) { +], function (QUIElementSelect, SelectItem, Handler, QUILocale) { "use strict"; var lg = 'quiqqer/discount'; @@ -39,526 +34,83 @@ define('package/quiqqer/discount/bin/controls/Select', [ */ return new Class({ - Extends: QUIControl, + Extends: QUIElementSelect, Type : 'package/quiqqer/discount/bin/controls/Select', Binds: [ - 'close', - 'fireSearch', - 'update', - - '$onDiscountDestroy', - '$onInputFocus', - '$onImport' + 'searchDiscounts' ], - options: { - max : false, // max entries - multible: true, // select more than one entry? - name : '', // string - styles : false, // object - label : false // text string or a <label> DOMNode Element - }, - - initialize: function (options, Input) { + initialize: function (options) { this.parent(options); - this.$Input = Input || null; - this.$Elm = null; - this.$List = null; - this.$Search = null; - this.$DropDown = null; + this.setAttribute('Search', this.searchDiscounts); + this.setAttribute('icon', 'fa fa-percent'); + this.setAttribute('child', 'package/quiqqer/discount/bin/controls/SelectItem'); - this.$SearchButton = null; - - this.$search = false; - this.$values = []; + this.setAttribute( + 'placeholder', + QUILocale.get(lg, 'control.select.search.placeholder') + ); this.addEvents({ - onImport: this.$onImport + onSearchButtonClick: this.$onSearchButtonClick }); }, - /** - * Return the DOMNode Element - * - * @method package/quiqqer/discount/bin/controls/Select#create - * @return {HTMLElement} The main DOM-Node Element - */ - create: function () { - - if (this.$Elm) { - return this.$Elm; - } - - var self = this; - - this.$Elm = new Element('div', { - 'class' : 'qui-discount-list', - 'data-quiid': this.getId() - }); - - if (!this.$Input) { - this.$Input = new Element('input', { - name: this.getAttribute('name') - }).inject(this.$Elm); - } else { - this.$Elm.wraps(this.$Input); - } - - if (this.getAttribute('styles')) { - this.$Elm.setStyles(this.getAttribute('styles')); - } - - this.$Input.set({ - styles: { - opacity : 0, - position: 'absolute', - zIndex : 1, - left : 5, - top : 5, - cursor : 'pointer' - }, - events: { - focus: this.$onInputFocus - } - }); - - - this.$List = new Element('div', { - 'class': 'qui-discount-list-list' - }).inject(this.$Elm); - - this.$Search = new Element('input', { - 'class' : 'qui-discount-list-search', - placeholder: QUILocale.get(lg, 'control.select.search.placeholder'), - events : { - keyup: function (event) { - if (event.key === 'down') { - self.down(); - return; - } - - if (event.key === 'up') { - self.up(); - return; - } - - if (event.key === 'enter') { - self.submit(); - return; - } - - self.fireSearch(); - }, - - blur : self.close, - focus: self.fireSearch - } - }).inject(this.$Elm); - - this.$SearchButton = new QUIButton({ - icon : 'fa fa-search', - styles: { - width: 50 - }, - events: { - onClick: function (Btn) { - Btn.setAttribute('icon', 'fa fa-spinner fa-spin'); - - require([ - 'package/quiqqer/discount/bin/controls/search/Window' - ], function (Window) { - - new Window({ - events: { - onSubmit: function (Win, values) { - for (var i = 0, len = values.length; i < len; i++) { - self.addDiscount(values[i].id); - } - - Win.close(); - } - } - }).open(); - - Btn.setAttribute('icon', 'fa fa-search'); - }); - } - } - }).inject(this.$Elm); - - this.$DropDown = new Element('div', { - 'class': 'qui-discount-list-dropdown', - styles : { - display: 'none', - top : this.$Search.getPosition().y + this.$Search.getSize().y, - left : this.$Search.getPosition().x - } - }).inject(document.body); - - if (this.getAttribute('label')) { - var Label = this.getAttribute('label'); - - if (typeof this.getAttribute('label').nodeName === 'undefined') { - Label = new Element('label', { - html: this.getAttribute('label') - }); - } - - Label.inject(this.$Elm, 'top'); - - if (Label.get('data-desc') && Label.get('data-desc') != ' ') { - new Element('div', { - 'class': 'description', - html : Label.get('data-desc'), - styles : { - marginBottom: 10 - } - }).inject(Label, 'after'); - } - } - - - // load values - if (this.$Input.value || this.$Input.value !== '') { - this.$Input.value.split(',').each(function (discountId) { - self.addDiscount(discountId); - }); - } - - return this.$Elm; - }, - - /** - * event: on inject - */ - $onImport: function () { - var Elm = this.getElm(); - - if (Elm.nodeName === 'INPUT') { - this.$Input = Elm; - } - - this.$Elm = null; - this.create(); - }, - - /** - * fire the search - * - * @method package/quiqqer/discount/bin/controls/Select#fireSearch - */ - fireSearch: function () { - if (this.$Search.value === '') { - return this.close(); - } - - this.cancelSearch(); - - this.$DropDown.set({ - html : '<span class="fa fa-spinner fa-spin"></span>', - styles: { - display: '', - top : this.$Search.getPosition().y + this.$Search.getSize().y, - left : this.$Search.getPosition().x - } - }); - - this.$search = this.search.delay(500, this); - }, - - /** - * cancel the search timeout - * - * @method package/quiqqer/discount/bin/controls/Select#cancelSearch - */ - cancelSearch: function () { - if (this.$search) { - clearTimeout(this.$search); - } - }, - - /** - * close the users search - * - * @method package/quiqqer/discount/bin/controls/Select#close - */ - close: function () { - this.cancelSearch(); - this.$DropDown.setStyle('display', 'none'); - this.$Search.value = ''; - }, - /** * trigger a users search and open a discount dropdown for selection * * @method package/quiqqer/discount/bin/controls/Select#search + * @return {Promise} */ - search: function () { - - var self = this, - value = this.$Search.value; + searchDiscounts: function () { + var value = this.$Search.value; - Discounts.search({ + return Discounts.search({ 'id' : value, 'discount': value }, { order: 'id ASC', limit: 5 }).then(function (result) { - - var i, id, len, nam, entry, Entry, - func_mousedown, func_mouseover, - - DropDown = self.$DropDown; - - - DropDown.set('html', ''); - - if (!result || !result.length) { - new Element('div', { - html : QUILocale.get(lg, 'control.select.no.results'), - styles: { - 'float': 'left', - 'clear': 'both', - padding: 5, - margin : 5 - } - }).inject(DropDown); - - return; - } - - // events - func_mousedown = function (event) { - var Elm = event.target; - - if (!Elm.hasClass('qui-discount-list-dropdown-entry')) { - Elm = Elm.getParent('.qui-discount-list-dropdown-entry'); - } - - self.addDiscount(Elm.get('data-id')); - }; - - func_mouseover = function () { - this.getParent().getElements( - '.qui-discount-list-dropdown-entry-hover' - ).removeClass( - 'qui-discount-list-dropdown-entry-hover' - ); - - this.addClass('qui-discount-list-dropdown-entry-hover'); - }; - - // create - for (i = 0, len = result.length; i < len; i++) { - - entry = result[i]; - id = entry.id; - - nam = '#' + id + ' - '; - nam = nam + QUILocale.get(lg, 'discount.' + id + '.title'); - - if (value) { - nam = nam.toString().replace( - new RegExp('(' + value + ')', 'gi'), - '<span class="mark">$1</span>' - ); - } - - Entry = new Element('div', { - html : '<span class="fa fa-percent"></span>' + - '<span>' + nam + ' (' + id + ')</span>', - 'class' : 'box-sizing qui-discount-list-dropdown-entry', - 'data-id': id, - events : { - mousedown : func_mousedown, - mouseenter: func_mouseover - } - }).inject(DropDown); - } + return result.map(function (Entry) { + return { + id : Entry.id, + title: Entry.text + }; + }); }); }, /** - * Add a user to the input - * - * @method package/quiqqer/discount/bin/controls/Select#addUser - * @param {Number|String} id - id of the user - * @return {Object} this (package/quiqqer/discount/bin/controls/Select) - */ - addDiscount: function (id) { - if (!id || id === '') { - return this; - } - - new SelectItem({ - id : id, - events: { - onDestroy: this.$onDiscountDestroy - } - }).inject(this.$List); - - this.$values.push(id); - - this.fireEvent('addDiscount', [this, id]); - this.$refreshValues(); - - return this; - }, - - /** - * keyup - users dropdown selection one step up - * - * @method package/quiqqer/discount/bin/controls/Select#up - * @return {Object} this (package/quiqqer/discount/bin/controls/Select) - */ - up: function () { - if (!this.$DropDown || !this.$DropDown.getFirst()) { - return this; - } - - var Active = this.$DropDown.getElement( - '.qui-discount-list-dropdown-entry-hover' - ); - - // Last Element - if (!Active) { - this.$DropDown.getLast().addClass( - 'qui-discount-list-dropdown-entry-hover' - ); - - return this; - } - - Active.removeClass( - 'qui-discount-list-dropdown-entry-hover' - ); - - if (!Active.getPrevious()) { - this.up(); - return this; - } - - Active.getPrevious().addClass( - 'qui-discount-list-dropdown-entry-hover' - ); - }, - - /** - * keydown - users dropdown selection one step down - * - * @method package/quiqqer/discount/bin/controls/Select#down - * @return {Object} this (package/quiqqer/discount/bin/controls/Select) - */ - down: function () { - if (!this.$DropDown || !this.$DropDown.getFirst()) { - return this; - } - - var Active = this.$DropDown.getElement( - '.qui-discount-list-dropdown-entry-hover' - ); - - // First Element - if (!Active) { - this.$DropDown.getFirst().addClass( - 'qui-discount-list-dropdown-entry-hover' - ); - - return this; - } - - Active.removeClass( - 'qui-discount-list-dropdown-entry-hover' - ); - - if (!Active.getNext()) { - this.down(); - return this; - } - - Active.getNext().addClass( - 'qui-discount-list-dropdown-entry-hover' - ); - - return this; - }, - - /** - * select the selected user / group - * - * @method package/quiqqer/discount/bin/controls/Select#submit - */ - submit: function () { - if (!this.$DropDown) { - return; - } - - var Active = this.$DropDown.getElement( - '.qui-discount-list-dropdown-entry-hover' - ); - - if (Active) { - this.addDiscount(Active.get('data-id')); - } - - this.$Input.value = ''; - this.search(); - }, - - /** - * Set the focus to the input field * - * @method package/quiqqer/discount/bin/controls/Select#focus - * @return {Object} this (package/quiqqer/discount/bin/controls/Select) + * @param {Object} Btn */ - focus: function () { - if (this.$Search) { - this.$Search.focus(); - } - - return this; - }, - - /** - * Write the ids to the real input field - * - * @method package/quiqqer/discount/bin/controls/Select#$refreshValues - */ - $refreshValues: function () { - this.$Input.value = this.$values.join(','); - this.$Input.fireEvent('change', [{ - target: this.$Input - }]); - }, - - /** - * event : if a user or a groupd would be destroyed - * - * @method package/quiqqer/discount/bin/controls/Select#$onDiscountDestroy - * @param {Object} Item - package/quiqqer/discount/bin/controls/DiscountDisplay - */ - $onDiscountDestroy: function (Item) { - this.$values = this.$values.erase( - Item.getAttribute('id') - ); - - this.$refreshValues(); - }, - - /** - * event : on input focus, if the real input field get the focus - * - * @param {DOMEvent} event - */ - $onInputFocus: function (event) { - if (typeof event !== 'undefined') { - event.stop(); - } + $onSearchButtonClick: function (Btn) { + Btn.setAttribute('icon', 'fa fa-spinner fa-spin'); + + require([ + 'package/quiqqer/discount/bin/controls/search/Window' + ], function (Window) { + new Window({ + autoclose: true, + multiple : this.getAttribute('multiple'), + events : { + onSubmit: function (Win, data) { + data = data.map(function (Entry) { + return parseInt(Entry.id); + }); + + for (var i = 0, len = data.length; i < len; i++) { + this.addItem(data[i]); + } + }.bind(this) + } + }).open(); - this.focus(); + Btn.setAttribute('icon', 'fa fa-search'); + }.bind(this)); } }); }); diff --git a/bin/controls/SelectItem.css b/bin/controls/SelectItem.css deleted file mode 100644 index 00bf74675813a26fb1174a637d336b33161e156f..0000000000000000000000000000000000000000 --- a/bin/controls/SelectItem.css +++ /dev/null @@ -1,49 +0,0 @@ -.quiqqer-discount-display { - border-bottom: 1px solid rgba(0, 0, 0, 0.1); - clear: both; - cursor: default; - float: left; - font-size: 14px; - line-height: 20px; - padding: 5px; - width: 100%; -} - -.quiqqer-discount-display:hover { - background: rgba(0, 0, 0, 0.1); -} - -.quiqqer-discount-display-icon { - float: left; - line-height: 20px; - text-align: center; - width: 30px; -} - -.quiqqer-discount-display-text { - float: left; - line-height: 20px; - overflow: hidden; - padding: 0 10px 0 0; - text-overflow: ellipsis; - white-space: nowrap; - width: calc(100% - 50px); -} - -.quiqqer-discount-display-destroy { - cursor: pointer; - float: left; - line-height: 20px; - text-align: center; - visibility: hidden; - width: 20px; -} - -.quiqqer-discount-display:hover .quiqqer-discount-display-destroy { - visibility: visible; -} - -.quiqqer-discount-display-destroy:hover { - background: #2F8FC6; - color: #FFFFFF; -} diff --git a/bin/controls/SelectItem.js b/bin/controls/SelectItem.js index d6d39b9098e404d5bc2d80df6a4735c3a23a4914..d6b9d0261e9e273e16c5f68b070968b546342d74 100644 --- a/bin/controls/SelectItem.js +++ b/bin/controls/SelectItem.js @@ -2,90 +2,48 @@ * Discount entry for a discount select * * @module package/quiqqer/discount/bin/controls/SelectItem + * @author www.pcsg.de (Henning Leutz) * * @require qui/controls/Control * @require package/quiqqer/discount/bin/classes/Handler * @require Locale - * @require css!package/quiqqer/discount/bin/controls/SelectItem.css */ define('package/quiqqer/discount/bin/controls/SelectItem', [ - 'qui/controls/Control', + 'qui/QUI', + 'qui/controls/elements/SelectItem', 'package/quiqqer/discount/bin/classes/Handler', - 'Locale', + 'Locale' - 'css!package/quiqqer/discount/bin/controls/SelectItem.css' - -], function (QUIControl, Handler, QUILocale) { +], function (QUI, QUISelectItem, Handler, QUILocale) { "use strict"; var Discounts = new Handler(); return new Class({ - Extends: QUIControl, + Extends: QUISelectItem, Type : 'package/quiqqer/discount/bin/controls/SelectItem', Binds: [ - '$onInject' + 'refresh' ], - options: { - id: false - }, - initialize: function (options) { this.parent(options); - - this.$Icon = null; - this.$Text = null; - this.$Destroy = null; - - this.addEvents({ - onInject: this.$onInject - }); - }, - - /** - * Return the DOMNode Element - * - * @returns {HTMLElement} - */ - create: function () { - var self = this, - Elm = this.parent(); - - Elm.set({ - 'class': 'quiqqer-discount-display smooth', - html : '<span class="quiqqer-discount-display-icon fa fa-percent"></span>' + - '<span class="quiqqer-discount-display-text"> </span>' + - '<span class="quiqqer-discount-display-destroy fa fa-remove"></span>' - }); - - this.$Icon = Elm.getElement('.quiqqer-discount-display-icon'); - this.$Text = Elm.getElement('.quiqqer-discount-display-text'); - this.$Destroy = Elm.getElement('.quiqqer-discount-display-destroy'); - - this.$Destroy.addEvent('click', function () { - self.destroy(); - }); - - return Elm; + this.setAttribute('icon', 'fa fa-percent'); }, /** * event : on inject */ - $onInject: function () { + refresh: function () { var self = this; this.$Text.set({ html: '<span class="fa fa-spinner fa-spin"></span>' }); - Discounts.getChild( - this.getAttribute('id') - ).then(function (data) { - + Discounts.getChild(this.getAttribute('id')).then(function (data) { var locale = QUILocale.get( 'quiqqer/discount', 'discount.' + data.id + '.title'