Newer
Older
* @module package/quiqqer/bricks/bin/Controls/Slider/PromosliderSettingsOnlyContent
* @author www.pcsg.de (Henning Leutz)
* Wallpaper Slider mit zwei Inhaltsbereichen
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
*/
define('package/quiqqer/bricks/bin/Controls/Slider/PromosliderSettingsOnlyContent', [
'qui/QUI',
'qui/controls/Control',
'qui/controls/windows/Confirm',
'qui/controls/buttons/Button',
'Locale',
'Mustache',
'controls/grid/Grid',
'utils/Controls',
'text!package/quiqqer/bricks/bin/Controls/Slider/PromosliderSettingsOnlyContentEntry.html',
'css!package/quiqqer/bricks/bin/Controls/Slider/PromoSliderSettings.css'
], function (QUI, QUIControl, QUIConfirm, QUIButton, QUILocale,
Mustache, Grid, ControlsUtils, templateEntry) {
"use strict";
var lg = 'quiqqer/bricks';
return new Class({
Extends: QUIControl,
Type : 'package/quiqqer/bricks/bin/Controls/Slider/PromosliderSettings',
Binds: [
'$onImport',
'$openAddDialog',
'$openDeleteDialog',
'$openEditDialog'
],
initialize: function (options) {
this.parent(options);
this.$Input = null;
this.$Grid = null;
this.$data = [];
this.addEvents({
onImport: this.$onImport
});
},
/**
* event: on import
*/
$onImport: function () {
this.$Input = this.getElm();
this.$Elm = new Element('div', {
'class': 'quiqqer-bricks-promoslider-settings',
styles : {
clear : 'both',
'float' : 'left',
height : 400,
overflow: 'hidden',
position: 'relative',
margin : '10px 0 0 0',
width : '100%'
}
}).wraps(this.$Input);
// exist label?
var id = this.$Input.get('id'),
Label = document.getElement('label[for="' + id + '"]');
if (Label) {
var Cell = Label.getParent('td'),
OldCell = this.$Elm.getParent('td');
Cell.set('colspan', 2);
this.$Elm.inject(Cell);
OldCell.destroy();
}
// 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 : [{
name : 'up',
icon : 'fa fa-angle-up',
disabled: true,
events : {
onClick: function () {
this.$Grid.moveup();
this.$refreshSorting();
}.bind(this)
}
}, {
name : 'down',
icon : 'fa fa-angle-down',
disabled: true,
events : {
onClick: function () {
this.$Grid.movedown();
this.$refreshSorting();
}.bind(this)
}
}, {
}, {
name : 'add',
textimage: 'fa fa-plus',
text : QUILocale.get('quiqqer/system', 'add'),
events : {
onClick: this.$openAddDialog
}
}, {
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
}, {
name : 'edit',
textimage: 'fa fa-edit',
text : QUILocale.get('quiqqer/system', 'edit'),
disabled : true,
events : {
onClick: this.$openEditDialog
}
}, {
name : 'delete',
textimage: 'fa fa-trash',
text : QUILocale.get('quiqqer/system', 'delete'),
disabled : true,
events : {
onClick: this.$openDeleteDialog
}
}],
columnModel: [{
header : QUILocale.get('quiqqer/system', 'image'),
dataIndex: 'imagePreview',
dataType : 'node',
width : 60
}, {
header : QUILocale.get(lg, 'quiqqer.products.control.promoslider.left'),
dataIndex: 'left',
dataType : 'code',
width : 300
}, {
header : QUILocale.get(lg, 'quiqqer.products.control.promoslider.right'),
dataIndex: 'right',
dataType : 'code',
width : 300
}, {
header : QUILocale.get(lg, 'quiqqer.products.control.promoslider.url'),
dataIndex: 'url',
dataType : 'string',
width : 300
}, {
dataIndex: 'image',
dataType : 'string',
hidden : true
}]
});
this.$Grid.addEvents({
onClick: function () {
var buttons = this.$Grid.getButtons(),
Edit = buttons.filter(function (Btn) {

Henning Leutz
committed
return Btn.getAttribute('name') === 'edit';
})[0],
Up = buttons.filter(function (Btn) {

Henning Leutz
committed
return Btn.getAttribute('name') === 'up';
})[0],
Down = buttons.filter(function (Btn) {

Henning Leutz
committed
return Btn.getAttribute('name') === 'down';
})[0],
Delete = buttons.filter(function (Btn) {

Henning Leutz
committed
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);

Henning Leutz
committed
if (typeOf(this.$data) !== 'array') {
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
this.$data = [];
}
this.refresh();
} catch (e) {
}
},
/**
* 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++) {
entry = this.$data[i];
insert = {
image : '',
imagePreview: new Element('span', {html: ' '})
};
if ("image" in entry && entry.image !== '') {
insert.image = entry.image;
insert.imagePreview = new Element('img', {
src: URL_DIR + insert.image + '&maxwidth=50&maxheight=50'
});
}
if ("left" in entry) {
insert.left = entry.left;
}
if ("right" in entry) {
insert.right = entry.right;
}
if ("url" in entry) {
insert.url = entry.url;
}
data.push(insert);
}
this.$Grid.setData({
data: data
});
var buttons = this.$Grid.getButtons(),
Edit = buttons.filter(function (Btn) {

Henning Leutz
committed
return Btn.getAttribute('name') === 'edit';
})[0],
Up = buttons.filter(function (Btn) {

Henning Leutz
committed
return Btn.getAttribute('name') === 'up';
})[0],
Down = buttons.filter(function (Btn) {

Henning Leutz
committed
return Btn.getAttribute('name') === 'down';
})[0],
Delete = buttons.filter(function (Btn) {

Henning Leutz
committed
return Btn.getAttribute('name') === 'delete';
})[0];
Up.disable();
Down.disable();
Edit.disable();
Delete.disable();
},
/**
* Refresh the data sorting in dependence of the grid
*/
$refreshSorting: function () {
var gridData = this.$Grid.getData(),
data = [];
for (var i = 0, len = gridData.length; i < len; i++) {
data.push({
image: gridData[i].image,
left : gridData[i].left,
right: gridData[i].right,
url : gridData[i].url || ''
});
}
this.$data = data;
this.update();
},
/**
* Update the field
*/
update: function () {
this.$Input.value = JSON.encode(this.$data);
},
/**
* Add an entry
*
* @param {string} [left] - left content
* @param {string} [right] - right content
* @param {string} [image] - image
* @param {string} [url] - click url
add: function (left, right, image, url) {
this.$data.push({
left : left || '',
right: right || '',
image: image || '',
url : url || ''
});
this.refresh();
this.update();
},
/**
* Edit an entry
*
* @param {number} index
* @param {string} [left] - left content
* @param {string} [right] - right content
* @param {string} [image] - image path
* @param {string} [url] - click url
edit: function (index, left, right, image, url) {
if (typeof index === 'undefined') {
return;
}
this.$data[index] = {
left : left || '',
right: right || '',
image: image || '',
url : url || ''
};
this.refresh();
this.update();
},
/**
* Delete one entry or multiple entries
*
* @param {number|array} index
*/
del: function (index) {
var newList = [];

Henning Leutz
committed
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) {

Henning Leutz
committed
if (Control === this) {
return;
}
if ("setProject" in Control) {
Control.setProject(Project);
}
}.bind(this));
},
/**

Henning Leutz
committed
* Dialogs
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
*/
/**
* opens the delete dialog
*
* @return {Promise}
*/
$openDeleteDialog: function () {
new QUIConfirm({
icon : 'fa fa-icon',
title : QUILocale.get(lg, 'quiqqer.products.control.delete.title'),
text : QUILocale.get(lg, 'quiqqer.products.control.delete.text'),
information: QUILocale.get(lg, 'quiqqer.products.control.delete.information'),
texticon : false,
maxWidth : 600,
maxHeight : 400,
ok_button : {
text : QUILocale.get('quiqqer/system', 'delete'),
textimage: 'fa fa-trash'
},
events : {
onSubmit: function () {
var selected = this.$Grid.getSelectedIndices();
this.$Grid.deleteRows(selected);
this.del(selected);
this.update();
}.bind(this)
}
}).open();
},

Henning Leutz
committed
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
496
497
498
499
500
/**
* Open edit dialog
*
* @retrun {Promise}
*/
$openEditDialog: function () {
var self = this,
data = this.$Grid.getSelectedData(),
index = this.$Grid.getSelectedIndices();
if (!data.length) {
return Promise.resolve();
}
data = data[0];
index = index[0];
return this.$createDialog().then(function (Dialog) {
Dialog.addEvent('onOpenAfterCreate', function () {
var Content = Dialog.getContent();
var Form = Content.getElement('form');
var Left = Form.elements.left;
var Right = Form.elements.right;
var Image = Form.elements.image;
var Url = Form.elements.url;
Left.value = data.left;
Right.value = data.right;
Image.value = data.image;
Url.value = data.url;
Image.fireEvent('change');
});
Dialog.addEvent('onSubmit', function () {
Dialog.Loader.show();
var Content = Dialog.getContent();
var Form = Content.getElement('form');
var Left = Form.elements.left;
var Right = Form.elements.right;
var Image = Form.elements.image;
var Url = Form.elements.url;
self.edit(index, Left.value, Right.value, Image.value, Url.value);
Dialog.close();
});
Dialog.setAttribute('title', QUILocale.get(lg, 'quiqqer.bricks.promoslider.editialog.title'));
Dialog.open();
});
},
/**
*
* @returns {Promise}
*/
$openAddDialog: function () {

Henning Leutz
committed
var self = this;

Henning Leutz
committed
return this.$createDialog().then(function (Dialog) {
Dialog.addEvent('onSubmit', function () {
Dialog.Loader.show();

Henning Leutz
committed
var Content = Dialog.getContent();
var Form = Content.getElement('form');
var Left = Form.elements.left;
var Right = Form.elements.right;
var Image = Form.elements.image;
var Url = Form.elements.url;

Henning Leutz
committed
self.add(Left.value, Right.value, Image.value, Url.value);

Henning Leutz
committed
Dialog.close();
});
Dialog.open();
});
},
/**
* Create a edit / add entry dialog
*
* @return {Promise}
*/
$createDialog: function () {

Henning Leutz
committed
var self = this;

Henning Leutz
committed
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
return new Promise(function (resolve) {
var Dialog = new QUIConfirm({
title : QUILocale.get(lg, 'quiqqer.bricks.promoslider.adddialog.title'),
icon : 'fa fa-edit',
maxWidth : 800,
maxHeight: 600,
autoclose: false,
events : {
onOpen: function (Win) {
Win.Loader.show();
Win.getContent().set('html', '');
var Container = new Element('div', {
html : Mustache.render(templateEntry, {
fieldImage : QUILocale.get(lg, 'quiqqer.bricks.promoslider.create.image'),
fieldUrl : QUILocale.get(lg, 'quiqqer.bricks.promoslider.create.url'),
fieldTitle : QUILocale.get(lg, 'quiqqer.bricks.promoslider.create.title'),
fieldDescription: QUILocale.get(lg, 'quiqqer.bricks.promoslider.create.text'),
fieldType : QUILocale.get(lg, 'quiqqer.bricks.promoslider.create.align'),
fieldLeft : QUILocale.get(lg, 'quiqqer.products.control.promoslider.left'),
fieldRight : QUILocale.get(lg, 'quiqqer.products.control.promoslider.right')
}),
'class': 'quiqqer-bricks-promoslider-settings-entry'
}).inject(Win.getContent());
var Text = Container.getElement('.field-description');
Text.getParent().setStyles({
height: 100
});
QUI.parse(Container).then(function () {
return ControlsUtils.parse(Container);
}).then(function () {
var controls = QUI.Controls.getControlsInElement(Container),
project = self.getAttribute('project');
controls.each(function (Control) {
if (Control === self) {
return;
}
if ("setProject" in Control) {
Control.setProject(project);
}
});
Win.fireEvent('openAfterCreate', [Win]);
moofx(Container).animate({
opacity: 1,
top : 0
}, {
duration: 250,
callback: function () {
resolve(Container);
Win.Loader.hide();
}
});
});

Henning Leutz
committed
});

Henning Leutz
committed
resolve(Dialog);
});