Newer
Older
/**
* Area edit control for the site object
*
* @author www.pcsg.de (Henning Leutz)

Henning Leutz
committed
*
* @require qui/QUI
* @require qui/controls/Control
* @require qui/controls/buttons/Button
* @require qui/controls/windows/Popup
* @require qui/controls/windows/Confirm
* @require qui/controls/elements/List
* @require Locale
* @require Ajax
* @require package/quiqqer/bricks/bin/Sortables
* @require css!package/quiqqer/bricks/bin/Site/Area.css

Henning Leutz
committed
'qui/QUI',
'qui/controls/Control',
'qui/controls/buttons/Button',
'Locale',
'Ajax',

Henning Leutz
committed
], function(QUI, QUIControl, QUIButton, QUIPopup, QUIConfirm, QUIList, QUILocale, QUIAjax, Sortables)
{
"use strict";
return new Class({
Extends : QUIControl,
Binds : [
'$onInject'
],
options : {
name : '',
description : '',
title : {},
},
initialize: function (options)
{
this.parent( options );
this.$loaded = false;
this.$AddButton = false;
this.$SettingsButton = false;
this.$SortableButton = false;
this.$MoreButton = false;

Henning Leutz
committed
this.$ExtraBtns = false;
this.addEvents({
onInject : this.$onInject
});
},
/**
* Return the domnode element
*/
create: function ()
{
this.$Elm = new Element('div', {
'class' : 'quiqqer-bricks-site-category-area',
html : '<div class="quiqqer-bricks-site-category-area-title">'+
QUILocale.get( title.group, title.var ) +
' <div class="quiqqer-bricks-site-category-area-buttons"></div>' +
'</div><ul class="quiqqer-bricks-site-category-area-list"></ul>',
'data-name' : this.getAttribute( 'name' )
});
var Buttons = this.$Elm.getElement(

Henning Leutz
committed
this.$ExtraBtns = new Element('div', {
'class' : 'quiqqer-bricks-site-category-area-extraButtons'
});
this.$Title = this.$Elm.getElement(
'.quiqqer-bricks-site-category-area-title'
);

Henning Leutz
committed
this.$FXExtraBtns = moofx( this.$ExtraBtns );
this.$List = this.$Elm.getElement(
'.quiqqer-bricks-site-category-area-list'
);
// buttons
this.$AddButton = new QUIButton({
text : QUILocale.get( lg, 'site.area.button.add' ),
textimage : 'icon-plus',
disable : true,
events : {
}
}).inject( Buttons );

Henning Leutz
committed
this.$ExtraBtns.inject( Buttons );
this.$MoreButton = new QUIButton({
title : QUILocale.get( lg, 'site.area.button.area.more.openIt' ),
icon : 'icon-caret-left',
events :
{
onClick : function(Btn)
{
if ( Btn.getAttribute( 'icon' ) == 'icon-caret-left' )
{
self.openButtons();
return;
}
self.closeButtons();
}
},
styles : {
marginLeft : 5
}
}).inject( Buttons );
// extra buttons
this.$SettingsButton = new QUIButton({
title : QUILocale.get( lg, 'site.area.button.area.settings' ),
icon : 'icon-gears',
events : {
onClick : this.openSettingsDialog
},
styles : {
marginLeft : 10
}

Henning Leutz
committed
}).inject( this.$ExtraBtns );
this.$SortableButton = new QUIButton({
title : QUILocale.get( lg, 'site.area.button.area.sort' ),
icon : 'icon-sort',
events :
{
onClick : function(Btn)
{
if ( Btn.isActive() )
{
Btn.setNormal();
self.unsortable();
return;
}
Btn.setActive();
self.sortable();
}
},
styles : {
marginLeft : 5
}

Henning Leutz
committed
}).inject( this.$ExtraBtns );
return this.$Elm;
},
/**
* event : on inject
*/
$onInject : function()
{
var self = this,
Project = Site.getProject();
var Loader = new Element('div', {
'class' : 'quiqqer-bricks-site-category-area-loader',
html : '<span class="icon-spinner icon-spin fa fa-spinner fa-spin"></span>',
styles : {
margin : 5
}
}).inject(this.$Elm);
this.$List.setStyles({
position : 'absolute',
opacity : 0
});
QUIAjax.get('package_quiqqer_bricks_ajax_project_getBricks', function(bricks)
{
self.$AddButton.enable();
self.$loaded = true;
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
if (promises.length) {
Promise.resolve(promises).then(function() {
var size = self.$List.getComputedSize(),
titleSize = self.$Title.getComputedSize();
moofx(self.$Elm).animate({
height : size.height + titleSize.height
}, {
duration : 250,
equation : 'cubic-bezier(.42,.4,.46,1.29)',
callback : function() {
self.$List.setStyle('position', null);
moofx(self.$List).animate({
opacity : 1
}, {
duration : 250,
equation : 'ease-out'
});
}
});
Loader.destroy();
});
return;
}
Loader.destroy();
project : Project.encode(),
area : this.getAttribute( 'name' )
});
},
/**
this.setAttribute( 'deactivate', false );
this.getElm().removeClass( 'quiqqer-bricks-site-category-area-deactivate' );
/**
* Deactivate the area
*/
deactivate : function()
{
var self = this,
data = this.getData();
if (data.length && !("deactivate" in data[ 0 ]))
new QUIConfirm({
title : QUILocale.get( lg, 'site.area.window.deactivate.title' ),
text : QUILocale.get( lg, 'site.area.window.deactivate.text' ),
information : QUILocale.get( lg, 'site.area.window.deactivate.information' ),
events :
{
onSubmit : function()
{
self.clear();
self.setAttribute( 'deactivate', true );
self.deactivate();
}
}
}).open();
return;
this.setAttribute( 'deactivate', true );
this.$AddButton.disable();
this.getElm().addClass( 'quiqqer-bricks-site-category-area-deactivate' );
* @param {Object} brickData - { brickId:1, inheritance:1 }
return new Promise(function(reslove, reject) {
if ("deactivate" in brickData)
{
this.clear();
this.setAttribute( 'deactivate', true );
this.deactivate();
if (!this.$loaded)
{
this.$brickData.push( brickData );
reslove();
return;
}
var BrickNode = this.addBrickById( brickData.brickId );
if (!BrickNode) {
reject();
return;
}
var Select = BrickNode.getElement( 'select' );
Select.set('data-inheritance', 0);
if ("inheritance" in brickData) {
Select.set( 'data-inheritance', brickData.inheritance );
}
}.bind(this));
},
/**
* @param {Number} brickId
* @return {HTMLElement|Boolean} Brick-Node
var found = this.$availableBricks.filter(function(Item) {
return Item.id === brickId;
BrickNode.getElement('select').set('value', brickId);
/**
* Removes all bricks in the area
*/
clear : function()
{
this.getElm().getElements( '.quiqqer-bricks-site-category-area-brick' ).destroy();
},
{
var i, len, Select;
html : '<select></select>'
});
Select = Elm.getElement( 'select' );
new QUIButton({
title : QUILocale.get( lg, 'site.area.button.delete' ),
events :
{
onClick : function() {
}
}
}).inject( Elm );
title : QUILocale.get( lg, 'site.area.button.settings' ),
icon : 'icon-gear',
events :
{
onClick : function(Btn)
{
var Elm = Btn.getElm(),
Parent = Elm.getParent( '.quiqqer-bricks-site-category-area-brick' ),
Select = Parent.getElement( 'select' );
self.openBrickSettingDialog( Select );
}
}
}).inject( Elm );
for (i = 0, len = this.$availableBricks.length; i < len; i++)
{
new Element('option', {
html : this.$availableBricks[ i ].title,
value : this.$availableBricks[ i ].id
}).inject( Select );
}
return Elm;
/**
* Return the brick list
* @returns {Array}
*/
getData : function()
{
{
return [{
deactivate : 1
}];
}
var data = [],
bricks = this.$Elm.getElements( 'select' );
for (var i = 0, len = bricks.length; i < len; i++)
{
data.push({
brickId : bricks[ i ].value,
inheritance : bricks[ i ].get( 'data-inheritance' ) == 1 ? 1 : 0
});
}
return data;
},
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
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
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
/**
* sort methods
*/
/**
* Switch the sortable on
*/
sortable : function()
{
var Elm = this.getElm(),
elements = Elm.getElements(
'.quiqqer-bricks-site-category-area-brick'
);
elements.each(function(Brick)
{
var i, len, buttons, Button;
buttons = Brick.getElements( '.qui-button' );
for ( i = 0, len = buttons.length; i < len; i++ )
{
Button = QUI.Controls.getById( buttons[ i ].get( 'data-quiid' ) );
if ( Button ) {
Button.setDisable();
}
}
var Select = Brick.getElement( 'select' ),
Option = Select.getElement( 'option[value="'+ Select.value +'"]' );
new Element('div', {
'class' : 'quiqqer-bricks-site-category-area-placeholder',
html : Option.get( 'html' )
}).inject( Brick );
});
Elm.getElements( 'select' ).set( 'disabled', true );
new Sortables( this.$List, {
revert: {
duration: 500,
transition: 'elastic:out'
},
clone : function(event)
{
var Target = event.target;
if ( Target.nodeName != 'LI' ) {
Target = Target.getParent( 'li' );
}
var size = Target.getSize(),
pos = Target.getPosition( Target.getParent('ul') );
return new Element('div', {
styles : {
background : 'rgba(0,0,0,0.5)',
height : size.y,
top : pos.y,
width : size.x,
zIndex : 1000
}
});
},
onStart : function(element)
{
var Ul = element.getParent( 'ul' );
element.addClass( 'quiqqer-bricks-site-category-area-dd-active' );
Ul.setStyles({
height : Ul.getSize().y,
overflow : 'hidden',
width : Ul.getSize().x
});
},
onComplete : function(element)
{
var Ul = element.getParent( 'ul' );
element.removeClass( 'quiqqer-bricks-site-category-area-dd-active' );
Ul.setStyles({
height : null,
overflow : null,
width : null
});
}
});
},
/**
* Switch the sortable off
*/
unsortable : function()
{
var Elm = this.getElm(),
elements = Elm.getElements(
'.quiqqer-bricks-site-category-area-brick'
);
Elm.getElements( 'select' ).set( 'disabled', false );
Elm.getElements( '.quiqqer-bricks-site-category-area-placeholder').destroy();
elements.each(function(Brick)
{
var i, len, buttons, Button;
buttons = Brick.getElements( '.qui-button' );
for ( i = 0, len = buttons.length; i < len; i++ )
{
Button = QUI.Controls.getById( buttons[ i ].get( 'data-quiid' ) );
if ( Button ) {
Button.setEnable();
}
}
});
},
/**
* Opens the extra settings buttons
*

Henning Leutz
committed
* @param {Function} [callback]
*/
openButtons : function(callback)
{
var self = this;
this.$AddButton.hide();
self.$FXExtraBtns.style({
borderLeft : '2px solid #cccfd5',

Henning Leutz
committed
height : 30,
overflow : 'hidden'

Henning Leutz
committed
var width = this.$ExtraBtns.getChildren().map(function(Elm)
{
var width = Elm.getSize().x;
width = width + Elm.getStyle( 'margin-left' ).toInt();
width = width + Elm.getStyle( 'margin-right' ).toInt();
return width;
}).sum();
// i dont know why i need 2 px more -.-"
width = width + 2;

Henning Leutz
committed
width : width,

Henning Leutz
committed
equation : 'ease-in-out',
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
callback : function()
{
self.$MoreButton.setAttribute( 'icon', 'icon-caret-right' );
self.$FXExtraBtns.style({
overflow : null
});
if ( typeof callback === 'function' ) {
callback();
}
}
});
},
/**
* Close the extra settings buttons
*
* * @param {Function} callback
*/
closeButtons : function( callback )
{
var self = this;
this.$FXExtraBtns.style({
overflow : 'hidden',
borderLeft : null,
marginLeft : 0
});
this.$FXExtraBtns.animate({
opacity : 0,
width : 0
}, {
callback : function()
{
self.$MoreButton.setAttribute( 'icon', 'icon-caret-left' );
self.$AddButton.show();
if ( typeof callback === 'function' ) {
callback();
}
}
});
},
/**
* Opens the brick add dialog
*/
openBrickDialog : function()
{
if ( !this.$availableBricks.length ) {
return;
}
var self = this;
new QUIPopup({
title : QUILocale.get( lg, 'site.area.window.add' ),
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
icon : 'icon-th',
maxWidth : 500,
maxHeight : 600,
autoclose : false,
events :
{
onOpen : function(Win)
{
var items = [],
Content = Win.getContent(),
List = new QUIList({
events :
{
onClick : function(List, data)
{
self.addBrickById( data.brickId );
Win.close();
}
}
});
List.inject( Content );
for ( var i = 0, len = self.$availableBricks.length; i < len; i++ )
{
items.push({
brickId : self.$availableBricks[ i ].id,
icon : 'icon-th',
title : self.$availableBricks[ i ].title,
text : self.$availableBricks[ i ].description
});
}
List.addItems( items );
}
}
}).open();
/**
* Opens the brick deletion dialog
*
* @param {HTMLElement} BrickElement - Element of the Brick
*/
openBrickDeleteDialog : function(BrickElement)
{
new QUIConfirm({
title : QUILocale.get( lg, 'site.area.window.delete.title' ),
text : QUILocale.get( lg, 'site.area.window.delete.text' ),
information : QUILocale.get( lg, 'site.area.window.delete.information' ),
events :
{
onSubmit : function() {
BrickElement.destroy();
}
}
}).open();
},
/**
* Opens the brick settings dialog
*
* @param {HTMLElement} Select
*/
openBrickSettingDialog : function(Select)
{
new QUIConfirm({
title : QUILocale.get(lg, 'site.area.window.settings.title'),
ok_button : {
text : QUILocale.get('quiqqer/system', 'save'),
textimage : 'icon-save fa fa-save'
},
cancel_button : {
text : QUILocale.get('quiqqer/system', 'cancel'),
textimage : 'icon-remove fa fa-remove'
},
events :
require([
'package/quiqqer/bricks/bin/Site/BrickEdit'
], function(BrickEdit) {
Win.Edit = new BrickEdit({
brickId : Select.value,
styles : {
height : Win.getContent().getSize().y
}
}).inject(Win.getContent());
});
/*
var Content = Win.getContent();
Content.set(
'html',
'<form>' +
' <label>' +
' <input type="checkbox" name="inheritance" />' +
QUILocale.get( lg, 'site.area.window.settings.setting.inheritance' ) +
var Form = Win.getContent().getElement( 'form' ),
elms = Form.elements;
elms.inheritance.checked = Select.get( 'data-inheritance' ).toInt();
// var Form = Win.getContent().getElement( 'form' );
//
// Select.set({
// 'data-inheritance' : Form.elements.inheritance.checked ? 1 : 0
// });
//
// Win.close();
},
/**
* Opens the
*/
openSettingsDialog : function()
{
var self = this;
new QUIConfirm({
title : QUILocale.get(lg, 'area.window.settings.title'),
icon : 'icon-gear',
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
maxHeight : 300,
autoclose : false,
events :
{
onOpen: function (Win)
{
var Content = Win.getContent();
Content.set(
'html',
'<form>' +
' <label>' +
' <input type="checkbox" name="deactivate" />' +
QUILocale.get( lg, 'area.window.settings.deactivate' ) +
' </label>' +
'</form>'
);
var Form = Win.getContent().getElement( 'form' ),
elms = Form.elements;
elms.deactivate.checked = self.getAttribute( 'deactivate' );
},
onSubmit : function(Win)
{
var Form = Win.getContent().getElement( 'form' );
Win.close();
if ( Form.elements.deactivate.checked )
{
self.deactivate();
} else
{
self.activate();
}
}
}
}).open();
}
});
});