Newer
Older
* @author www.pcsg.de (Henning Leutz)

Henning Leutz
committed
*
* @require qui/QUI
* @require qui/controls/desktop/Panel
* @require qui/controls/buttons/Select
* @require qui/controls/buttons/Button
* @require qui/controls/buttons/Seperator
* @require qui/controls/windows/Confirm
* @require controls/grid/Grid
* @require Locale
* @require Projects
* @require Ajax
* @require css!package/quiqqer/bricks/bin/Manager.css
'qui/QUI',
'qui/controls/desktop/Panel',
'qui/controls/buttons/Select',
'qui/controls/buttons/Button',
'qui/controls/buttons/Seperator',
'controls/grid/Grid',
'Locale',
'Projects',
], function (QUI, QUIPanel, QUISelect, QUIButton, QUISeperator, QUIConfirm, Grid, QUILocale, Projects, Ajax) {
Extends: QUIPanel,
Type : 'package/quiqqer/bricks/bin/Manager',
this.$Grid = false;
this.$ProjectSelect = false;
this.$ProjectLangs = false;
var self = this,
project = this.$ProjectSelect.getValue(),
lang = this.$ProjectLangs.getValue();
var options = self.$Grid.options,
page = parseInt(options.page),
perPage = parseInt(options.perPage),
data : result.slice(start, start + perPage),
page : page,
total: result.length
var selected = this.$Grid.getSelectedData(),
AddButton = this.getButtons('brick-add'),
EditButton = this.getButtons('brick-edit'),
DelButton = this.getButtons('brick-delete');
return;
}
AddButton.enable();
DelButton.enable();
if (selected.length == 1) {
EditButton.enable();
}
var self = this;
// Buttons
this.$ProjectSelect = new QUISelect({
name : 'projects-name',
events: {
onChange: this.$refreshProjectLanguages
}
});
this.$ProjectLangs = new QUISelect({
name : 'projects-langs',
events: {
onChange: this.refresh
this.addButton(this.$ProjectSelect);
this.addButton(this.$ProjectLangs);
this.addButton(new QUISeperator());
textimage: 'fa fa-plus',
text : QUILocale.get(lg, 'manager.button.add'),
title : QUILocale.get(lg, 'manager.button.add'),
name : 'brick-add',
disabled : true,
events : {
textimage: 'fa fa-edit',
text : QUILocale.get(lg, 'manager.button.edit'),
title : QUILocale.get(lg, 'manager.button.edit'),
name : 'brick-edit',
disabled : true,
events : {
onClick: function () {
this.editBrick(
this.$Grid.getSelectedData()[0].id
);
}.bind(this)
}
})
);
this.addButton(
new QUIButton({
icon : 'fa fa-trash',
title : QUILocale.get(lg, 'manager.button.delete'),
// Grid
var Container = new Element('div').inject(
this.getContent()
);
columnModel : [{
header : QUILocale.get('quiqqer/system', 'id'),
dataIndex: 'id',
dataType : 'integer',
width : 40
header : QUILocale.get('quiqqer/system', 'title'),
dataIndex: 'title',
dataType : 'string',
width : 140
header : QUILocale.get('quiqqer/system', 'description'),
dataIndex: 'description',
dataType : 'string',
width : 300
header : QUILocale.get(lg, 'brick.type'),
dataIndex: 'type',
dataType : 'string',
width : 200
onRefresh : this.refresh,
onDblClick: this.$onDblClick,
onClick : this.$onClick
Projects.getList(function (projects) {
for (var project in projects) {
continue;
}
self.$ProjectSelect.appendChild(
);
}
self.$ProjectSelect.setValue(
);
});
},
/**
* event : on resize
*/
return;
}
var Body = this.getContent();
return;
}
var size = Body.getSize();
this.$Grid.setHeight(size.y - 40);
this.$Grid.setWidth(size.x - 40);
/**
* Refresh the project language dropdown
*/
var self = this,
activeProject = this.$ProjectSelect.getValue();
Projects.getList(function (projects) {
for (var project in projects) {
if (!projects.hasOwnProperty(project)) {
var langs = projects[project].langs;
langs = langs.split(',');
);
}
self.$ProjectLangs.setValue(
maxHeight: 300,
maxWidth : 400,
autoclose: false,
events : {
onOpen: function (Win) {

Henning Leutz
committed
' <input type="text" name="title" required="required" />' +
' </span>' +
' <select name="type"></select>' +
'</label>'
);
self.getAvailableBricks(function (bricklist) {
if (!Body) {
var i, len, group, title, val;
var Select = Body.getElement('select'),
Title = Body.getElement('[name="title"]');
for (i = 0, len = bricklist.length; i < len; i++) {
title = bricklist[i].title;
group = title.group;
val = title.var;
value: bricklist[i].control,
html : QUILocale.get(group, val)
}).inject(Select);
Title = Body.getElement('[name="title"]'),
Type = Body.getElement('[name="type"]');
if (Title.value === '') {
QUI.getMessageHandler(function (MH) {

Henning Leutz
committed
MH.addError(

Henning Leutz
committed
Title
);
});
Title.focus();
Win.Loader.hide();
var project = self.$ProjectSelect.getValue(),
lang = self.$ProjectLangs.getValue();
self.createBrick(project, lang, {
title: Title.value,
type : Type.value
}, function (brickId) {
brickIds = this.$Grid.getSelectedData().map(function (brick) {
maxHeight: 300,
maxWidth : 600,
autoclose: false,
title : QUILocale.get(lg, 'manager.window.delete.title'),
events : {
onOpen: function (Win) {
self.$Grid.getSelectedData().each(function (brick) {
lists = lists + '<li>' + brick.id + ' - ' + brick.title + '</li>';
QUILocale.get(lg, 'manager.window.delete.information', {
list: lists
Win.close();
self.refresh();
});
}
}
}).open();
},
/**
require([
'package/quiqqer/bricks/bin/BrickEdit',
'utils/Panels'
PanelUtils.openPanelInTasks(
new BrickEdit({
id : brickId,
projectName: this.$ProjectSelect.getValue(),
projectLang: this.$ProjectLangs.getValue(),
events : {
onDelete: this.refresh
*
* @param {Function} [callback] - callback function
*
* @return Promise
getAvailableBricks: function (callback) {
return new Promise(function (resolve, reject) {
Ajax.get('package_quiqqer_bricks_ajax_getAvailableBricks', function (result) {
if (typeof callback === 'function') {
callback(result);
}
resolve(result);
}, {
*
* @param {String} project - name of the project
* @param {String} lang - Language of the project
* @param {Function} [callback] - callback function
*
* @return Promise
getBricksFromProject: function (project, lang, callback) {
return new Promise(function (resolve, reject) {
Ajax.get('package_quiqqer_bricks_ajax_project_getBricks', function (result) {
if (typeof callback === 'function') {
callback(result);
}
resolve(result);
}, {
'package': 'quiqqer/bricks',
project : JSON.encode({
name: project,
lang: lang
* @param {String} project - name of the project
* @param {String} lang - Language of the project
* @param {Object} data - Data of the brick
* @param {Function} [callback] - callback function
*
* @return Promise
createBrick: function (project, lang, data, callback) {
return new Promise(function (resolve, reject) {
Ajax.post('package_quiqqer_bricks_ajax_project_createBrick', function (brickId) {
if (typeof callback === 'function') {
callback(brickId);
}
resolve(brickId);
}, {
'package': 'quiqqer/bricks',
project : JSON.encode({
name: project,
lang: lang
* @param {Array} brickIds - Brick IDs which should be deleted
* @param {Function} [callback] - callback function
*
* @return Promise
var panels = QUI.Controls.getByType(
'package/quiqqer/bricks/bin/BrickEdit'
);
Ajax.post('package_quiqqer_bricks_ajax_brick_delete', function () {
if (typeof callback === 'function') {
callback();
}
resolve();
// exist brick panels?
var c, i, len, clen, brickId;
for (i = 0, len = brickIds.length; i < len; i++) {
brickId = brickIds[i];
for (c = 0, clen = panels.length; c < clen; c++) {
if (panels[c].getAttribute('id') == brickId) {
panels[c].destroy();
}
}
}
'package': 'quiqqer/bricks',
brickIds : JSON.encode(brickIds),
onError : reject