Skip to content
Code-Schnipsel Gruppen Projekte
Commit f114754c erstellt von Henning Leutz's avatar Henning Leutz :martial_arts_uniform:
Dateien durchsuchen

refactor: Discounts select bassierend auf package/quiqqer/discount/bin/controls/Select

Übergeordneter 828e1bad
No related branches found
No related tags found
Keine zugehörigen Merge Requests gefunden
......@@ -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();
......
......@@ -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();
......
......@@ -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;
......
......@@ -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
);
}
......
......@@ -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 {
......
......@@ -5,7 +5,7 @@
*/
/**
* Returns discount list
* Update a discount
*
* @param string|int $discountId - Discount-ID
* @param string $params - JSON Discount attributes
......
@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;
}
......@@ -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') != '&nbsp;') {
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));
}
});
});
.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;
}
......@@ -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">&nbsp;</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'
......
0% oder .
You are about to add 0 people to the discussion. Proceed with caution.
Bearbeitung dieser Nachricht zuerst beenden!
Bitte registrieren oder zum Kommentieren