-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathjs_lib_gui_ui.js.html
More file actions
467 lines (394 loc) · 17.4 KB
/
js_lib_gui_ui.js.html
File metadata and controls
467 lines (394 loc) · 17.4 KB
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
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
160
161
162
163
164
165
166
167
168
169
170
171
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
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
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
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
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
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Source: js/lib/gui/ui.js</title>
<script src="scripts/prettify/prettify.js"> </script>
<script src="scripts/prettify/lang-css.js"> </script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>
<body>
<div id="main">
<h1 class="page-title">Source: js/lib/gui/ui.js</h1>
<section>
<article>
<pre class="prettyprint source linenums"><code>/**
* Responsible class to manage all things related with GUI
* @constructor
*/
function UI(){
}
/**
* Initialize wizard that show open or create new project
*/
UI.prototype.showIntro = function showIntro() {
var container = $(document.createElement('div')).attr('id','wizard');
container.dialog({modal:true,dialogClass: "no-close",closeOnEscape: false});
this.showNewOpenProject({data:{that:this}});
};
/**
* Show wizard with recent projects to open, create new project or open other project
* @param {event} e to send this object reference
*/
UI.prototype.showNewOpenProject = function showNewOpenProject(e) {
var that = e.data.that;
var userconfig = application.config.user.getInstance();
var backend = application.backend.getInstance();
var fs = require('fs');
var wizarddiv = $("#wizard") ;
wizarddiv.empty();
var datainfo = userconfig.getLastProjects();
var template = fs.readFileSync('./templates/initialwizard.step1.hbs',{encoding:'utf8'});
var templatecompiled = application.util.template.compile(template);
var data = {
projects : datainfo.slice(-5)
};
wizarddiv.append(templatecompiled(data));
$('#newproject').click({that:that},that.showTypeProject);
$('#listProjects button').click({that:that},that.launcherloadProject);
};
/**
* Load dialog on #wizard div to create new project.
* @param {event} e to send this object reference
*/
UI.prototype.showTypeProject = function(e) {
var that = e.data.that;
var fs = require('fs');
$("#wizard").empty();
var template = fs.readFileSync('./templates/initialwizard.step2.hbs',{encoding:'utf8'});
var templatecompiled = application.util.template.compile(template);
$("#wizard").append(templatecompiled());
$("#advprojbtn").click(function(){
var controller = application.controller.getInstance();
controller.createProProject($("#projectname").val());
$('#wizard').dialog('close');
$('#wizard').remove();
});
$("#smplprojbtn").click(function(){
var controller = application.controller.getInstance();
controller.createSimpleProject($("#projectname").val());
$('#wizard').dialog('close');
$('#wizard').remove();
});
$("#wzrdgoback").click({that:that},that.showNewOpenProject);
$("#projectname").keyup(function(e){
var backend = application.backend.getInstance();
if(backend.checkProjectExists(this.value)){
$("#projectnamecontainer").removeClass("has-success").addClass("has-error");
$("#validateindicator").removeClass("glyphicon-ok").addClass("glyphicon-remove");
$("#advprojbtn").attr("disabled","disabled");
$("#smplprojbtn").attr("disabled","disabled");
}
else{
$("#projectnamecontainer").addClass("has-success").removeClass("has-error");
$("#validateindicator").addClass("glyphicon-ok").removeClass("glyphicon-remove");
$("#advprojbtn").removeAttr("disabled");
$("#smplprojbtn").removeAttr("disabled");
}
})
.focus();
};
/**
* Load theme to apply all aplication. This function look for css/js folders and load all find.
*/
UI.prototype.loadTheme = function loadTheme(){
var fs = require('fs');
var path = require('path');
Cloudbook.UI.themeeditorpath = path.join('themes','editor','default');
var cssbasepath = path.join(Cloudbook.UI.themeeditorpath,'css');
if(fs.existsSync(cssbasepath)){
fs.readdirSync(cssbasepath).forEach(function(csspath){
var css = document.createElement('link');
css.rel = 'stylesheet';
css.href = path.join(cssbasepath,csspath);
document.head.appendChild(css);
});
}
var scriptsbasepath = path.join(Cloudbook.UI.themeeditorpath,'js');
if(fs.existsSync(scriptsbasepath)){
fs.readdirSync(scriptsbasepath).forEach(function(jspath){
CBUtil.include(path.join(scriptsbasepath,jspath))
});
}
}
/**
* Create components buttons to append elements into selected section.
* Here method call editorView and add_callback methods of CBObjects.
* See
* {@link CBObject#editorView} and
* {@link CBObject.add_callback}
*/
UI.prototype.renderActionsButtons = function renderActionsButtons(){
var that = this;
var backend = application.backend.getInstance();
var path = require('path');
Object.keys(Cloudbook.Actions).forEach(function (component) {
var componentpath = Cloudbook.Actions[component]['path'];
var description = require("./" + path.join(componentpath,"metadata.json"));
backend.loadComponentExtraCss(componentpath,description);
$(Cloudbook.UI.navactions).append($(document.createElement('button'))
.bind('click', function () {that.getCBObjectFromButton(component)})
.addClass('btn').addClass('btn-default')
.html(that.calculeButtonContent(componentpath, description)));
});
}
/**
* Create element from component. This include cbobject and rendered view on targetcontent.
* When append rendered view on targetcontent then trigger add_callback function related with component
* @param {String} component Component idtype indicated on metadata file.
*/
UI.prototype.getCBObjectFromButton = function getCBObjectFromButton(component) {
var CBStorage = application.storagemanager.getInstance();
var fullobject = new Cloudbook.Actions[component]['component']();
var viewobject = $(fullobject.editorView());
$(Cloudbook.UI.targetcontent).append(viewobject);
fullobject.add_callback(viewobject,fullobject);
var sectionWhereAppend = CBStorage.getSectionById(Cloudbook.UI.selected.attr('data-cbsectionid'));
sectionWhereAppend.content.push(fullobject);
};
/**
* On component metadata file may be field "icon" and "label". This fields are used to create action component button.
* When user click this button, on targetcontent to been added an element.
* @param {String} pluginpath relative path to root component
* @param {Object} infobutton JSON created from metadata file.
* @param {String} infobutton.icon relative icon path
* @param {String} infobutton.label Label button.
* @result {String} Html code to be included on button tag
*/
UI.prototype.calculeButtonContent = function calculeButtonContent(pluginpath, infobutton) {
var result = "";
var fs = require('fs');
var path = require('path');
if (infobutton.hasOwnProperty('icon')) {
var iconpath = path.join(pluginpath,infobutton.icon);
if (fs.existsSync(iconpath)) {
result = '<img src="' + iconpath + '" />';
}
}
if (infobutton.hasOwnProperty('label')) {
result += "<div>"+infobutton.label+"</div>";
}
return result;
};
UI.prototype.initSectionsPro = function initSectionsPro() {
var backend = application.backend.getInstance();
var cbsecid = backend.initSections();
var son = this.createSectionProView(cbsecid);
var list = $(document.createElement('ul')).addClass("connectedSortable");
list.append(son);
$(Cloudbook.UI.navsections).html(list).attr('data-cbsectionid','1');
$($(son.children('.displaysection')).children('.divselector')).click();
this.reloadSortable();
};
UI.prototype.reloadSortable = function reloadSortable(element){
var that = this;
var backend = application.backend.getInstance();
$(".connectedSortable").sortable({
placeholder: "ui-state-highlight",
opacity:0.5,
axis:"y",
start:function(ev,ui){that.oldparent = ui.item.parent().parent().attr('data-cbsectionid');},
stop:function(ev,ui){
that.newparent = ui.item.parent().parent().attr('data-cbsectionid');
if (that.oldparent !== that.newparent ){
listoldparent = $("[data-cbsectionid=" + that.oldparent + "] > ul > li").map(function(element){return this.dataset.cbsectionid});
listnewparent = $("[data-cbsectionid=" + that.newparent + "] > ul > li").map(function(element){return this.dataset.cbsectionid});
backend.regenerateSubsection(that.oldparent,listoldparent.toArray());
backend.regenerateSubsection(that.newparent,listnewparent.toArray());
}
},
connectWith:".connectedSortable"}).disableSelection();
}
UI.prototype.createSectionProView = function createSectionProView(cbsecid) {
var section = $(document.createElement('li')).addClass('cbsection');
var CBStorage = application.storagemanager.getInstance();
section.attr('data-cbsectionid',cbsecid);
var displaysection = $(document.createElement('div')).addClass('displaysection');
var textsection = $(document.createElement('div')).addClass('divselector');
var actions = $(document.createElement('button')).html('+').attr('data-toggle','dropdown').attr('id',cbsecid);
var subsections = $(document.createElement('ul')).addClass('subsections').addClass("connectedSortable");
textsection.append($(document.createElement('div')).html(CBStorage.getSectionById(cbsecid).name).addClass('caption'));
textsection.click({that:this},this.selectSection);
actions.click({that:this},this.createMenu);
displaysection.append([textsection,actions]);
section.append([displaysection,subsections]);
return section ;
};
UI.prototype.createMenu = function createMenu(e) {
var that = e.data.that;
var element = $(e.currentTarget);
element.contextMenu([
{
name: CBI18n.gettext('Insert before'),
fun:function(){that.appendBefore(e)}
},
{
name:CBI18n.gettext('Insert after'),
fun:function(){that.appendAfter(e)}
},
{
name:CBI18n.gettext('Insert subsection'),
fun:function(){that.appendSubsection(e)}
},
{
name:CBI18n.gettext('Delete'),
fun: function(){
that.dialogDeleteSection($(element).closest('[data-cbsectionid]').attr('data-cbsectionid'));
}
},
{
name:CBI18n.gettext('Edit'),
fun: function(){
that.dialogUpdateSectionName($(element).closest('[data-cbsectionid]').attr('data-cbsectionid'));
}
}]);
element.trigger('click.contextMenu',[e]);
};
UI.prototype.createSectionPageView = function createSectionPageView(cbsecid) {
var section = $(document.createElement('li')).addClass('cbsection');
section.attr('data-cbsectionid',cbsecid);
var thumbnail = $(document.createElement('div')).addClass('displaysection');
var appendbefore = $(document.createElement('div')).addClass('appendbefore');
var sectionimage = $(document.createElement('div')).addClass('divselector');
var appendsubsection = $(document.createElement('div')).addClass('appendsubsection');
var appendafter = $(document.createElement('div')).addClass('appendafter');
var subsections = $(document.createElement('ul')).addClass('subsections').addClass("connectedSortable");
appendbefore.append($(document.createElement('img')).attr('src',Cloudbook.UI.themeeditorpath+"/img/add.png"));
appendsubsection.append($(document.createElement('img')).attr('src',Cloudbook.UI.themeeditorpath+"/img/subsection.png"));
appendafter.append($(document.createElement('img')).attr('src',Cloudbook.UI.themeeditorpath+"/img/add.png"));
sectionimage.append($(document.createElement('img')).attr('src',Cloudbook.UI.themeeditorpath+"/img/white.png"));
appendbefore.click({that:this},this.appendBefore);
appendsubsection.click({that:this},this.appendSubsection);
appendafter.click({that:this},this.appendAfter);
sectionimage.click({that:this},this.selectSection);
thumbnail.append([appendbefore,sectionimage,appendsubsection,appendafter]);
section.append([thumbnail,subsections]);
return section ;
};
UI.prototype.appendBefore = function appendBefore(e){
var CBStorage = application.storagemanager.getInstance();
var that = e.data.that;
var listparents = $(e.currentTarget).parents('.cbsection');
var backend = application.backend.getInstance();
var parent = null;
if (listparents.length <2){
parent = "1";
}
else{
parent = $(listparents[1]).attr('data-cbsectionid');
}
var cbsecid = backend.appendNewSectionObjectByUID(parent,'basic');
var son = that.createSectionProView(cbsecid);
$(listparents[0]).before(son);
that.reloadSortable();
that.dialogUpdateSectionName(cbsecid);
}
UI.prototype.appendSubsection = function appendSubsection(e){
var that = e.data.that;
var CBStorage = application.storagemanager.getInstance();
var parent = $(e.currentTarget).parents('.cbsection');
var backend = application.backend.getInstance();
var parentObjectSection = $(parent[0]).attr('data-cbsectionid');
var cbsecid = backend.appendNewSectionObjectByUID(parentObjectSection,'basic');
var newsection = that.createSectionProView(cbsecid);
$(parent[0]).children("ul").append(newsection);
that.reloadSortable();
that.dialogUpdateSectionName(cbsecid);
}
UI.prototype.appendAfter = function appendAfter(e){
var that = e.data.that;
var CBStorage = application.storagemanager.getInstance();
var backend = application.backend.getInstance();
var listparents = $(e.currentTarget).parents('.cbsection');
var parentObjectSection = null;
if (listparents.length <2){
parentObjectSection = "1";
}
else{
parentObjectSection = $(listparents[1]).attr('data-cbsectionid');
}
var cbsecid = backend.appendNewSectionObjectByUID(parentObjectSection,'basic');
var son = that.createSectionProView(cbsecid);
$(listparents[0]).after(son);
that.reloadSortable();
that.dialogUpdateSectionName(cbsecid);
}
UI.prototype.selectSection = function selectSection(e){
var that = e.data.that;
if (Cloudbook.UI.selected !== undefined){
$(Cloudbook.UI.selected.children('.displaysection')).removeClass('sectionselected');
}
Cloudbook.UI.selected = $($(this).parents('.cbsection')[0]);
Cloudbook.UI.selected.children('.displaysection').addClass('sectionselected');
that.loadContent(Cloudbook.UI.selected.attr('data-cbsectionid'));
}
UI.prototype.loadContent = function loadContent(id){
var CBStorage = application.storagemanager.getInstance();
$(Cloudbook.UI.targetcontent).html("");
var section = CBStorage.getSectionById(id);
if (section !== undefined ){
section.content.forEach(function (element){
var x = element.editorView();
$(Cloudbook.UI.targetcontent).append(x);
element.add_callback(x,element);
});
}
}
UI.prototype.updateSectionName = function(name,cbsectionid) {
$("li[data-cbsectionid='"+cbsectionid+"'] > div.displaysection > div.divselector").html("<div>"+name+"</div>");
};
UI.prototype.dialogUpdateSectionName = function dialogUpdateSectionName(cbsectionid) {
var controller = application.controller.getInstance();
var template = application.util.template.getTemplate('templates/updateSectionName.hbs');
var dialog = $(template());
dialog.find('button').click(function(){
var name = $('#sectionname').val();
controller.updateSectionName(name,cbsectionid);
dialog.dialog('close');
dialog.remove();
});
dialog.dialog({modal:true,dialogClass: "no-close",closeOnEscape: false});
}
UI.prototype.deleteSection = function deleteSection(cbsectionid) {
$('[data-cbsectionid="'+cbsectionid+'"]').remove();
};
UI.prototype.dialogDeleteSection = function dialogDeleteSection(cbsectionid) {
var controller = application.controller.getInstance();
controller.deleteSection(cbsectionid);
};
UI.prototype.launcherloadProject = function launcherloadProject(e) {
var that = e.data.that;
var element = e.currentTarget;
var path = element.dataset.path;
var controller = application.controller.getInstance();
controller.loadProject(path + "/project.cloudbook");
};
UI.prototype.loadProject = function loadProject(path) {
console.log(path);
};
/**
* This namespace has singleton instance of UI class
* @namespace ui
* @memberOf application
*/
CBUtil.createNameSpace('application.ui');
application.ui = CBUtil.singleton(UI);
</code></pre>
</article>
</section>
</div>
<nav>
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Backend.html">Backend</a></li><li><a href="CBObject.html">CBObject</a></li><li><a href="CBSection.html">CBSection</a></li><li><a href="ConfigUserManager.html">ConfigUserManager</a></li><li><a href="Controller.html">Controller</a></li><li><a href="StorageManager.html">StorageManager</a></li><li><a href="TextBox.html">TextBox</a></li><li><a href="Translator.html">Translator</a></li><li><a href="UI.html">UI</a></li><li><a href="Util.html">Util</a></li></ul><h3>Namespaces</h3><ul><li><a href="application.html">application</a></li><li><a href="application.backend.html">backend</a></li><li><a href="application.controller.html">controller</a></li><li><a href="application.storagemanager.html">storagemanager</a></li><li><a href="application.ui.html">ui</a></li><li><a href="Cloudbook.html">Cloudbook</a></li><li><a href="Cloudbook.Actions.html">Actions</a></li><li><a href="Cloudbook.Sections.html">Sections</a></li><li><a href="Cloudbook.UI.html">UI</a></li><li><a href="Project.html">Project</a></li><li><a href="Project.Data.html">Data</a></li><li><a href="Project.Info.html">Info</a></li></ul><h3>Global</h3><ul><li><a href="global.html#getInstance">getInstance</a></li></ul>
</nav>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.0-beta3</a> on Tue Mar 24 2015 12:37:37 GMT+0100 (CET)
</footer>
<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>