Newer
Older

Dominik Chrzanowski
committed
/**
* @module package/quiqqer/menu/bin/Controls/NavTabsVertical
* @author Dominik Chrzanowski
*
*/
define('package/quiqqer/menu/bin/Controls/NavTabsVerticalSettings', [
'qui/QUI',
'qui/controls/Control',
'qui/controls/windows/Confirm',
'qui/controls/buttons/Button',
'qui/controls/buttons/Switch',
'Locale',
'Mustache',
'controls/grid/Grid',
'utils/Controls',
'text!package/quiqqer/menu/bin/Controls/NavTabsVerticalSettings.html',
'css!package/quiqqer/menu/bin/Controls/NavTabsVerticalSettings.css'
], function (
QUI,
QUIControl,
QUIConfirm,
QUIButton,
QUISwitch,
QUILocale,
Mustache,
Grid,
ControlsUtils,
templateEntry

Dominik Chrzanowski
committed
) {
"use strict";
var lg = 'quiqqer/menu';
return new Class({
Extends: QUIControl,
Type : 'package/quiqqer/menu/bin/Controls/NavTabsVerticalSettings',

Dominik Chrzanowski
committed
Binds: [
'$onImport',
'$openAddDialog',
'$openDeleteDialog',
'$openEditDialog',
'$toggleSlideStatus',
'update'
],
initialize: function (options) {
this.parent(options);
this.$Input = null;

Dominik Chrzanowski
committed
this.$data = [];
this.addEvents({
onImport: this.$onImport
});
},
/**
* event: on import
*/
$onImport: function () {
this.$Input = this.getElm();
this.$Elm = new Element('div', {
'class': 'quiqqer-menu-navTabsVertival-settings',
styles : {
clear : 'both',
'float' : 'left',
height : 400,

Dominik Chrzanowski
committed
overflow: 'hidden',
position: 'relative',

Dominik Chrzanowski
committed
}
}).wraps(this.$Input);
// grid and sizes
var size = this.$Elm.getSize();
var Desktop = new Element('div', {
styles: {
width: size.x
}
}).inject(this.$Elm);
this.$Grid = new Grid(Desktop, {
height : 400,
width : size.x,
buttons : [

Dominik Chrzanowski
committed
{

Dominik Chrzanowski
committed
disabled: true,

Dominik Chrzanowski
committed
onClick: function () {
this.$Grid.moveup();
this.$refreshSorting();
}.bind(this)
}
}, {

Dominik Chrzanowski
committed
disabled: true,

Dominik Chrzanowski
committed
onClick: function () {
this.$Grid.movedown();
this.$refreshSorting();
}.bind(this)
}
}, {
type: 'separator'
}, {

Dominik Chrzanowski
committed
textimage: 'fa fa-plus',
text : QUILocale.get('quiqqer/quiqqer', 'add'),
events : {

Dominik Chrzanowski
committed
onClick: this.$openAddDialog
}
}, {
type: 'separator'
}, {

Dominik Chrzanowski
committed
textimage: 'fa fa-edit',
text : QUILocale.get('quiqqer/quiqqer', 'edit'),
disabled : true,
events : {

Dominik Chrzanowski
committed
onClick: this.$openEditDialog
}
}, {

Dominik Chrzanowski
committed
textimage: 'fa fa-trash',
text : QUILocale.get('quiqqer/quiqqer', 'delete'),
disabled : true,
events : {

Dominik Chrzanowski
committed
onClick: this.$openDeleteDialog
}
}
],
columnModel: [
{
header : QUILocale.get(lg, 'control.navTabsVertical.entries.isDisable'),

Dominik Chrzanowski
committed
dataIndex: 'isDisabledDisplay',

Dominik Chrzanowski
committed
}, {
dataIndex: 'isDisabled',

Dominik Chrzanowski
committed
}, {
header : QUILocale.get(lg, 'control.navTabsVertical.entries.entryTitleIcon'),

Dominik Chrzanowski
committed
dataIndex: 'titleIconPreview',

Dominik Chrzanowski
committed
},
{
header : QUILocale.get(lg, 'control.navTabsVertical.entries.entryTitle'),

Dominik Chrzanowski
committed
dataIndex: 'entryTitle',

Dominik Chrzanowski
committed
},
{
header : QUILocale.get(lg, 'control.navTabsVertical.entries.entryImage'),

Dominik Chrzanowski
committed
dataIndex: 'entryImagePreview',

Dominik Chrzanowski
committed
},
{
header : QUILocale.get(lg, 'control.navTabsVertical.entries.entryContent'),

Dominik Chrzanowski
committed
dataIndex: 'entryContent',

Dominik Chrzanowski
committed
},
{
dataIndex: 'newTab',

Dominik Chrzanowski
committed
}, {
dataIndex: 'image',

Dominik Chrzanowski
committed
}
]
});
this.$Grid.addEvents({
onClick: function () {
var buttons = this.$Grid.getButtons(),

Dominik Chrzanowski
committed
return Btn.getAttribute('name') === 'edit';
})[0],

Dominik Chrzanowski
committed
return Btn.getAttribute('name') === 'up';
})[0],

Dominik Chrzanowski
committed
return Btn.getAttribute('name') === 'down';
})[0],

Dominik Chrzanowski
committed
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
return Btn.getAttribute('name') === 'delete';
})[0];
Up.enable();
Down.enable();
Edit.enable();
Delete.enable();
}.bind(this),
onDblClick: this.$openEditDialog
});
this.$Grid.getElm().setStyles({
position: 'absolute'
});
try {
this.$data = JSON.decode(this.$Input.value);
if (typeOf(this.$data) !== 'array') {
this.$data = [];
}
this.refresh();
} catch (e) {
}
},
/**
* Toggles the slide's status between enabled and disabled
*
* @param {Object} [Caller] - the object calling this event
*/
$toggleSlideStatus: function (Caller) {
if (!Caller) {
return;
}
// get cell number
var row = Caller.getElm().getParent('li').get('data-row');
this.$data[row].isDisabled = Caller.getStatus();
this.update();
},
/**
* Resize the control
*
* @return {Promise}
*/
resize: function () {
var size = this.getElm().getSize();
return this.$Grid.setWidth(size.x).then(function () {
this.$Grid.resize();
}.bind(this));
},
/**
* refresh the display
*/
refresh: function () {
var i, len, entry, insert;
var data = [];
for (i = 0, len = this.$data.length; i < len; i++) {

Dominik Chrzanowski
committed
insert = {
titleIcon : '',
entryImage : '',
titleIconPreview : new Element('span', {html: ' '}),

Dominik Chrzanowski
committed
entryImagePreview: new Element('span', {html: ' '})
};
entry.isDisabled = parseInt(entry.isDisabled);
insert.isDisabledDisplay = new QUISwitch({
status: entry.isDisabled,

Dominik Chrzanowski
committed
events: {
onChange: this.$toggleSlideStatus
}
});
if ("titleIcon" in entry && entry.titleIcon !== '') {
insert.titleIcon = entry.titleIcon;
if (entry.titleIcon.includes('fa ')) {
insert.titleIconPreview = new Element('span', {
'class': insert.titleIcon
});
} else {
insert.titleIconPreview = new Element('img', {
src : URL_DIR + insert.titleIcon + '&maxwidth=50&maxheight=50',
width : 50,
height: 50
});
}

Dominik Chrzanowski
committed
}
if ("entryTitle" in entry) {
insert.entryTitle = entry.entryTitle;
}
if ("entryImage" in entry && entry.entryImage !== '') {
insert.entryImage = entry.entryImage;
insert.entryImagePreview = new Element('img', {
src : URL_DIR + insert.entryImage + '&maxwidth=50&maxheight=50',
width : 50,
height: 50

Dominik Chrzanowski
committed
});
}
if ("entryContent" in entry) {
insert.entryContent = entry.entryContent;
}
data.push(insert);
}
this.$Grid.setData({
data: data
});
var buttons = this.$Grid.getButtons(),

Dominik Chrzanowski
committed
return Btn.getAttribute('name') === 'edit';
})[0],

Dominik Chrzanowski
committed
return Btn.getAttribute('name') === 'up';
})[0],

Dominik Chrzanowski
committed
return Btn.getAttribute('name') === 'down';
})[0],

Dominik Chrzanowski
committed
return Btn.getAttribute('name') === 'delete';
})[0];
Up.disable();
Down.disable();
Edit.disable();
Delete.disable();
},
/**
* Update the field
*/
update: function () {
this.$Input.value = JSON.encode(this.$data);
},
/**
* Add an entry
*
* @param {Object} params
*/
add: function (params) {
var entry = {
titleIcon : '',
entryTitle : '',
entryImage : '',

Dominik Chrzanowski
committed
entryContent: '',

Dominik Chrzanowski
committed
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
};
if ("isDisabled" in params) {
entry.isDisabled = parseInt(params.isDisabled);
}
if ("titleIcon" in params && params.titleIcon !== '') {
entry.titleIcon = params.titleIcon;
}
if ("entryTitle" in params) {
entry.entryTitle = params.entryTitle;
}
if ("entryImage" in params) {
entry.entryImage = params.entryImage;
}
if ("entryContent" in params) {
entry.entryContent = params.entryContent;
}
this.$data.push(entry);
this.refresh();
this.update();
},
/**
* Edit an entry
*
* @param {number} index
* @param {object} params
*/
edit: function (index, params) {
if (typeof index === 'undefined') {
return;
}
var entry = {
titleIcon : '',
entryTitle : '',
entryImage : '',

Dominik Chrzanowski
committed
entryContent: '',

Dominik Chrzanowski
committed
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
};
if ("isDisabled" in params) {
entry.isDisabled = parseInt(params.isDisabled);
}
if ("titleIcon" in params) {
entry.titleIcon = params.titleIcon;
}
if ("entryTitle" in params) {
entry.entryTitle = params.entryTitle;
}
if ("entryImage" in params) {
entry.entryImage = params.entryImage;
}
if ("entryContent" in params) {
entry.entryContent = params.entryContent;
}
this.$data[index] = entry;
this.refresh();
this.update();
},
/**
* Delete one entry or multiple entries
*
* @param {number|array} index
*/
del: function (index) {
var newList = [];
if (typeOf(index) !== 'array') {
index = [index];
}
for (var i = 0, len = this.$data.length; i < len; i++) {
if (!index.contains(i)) {
newList.push(this.$data[i]);
}
}
this.$data = newList;
},
/**
* Set the used project
*
* @param {string|object} Project
*/
setProject: function (Project) {
this.setAttribute('project', Project);
var controls = QUI.Controls.getControlsInElement(this.getElm());
controls.each(function (Control) {
if (Control === this) {
return;
}
if ("setProject" in Control) {
Control.setProject(Project);
}
}.bind(this));
},
/**
* Refresh the data sorting in dependence of the grid
*/
$refreshSorting: function () {
var gridData = this.$Grid.getData(),

Dominik Chrzanowski
committed
for (var i = 0, len = gridData.length; i < len; i++) {
data.push({
isDisabled : parseInt(gridData[i].isDisabled),
titleIcon : gridData[i].titleIcon,
entryTitle : gridData[i].entryTitle,
entryImage : gridData[i].entryImage,

Dominik Chrzanowski
committed
entryContent: gridData[i].entryContent
});
}
this.$data = data;
this.update();
},
/**
* Dialogs
*/
/**
* opens the delete dialog
*
* @return {Promise}
*/
$openDeleteDialog: function () {
new QUIConfirm({
icon : 'fa fa-icon',
text : QUILocale.get(lg, 'control.navTabsVertical.entries.delete.title'),

Dominik Chrzanowski
committed
information: QUILocale.get(lg, 'control.navTabsVertical.entries.delete.information'),
texticon : false,
maxWidth : 600,
maxHeight : 400,
ok_button : {
text : QUILocale.get('quiqqer/quiqqer', 'delete'),

Dominik Chrzanowski
committed
textimage: 'fa fa-trash'
},

Dominik Chrzanowski
committed
onSubmit: function () {
var selected = this.$Grid.getSelectedIndices();
this.$Grid.deleteRows(selected);
this.del(selected);
this.update();
}.bind(this)
}
}).open();
},
/**
* Open edit dialog
*
* @retrun {Promise}
*/
$openEditDialog: function () {
var self = this,
data = this.$Grid.getSelectedData(),

Dominik Chrzanowski
committed
index = this.$Grid.getSelectedIndices();
if (!data.length) {
return Promise.resolve();
}

Dominik Chrzanowski
committed
index = index[0];
return this.$createDialog().then(function (Dialog) {
Dialog.addEvent('onSubmit', function () {
Dialog.Loader.show();
var Content = Dialog.getContent();

Dominik Chrzanowski
committed
var Image = Form.elements.titleIcon;
var entryTitle = Form.elements.entryTitle;
var entryImage = Form.elements.entryImage;

Dominik Chrzanowski
committed
var entryContent = Form.elements.entryContent;
self.edit(index, {
titleIcon : Image.value,
entryTitle : entryTitle.value,
entryImage : entryImage.value,

Dominik Chrzanowski
committed
entryContent: entryContent.value,
isDisabled : Dialog.IsDisabledSwitch.getStatus()

Dominik Chrzanowski
committed
});
Dialog.close();
});
Dialog.addEvent('onOpenAfterCreate', function () {
var Content = Dialog.getContent();

Dominik Chrzanowski
committed
var Image = Form.elements.titleIcon;
var entryTitle = Form.elements.entryTitle;
var entryImage = Form.elements.entryImage;

Dominik Chrzanowski
committed
var entryContent = Form.elements.entryContent;
if (data.isDisabled) {
Dialog.IsDisabledSwitch.on();
} else {
Dialog.IsDisabledSwitch.off();
}
Image.value = data.titleIcon;
entryTitle.value = data.entryTitle;
entryImage.value = data.entryImage;

Dominik Chrzanowski
committed
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
entryContent.value = data.entryContent;
if (data.newTab && data.newTab.getAttribute('data-enabled') === "1") {
Dialog.NewTabSwitch.on();
} else {
Dialog.NewTabSwitch.off();
}
Image.fireEvent('change');
entryTitle.fireEvent('change');
entryImage.fireEvent('change');
entryContent.fireEvent('change');
});
Dialog.setAttribute('title', QUILocale.get(lg, 'control.navTabsVertical.entries.edit.title'));
Dialog.open();
});
},
/**
* opens the add dialog
*
* @return {Promise}
*/
$openAddDialog: function () {
var self = this;
return this.$createDialog().then(function (Dialog) {
Dialog.addEvent('onSubmit', function () {
Dialog.Loader.show();
var Content = Dialog.getContent();

Dominik Chrzanowski
committed
var Image = Form.elements.titleIcon;
var entryTitle = Form.elements.entryTitle;
var entryImage = Form.elements.entryImage;

Dominik Chrzanowski
committed
var entryContent = Form.elements.entryContent;
self.add({
titleIcon : Image.value,
entryTitle : entryTitle.value,
entryImage : entryImage.value,

Dominik Chrzanowski
committed
entryContent: entryContent.value,
isDisabled : Dialog.IsDisabledSwitch.getStatus()

Dominik Chrzanowski
committed
});
Dialog.close();
});
Dialog.open();
});
},
/**
* Create a edit / add entry dialog
*
* @return {Promise}
*/
$createDialog: function () {
var self = this;
return new Promise(function (resolve) {
var Dialog = new QUIConfirm({
title : QUILocale.get(lg, 'control.navTabsVertical.entries.add.title'),
icon : 'fa fa-edit',
maxWidth : 800,
maxHeight : 600,
autoclose : false,

Dominik Chrzanowski
committed
IsDisabledSwitch: false,

Dominik Chrzanowski
committed
onOpen: function (Win) {
Win.Loader.show();
Win.getContent().set('html', '');
var prefix = 'control.navTabsVertical.entries.',

Dominik Chrzanowski
committed
Container = new Element('div', {
html : Mustache.render(templateEntry, {
fieldIsDisabled : QUILocale.get(lg, prefix + 'isDisable'),
fieldTitleIcon : QUILocale.get(lg, prefix + 'entryTitleIcon'),
fieldEntryTitle : QUILocale.get(lg, prefix + 'entryTitle'),
fieldEntryImage : QUILocale.get(lg, prefix + 'entryImage'),

Dominik Chrzanowski
committed
fieldEntryContent: QUILocale.get(lg, prefix + 'entryContent')
}),
'class': 'quiqqer-menu-navTabsVertival-settings'
}).inject(Win.getContent());
var Text = Container.getElement('.field-entryContent');
Text.getParent().setStyles({
height: 100
});
Win.IsDisabledSwitch = new QUISwitch({

Dominik Chrzanowski
committed
status: false
}).inject(Container.getElement('#isDisabledWrapper'));
Win.NewTabSwitch = new QUISwitch({
name: 'newTab'
}).inject(Container.getElement('#newTabWrapper'));
QUI.parse(Container).then(function () {
return ControlsUtils.parse(Container);
}).then(function () {
var controls = QUI.Controls.getControlsInElement(Container),

Dominik Chrzanowski
committed
controls.each(function (Control) {
if (Control === self) {
return;
}
if ("setProject" in Control) {
Control.setProject(project);
}
});
Win.fireEvent('openAfterCreate', [Win]);
moofx(Container).animate({
opacity: 1,

Dominik Chrzanowski
committed
}, {
duration: 250,
callback: function () {
resolve(Container);
Win.Loader.hide();
}
});
});
}
}
});
resolve(Dialog);
});
}
});
});