Newer
Older
1
2
3
4
5
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/**
* BlockEdit Control
* Edit and change a Block
*
* @module package/quiqqer/blocks/bin/BlockEdit
* @author www.pcsg.de (Henning Leutz)
*
* @event onLoaded [ this ]
*/
define('package/quiqqer/blocks/bin/BlockEdit', [
'qui/QUI',
'qui/controls/Control',
'package/quiqqer/blocks/bin/BlockAreas',
'Ajax',
'Locale',
'css!package/quiqqer/blocks/bin/BlockEdit.css'
], function(QUI, QUIControl, BlockAreas, Ajax, QUILocale)
{
"use strict";
return new Class({
Extends : QUIControl,
Type : 'package/quiqqer/blocks/bin/BlockEdit',
Binds : [
'$onInject',
'$onDestroy'
],
options : {
id : false,
project : false
},
initialize : function(options)
{
this.parent( options );
this.$availableBlocks = [];
this.$Editor = false;
this.$Areas = false;
this.addEvents({
onInject : this.$onInject,
onDestroy : this.$onDestroy
});
},
/**
* Return the HTML Node Element
*
* @return {HTMLElement}
*/
create : function()
{
this.$Elm = new Element('div', {
'class' : 'quiqqer-blocks-blockedit'
});
return this.$Elm;
},
/**
* event : on inject
*/
$onInject : function()
{
var self = this;
Ajax.get([
'package_quiqqer_blocks_ajax_getBlock',
'package_quiqqer_blocks_ajax_getAvailableBlocks'
], function(data, blocks)
{
self.$availableBlocks = blocks;
self.setAttributes( data );
self.$createData(function() {
self.fireEvent( 'loaded', [ self ] );
});
}, {
'package' : 'quiqqer/block',
blockId : this.getAttribute( 'id' )
});
},
/**
* event : on destroy
*/
$onDestroy : function()
{
if ( this.$Editor ) {
this.$Editor.destroy();
}
},
/**
* Create the html for the control
*
* @param {Function} [callback]
*/
$createData : function(callback)
{
var self = this;
new Element('div', {
'html' : '<label>' +
' <span class="quiqqer-blocks-blockedit-label-text">' +
' Title' +
' </span>' +
' <input type="text" name="title" />' +
'</label>' +
'<label>' +
' <span class="quiqqer-blocks-blockedit-label-text">' +
' Block Typ' +
' </span>' +
' <select name="type"></select>' +
'</label>'+
'<label class="quiqqer-blocks-areas">' +
' <span class="quiqqer-blocks-blockedit-label-text">' +
' Erlaubte Blockbereiche' +
' </span>' +
'</label>'
}).inject( this.$Elm );
var i, len, title, group, val;
var Type = this.$Elm.getElement( '[name="type"]'),
Title = this.$Elm.getElement( '[name="title"]' );
for ( i = 0, len = this.$availableBlocks.length; i < len; i++ )
{
title = this.$availableBlocks[ i ].title;
if ( 'group' in title )
{
group = title.group;
val = title.var;
} else
{
group = title[ 0 ];
val = title[ 1 ];
}
new Element('option', {
value : this.$availableBlocks[ i ].control,
html : QUILocale.get( group, val )
}).inject( Type );
}
Title.value = this.getAttribute( 'title' );
Type.value = this.getAttribute( 'type' );
var areas = [];
if ( this.getAttribute( 'areas' ) )
{
areas = this.getAttribute('areas')
.replace(/^,*/, '')
.replace(/,*$/, '')
.split(',');
}
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
// areas
this.$Areas = new BlockAreas({
blockId : this.getAttribute( 'id' ),
project : this.getAttribute( 'project' ),
areas : areas,
styles : {
height : 120
}
}).inject( this.$Elm.getElement( '.quiqqer-blocks-areas' ), 'after' );
// block type
if ( this.getAttribute( 'type' ) == 'content' )
{
new Element('label', {
html : '<span class="quiqqer-blocks-blockedit-label-editor">' +
'Block Inhalt' +
'</span>'
}).inject( this.$Elm );
// load ckeditor
require(['classes/editor/Manager'], function(EditorManager)
{
new EditorManager().getEditor(null, function(Editor)
{
self.$Editor = Editor;
var EditorContainer = new Element('div', {
styles : {
clear : 'both',
height : 300,
width : '100%'
}
}).inject( self.$Elm );
self.$Editor.addEvent('onLoaded', function()
{
if ( typeof callback === 'function' ) {
callback();
}
});
self.$Editor.inject( EditorContainer );
self.$Editor.setHeight( 300 );
self.$Editor.setContent( self.getAttribute( 'content' ) );
});
});
return;
}
// plugin / package blocks
if ( typeof callback === 'function' ) {
callback();
}
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
},
/**
* Saves the block
*/
save : function(callback)
{
var Type = this.$Elm.getElement( '[name="type"]'),
Title = this.$Elm.getElement( '[name="title"]' );
var data = {
title : Title.value,
type : Type.value,
content : '',
areas : this.$Areas.getAreas().join(',')
};
if ( this.$Editor ) {
data.content = this.$Editor.getContent();
}
Ajax.post('package_quiqqer_blocks_ajax_block_save', function()
{
if ( typeof callback === 'function' ) {
callback();
}
}, {
'package' : 'quiqqer/block',
blockId : this.getAttribute( 'id' ),
data : JSON.encode( data )
});
}
});
});