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

währungen editieren, löschen, blätterfunktion

Übergeordneter 1124b159
Keine zugehörigen Branchen gefunden
Keine zugehörigen Tags gefunden
Keine zugehörigen Merge Requests gefunden
<?php
/**
* This file contains package_quiqqer_currency_ajax_delete
*/
/**
* Delete a currency
*
* @return array
*/
QUI::$Ajax->registerFunction(
'package_quiqqer_currency_ajax_delete',
function ($currency) {
QUI\ERP\Currency\Handler::deleteCurrency($currency);
},
array('currency'),
'Permission::checkAdminUser'
);
......@@ -16,13 +16,7 @@
/* @var $Currency \QUI\ERP\Currency\Currency */
foreach ($allowed as $Currency) {
$result[] = array(
'text' => $Currency->getText(),
'sign' => $Currency->getSign(),
'code' => $Currency->getCode(),
'rate' => $Currency->getExchangeRate(),
'autoupdate' => $Currency->autoupdate(),
);
$result[] = $Currency->toArray();
}
return $result;
......
<?php
/**
* This file contains package_quiqqer_currency_ajax_getCurrency
*/
/**
* Return the currency
*
* @return array
*/
QUI::$Ajax->registerFunction(
'package_quiqqer_currency_ajax_getCurrency',
function ($currency) {
$Currency = QUI\ERP\Currency\Handler::getCurrency($currency);
return $Currency->toArray();
},
array('currency')
);
<?php
/**
* This file contains package_quiqqer_currency_ajax_update
*/
/**
* Saves a currency
*
* @return array
*/
QUI::$Ajax->registerFunction(
'package_quiqqer_currency_ajax_update',
function ($currency, $code, $rate) {
$Currency = QUI\ERP\Currency\Handler::getCurrency($currency);
$Currency->setExchangeRate($rate);
$Currency->setCode($code);
$Currency->save();
},
array('currency', 'code', 'rate'),
'Permission::checkAdminUser'
);
......@@ -18,13 +18,15 @@ define('package/quiqqer/currency/bin/settings/AllowedCurrencies', [
'qui/QUI',
'qui/controls/Control',
'qui/controls/buttons/Switch',
'qui/controls/windows/Confirm',
'Ajax',
'Locale',
'controls/grid/Grid',
'package/quiqqer/currency/bin/settings/CurrencyWindow',
'css!package/quiqqer/currency/bin/settings/AllowedCurrencies.css'
], function (QUI, QUIControl, QUISwitch, QUIAjax, QUILocale, Grid) {
], function (QUI, QUIControl, QUISwitch, QUIConfirm, QUIAjax, QUILocale, Grid, CurrencyWindow) {
"use strict";
var lg = 'quiqqer/currency';
......@@ -35,6 +37,7 @@ define('package/quiqqer/currency/bin/settings/AllowedCurrencies', [
Extends: QUIControl,
Binds: [
'refresh',
'$onImport',
'$onCurrencyStatusChange',
'$switchCurrencyStatus',
......@@ -84,7 +87,8 @@ define('package/quiqqer/currency/bin/settings/AllowedCurrencies', [
html : '<div class="quiqqer-currency-allowed-container"></div>'
}).wraps(this.$Input);
var Settings = this.$Elm.getParent('.qui-xml-panel-row-item');
var self = this,
Settings = this.$Elm.getParent('.qui-xml-panel-row-item');
if (Settings) {
Settings.setStyles({
......@@ -140,58 +144,115 @@ define('package/quiqqer/currency/bin/settings/AllowedCurrencies', [
name : 'edit',
text : 'Währung editieren',
textimage: 'fa fa-edit',
disabled : true
disabled : true,
events : {
onClick: function () {
self.openEditDialog(self.$Grid.getSelectedData()[0].code);
}
}
}, {
type: 'seperator'
}, {
name : 'delete',
text : 'Währung löschen',
textimage: 'fa fa-trash',
disabled : true
disabled : true,
events : {
onClick: function () {
self.openDeleteDialog(self.$Grid.getSelectedData()[0].code);
}
}
}]
});
this.$Grid.setWidth(width);
this.$Grid.addEvents({
click : function () {
onClick: function () {
var selected = self.$Grid.getSelectedIndices(),
buttons = self.$Grid.getButtons();
},
refresh: function () {
this.getCurrencies().then(function (list) {
var data = [],
values = this.getAttribute('values');
for (var i in list) {
if (!list.hasOwnProperty(i)) {
continue;
}
list[i].allowed = new QUISwitch({
status: (typeof values[i] !== 'undefined')
});
var Edit = buttons.filter(function (Btn) {
return Btn.getAttribute('name') == 'edit';
})[0];
list[i].autoupdate = new QUISwitch({
status : list[i].autoupdate,
currency: list[i].code,
events : {
onChange: this.$changeAutoUpdate
}
});
var Delete = buttons.filter(function (Btn) {
return Btn.getAttribute('name') == 'delete';
})[0];
data.push(list[i]);
}
if (selected.length) {
Edit.enable();
Delete.enable();
}
},
this.$Grid.setData({
data: data
});
}.bind(this));
}.bind(this)
onDblClick: function () {
self.openEditDialog(self.$Grid.getSelectedData()[0].code);
},
onRefresh: this.refresh
});
this.$Grid.refresh();
},
/**
* refresh the currency list
*/
refresh: function () {
return this.getCurrencies().then(function (list) {
var data = [],
values = this.getAttribute('values');
for (var i in list) {
if (!list.hasOwnProperty(i)) {
continue;
}
list[i].allowed = new QUISwitch({
status: (typeof values[i] !== 'undefined')
});
list[i].autoupdate = new QUISwitch({
status : list[i].autoupdate,
currency: list[i].code,
events : {
onChange: this.$changeAutoUpdate
}
});
data.push(list[i]);
}
var perPage = this.$Grid.options.perPage,
page = this.$Grid.options.page,
start = (page - 1) * perPage,
total = data.length;
data = data.splice(start, perPage);
this.$Grid.setData({
data : data,
total: total,
page : page
});
var buttons = this.$Grid.getButtons();
var Edit = buttons.filter(function (Btn) {
return Btn.getAttribute('name') == 'edit';
})[0];
var Delete = buttons.filter(function (Btn) {
return Btn.getAttribute('name') == 'delete';
})[0];
Edit.disable();
Delete.disable();
}.bind(this));
},
/**
* update values to the input field
*/
......@@ -227,6 +288,22 @@ define('package/quiqqer/currency/bin/settings/AllowedCurrencies', [
});
},
/**
* Delete a currency
*
* @param {String} currency
* @returns {Promise}
*/
deleteCurrency: function (currency) {
return new Promise(function (resolve, reject) {
QUIAjax.post('package_quiqqer_currency_ajax_delete', resolve, {
'package': 'quiqqer/currency',
currency : currency,
onError : reject
});
});
},
/**
* event : on currency status change
* @param Switch
......@@ -286,6 +363,61 @@ define('package/quiqqer/currency/bin/settings/AllowedCurrencies', [
onError : reject
});
});
},
/**
* dialogs
*/
/**
* Opens the edit dialog
*
* @param {String} currency
*/
openEditDialog: function (currency) {
new CurrencyWindow({
currency: currency
}).open();
},
/**
* Opens the delete dialog
*
* @param {String} currency
*/
openDeleteDialog: function (currency) {
var self = this;
new QUIConfirm({
icon : 'fa fa-trash',
texticon : 'fa fa-trash',
title : QUILocale.get(lg, 'window.delete.title'),
text : QUILocale.get(lg, 'window.delete.text', {
currency: currency
}),
information: QUILocale.get(lg, 'window.delete.information', {
currency: currency
}),
maxHeight : 400,
maxWidth : 600,
autoclose : false,
events : {
onSubmit: function (Win) {
Win.Loader.show();
self.deleteCurrency(currency).then(function () {
self.refresh().then(function () {
self.update();
Win.Loader.hide();
Win.close();
});
}, function () {
Win.Loader.hide();
});
}
}
}).open();
}
});
});
.quiqqer-currency-setting .field-container {
margin-bottom: 10px;
}
.quiqqer-currency-setting .field-container-item {
width: 200px;
}
\ No newline at end of file
<form>
<label class="field-container">
<span class="field-container-item">
{{currencyTitle}}
</span>
<div class="field-container-field currency-title"></div>
</label>
<label class="field-container">
<span class="field-container-item" title="{{currencyCodeDescription}}">
{{currencyCode}}
</span>
<input class="field-container-field" name="code"/>
</label>
<label class="field-container">
<span class="field-container-item">
{{currencySign}}
</span>
<div class="field-container-field currency-sign"></div>
</label>
<label class="field-container">
<span class="field-container-item">
{{currencyExchangeRate}}
</span>
<input class="field-container-field" name="rate" type="number"/>
</label>
</form>
\ No newline at end of file
/**
* @module package/quiqqer/currency/bin/settings/Currency
* @author www.pcsg.de (Henning Leutz)
*
* @require qui/QUI
* @require qui/controls/Control
*/
define('package/quiqqer/currency/bin/settings/Currency', [
'qui/QUI',
'qui/controls/Control',
'Locale',
'Ajax',
'Mustache',
'package/quiqqer/translator/bin/controls/Update',
'text!package/quiqqer/currency/bin/settings/Currency.html',
'css!package/quiqqer/currency/bin/settings/Currency.css'
], function (QUI, QUIControl, QUILocale, QUIAjax, Mustache, Translation, template) {
"use strict";
var lg = 'quiqqer/currency';
return new Class({
Extends: QUIControl,
Type : 'package/quiqqer/currency/bin/settings/Currency',
Binds: [
'$onInject'
],
options: {
currency: false
},
initialize: function (options) {
this.parent(options);
this.$Form = null;
this.$Code = null;
this.$Rate = null;
this.$TranslationTitle = null;
this.$TranslationSign = null;
this.addEvents({
onInject: this.$onInject
});
},
/**
* Return the DOMNode
*
* @returns {HTMLDivElement}
*/
create: function () {
this.$Elm = new Element('div', {
'class': 'quiqqer-currency-setting',
html : Mustache.render(template, {
currencyTitle : QUILocale.get('quiqqer/system', 'title'),
currencyCode : QUILocale.get(lg, 'control.currency.code'),
currencySign : QUILocale.get(lg, 'control.currency.sign'),
currencyExchangeRate : QUILocale.get(lg, 'control.currency.rate'),
currencyCodeDescription: QUILocale.get(lg, 'control.currency.code.decription')
})
});
this.$Form = this.$Elm.getElement('form');
this.$Code = this.$Form.elements.code;
this.$Rate = this.$Form.elements.rate;
return this.$Elm;
},
/**
* event: on inject
*/
$onInject: function () {
var self = this;
var TitleContainer = this.getElm().getElement('.currency-title'),
SignContainer = this.getElm().getElement('.currency-sign'),
currency = this.getAttribute('currency');
this.$TranslationTitle = new Translation({
'group': 'quiqqer/currency',
'var' : 'currency.' + currency + '.text'
}).inject(TitleContainer);
this.$TranslationSign = new Translation({
'group': 'quiqqer/currency',
'var' : 'currency.' + currency + '.sign'
}).inject(SignContainer);
QUIAjax.get('package_quiqqer_currency_ajax_getCurrency', function (data) {
self.$Code.value = data.code;
self.$Rate.value = data.rate;
}, {
'package': 'quiqqer/currency',
currency : this.getAttribute('currency')
});
},
/**
* alias for update()
*/
save: function () {
return this.update();
},
/**
* Updates the currency
*
* @return {Promise}
*/
update: function () {
return new Promise(function (resolve) {
Promise.all([
this.$TranslationTitle.save(),
this.$TranslationSign.save()
]).then(function () {
QUIAjax.post('package_quiqqer_currency_ajax_update', resolve, {
'package': 'quiqqer/currency',
currency : this.getAttribute('currency'),
code : this.$Code.value,
rate : this.$Rate.value
});
}.bind(this));
}.bind(this));
}
});
});
/**
* @module package/quiqqer/currency/bin/settings/CurrencyWindow
* @author www.pcsg.de (Henning Leutz)
*
* @require qui/QUI
* @require qui/controls/Control
* @require package/quiqqer/currency/bin/settings/Currency
*/
define('package/quiqqer/currency/bin/settings/CurrencyWindow', [
'qui/QUI',
'qui/controls/windows/Confirm',
'Locale',
'package/quiqqer/currency/bin/settings/Currency'
], function (QUI, QUIConfirm, QUILocale, Currency) {
"use strict";
return new Class({
Extends: QUIConfirm,
Type : 'package/quiqqer/currency/bin/settings/CurrencyWindow',
Binds: [
'$onOpen',
'$onSubmit'
],
options: {
currency : false,
icon : 'fa fa-money',
title : 'Währung bearbeiten',
texticon : false,
autoclose: false,
maxHeight: 400,
maxWidth : 600
},
initialize: function (options) {
this.setAttribute(
'title',
QUILocale.get('quiqqer/currency', 'control.currency.title', {
currency: options.currency
})
);
this.parent(options);
this.$Currency = null;
this.addEvents({
onOpen : this.$onOpen,
onSubmit: this.$onSubmit
});
},
/**
* event : on open
*/
$onOpen: function () {
this.$Currency = new Currency({
currency: this.getAttribute('currency')
}).inject(this.getContent());
},
/**
* event : on submit
*/
$onSubmit: function () {
this.Loader.show();
this.$Currency.save().then(function () {
this.Loader.hide();
this.close();
}.bind(this));
}
});
});
......@@ -7,6 +7,48 @@
</locale>
</groups>
<groups name="quiqqer/currency" datatype="js">
<locale name="control.currency.title">
<de><![CDATA[Währungs-Einstellungen: [currency]]]></de>
<en><![CDATA[Currency settings [currency]]]></en>
</locale>
<locale name="control.currency.code">
<de><![CDATA[Währungscode]]></de>
<en><![CDATA[Currency code]]></en>
</locale>
<locale name="control.currency.code.decription">
<de><![CDATA[zB: EUR, USD oder BTC]]></de>
<en><![CDATA[eq.: EUR, USD oder BTC]]></en>
</locale>
<locale name="control.currency.sign">
<de><![CDATA[Währungsszeichen]]></de>
<en><![CDATA[Currency code]]></en>
</locale>
<locale name="control.currency.rate">
<de><![CDATA[Umrechnungskurs]]></de>
<en><![CDATA[Exchange rate]]></en>
</locale>
<locale name="window.delete.title">
<de><![CDATA[Währung löschen]]></de>
<en><![CDATA[Delete currency]]></en>
</locale>
<locale name="window.delete.text">
<de><![CDATA[Möchten Sie die Währung [currency] wirklich löschen?]]></de>
<en><![CDATA[Do you really want to delete the currency [currency]?]]></en>
</locale>
<locale name="window.delete.information">
<de><![CDATA[
Die Währung wird unwiderruflich gelöscht.
Ein Wiederherstellen ist nur mit dem neu Anlegen der Währung möglich.
]]></de>
<en><![CDATA[
The currency is permanently deleted.
The restoring of the currency is only possible with the new creation of it.
]]></en>
</locale>
</groups>
<groups name="quiqqer/currency" datatype="php,js">
<locale name="window.erp.title">
<de><![CDATA[Shop]]></de>
......
......@@ -109,6 +109,22 @@ public function getSign()
);
}
/**
* Return the currency data
*
* @return array
*/
public function toArray()
{
return array(
'text' => $this->getText(),
'sign' => $this->getSign(),
'code' => $this->getCode(),
'rate' => $this->getExchangeRate(),
'autoupdate' => $this->autoupdate()
);
}
/**
* Format an amount
*
......@@ -228,6 +244,17 @@ public function setExchangeRate($rate)
$this->exchangeRate = (float)$rate;
}
/**
* @param string $code
* @throws QUI\Exception
*/
public function setCode($code)
{
QUI\Rights\Permission::checkPermission('currency.edit');
$this->code = $code;
}
/**
* Set the autoupdate status
*
......
......@@ -40,15 +40,31 @@ public static function table()
}
/**
* @param string $currency - currency code
* @throws QUI\Exception
*/
public static function createCurrency($currencyCode, $rate)
public static function createCurrency($currency, $rate)
{
QUI\Rights\Permission::checkPermission('currency.create');
}
/**
* Delete a currency
*
* @param string $currency - currency code
* @throws QUI\Exception
*/
public static function deleteCurrency($currency)
{
QUI\Rights\Permission::checkPermission('currency.delete');
QUI::getDataBase()->delete(self::table(), array(
'currency' => $currency
));
}
/**
* Return the default currency
*
......
0% Lade oder .
You are about to add 0 people to the discussion. Proceed with caution.
Bearbeitung dieser Nachricht zuerst beenden!
Bitte registrieren oder zum Kommentieren