Commit 47365bf9 authored by Marcel Rieger's avatar Marcel Rieger
Browse files

Fix template and ajax calls across platform.

parent c4143d3a
......@@ -434,8 +434,7 @@ define(["jquery", "vispa/module", "vispa/view"], function($, VispaModule, VispaV
// manipulators cannot be created via the rendering process, so we do this in callbacks
// that are fired, when the rendering is done
var callbacks = $.Callbacks();
var dfds = [];
var tasks = [];
// get a list of all sections
var sections = vispa.preferences.sectionOrder;
......@@ -501,9 +500,8 @@ define(["jquery", "vispa/module", "vispa/view"], function($, VispaModule, VispaV
__renderObj["lvl3-element"]["lvl3-content"] = manipulatorId;
// add the manipulator via a callback
callbacks.add(function() {
var dfd = self.createManipulator(section, name, entry, manipulatorId);
dfds.push(dfd);
tasks.push(function(callback) {
self.createManipulator(section, name, entry, manipulatorId, callback);
});
_renderObj["lvl2-element"]["lvl3-list"].push(__renderObj);
......@@ -555,11 +553,8 @@ define(["jquery", "vispa/module", "vispa/view"], function($, VispaModule, VispaV
contentFlag = true;
content.render(renderData, directives);
// fire the callbacks that insert the manipulators
callbacks.fire();
// the dfds are resolved when all callbacks are fired
$.when.apply($, dfds).done(function() {
// process the tasks to insert the manipulators
async.parallel(tasks, function(err) {
content.scrollspy({
target: "#" + navId,
offset: 50
......@@ -571,7 +566,7 @@ define(["jquery", "vispa/module", "vispa/view"], function($, VispaModule, VispaV
return this;
},
createManipulator: function(section, name, entry, manipulatorId) {
createManipulator: function(section, name, entry, manipulatorId, callback) {
var self = this;
var target = $("#" + manipulatorId);
......@@ -586,87 +581,92 @@ define(["jquery", "vispa/module", "vispa/view"], function($, VispaModule, VispaV
var type = defaults.type || "string";
var data = {
target: target,
observable: observable,
section: section,
name: name,
entry: entry,
defaults: defaults,
value: observable.preferences[entry],
target : target,
observable : observable,
section : section,
name : name,
entry : entry,
defaults : defaults,
value : observable.preferences[entry],
defaultValue: defaults.value,
type: type,
description: defaults.desc || defaults.descr || defaults.description,
settings: observable.settings
type : type,
description : defaults.desc || defaults.descr || defaults.description,
settings : observable.settings
};
switch (type.toLowerCase()) {
case "s":
case "str":
case "string":
return this.createStringManipulator(data);
return this.createStringManipulator(data, callback);
case "i":
case "int":
case "integer":
return this.createIntegerManipulator(data);
return this.createIntegerManipulator(data, callback);
case "f":
case "float":
return this.createFloatManipulator(data);
return this.createFloatManipulator(data, callback);
case "b":
case "bool":
case "boolean":
return this.createBooleanManipulator(data);
return this.createBooleanManipulator(data, callback);
case "l":
case "list":
return this.createListManipulator(data);
return this.createListManipulator(data, callback);
case "o":
case "obj":
case "object":
return this.createObjectManipulator(data);
return this.createObjectManipulator(data, callback);
default:
return null;
}
},
createStringManipulator: function(data) {
createStringManipulator: function(data, callback) {
// selection?
if (data.defaults.selection && data.defaults.selection.length)
return this.createSelectionManipulator(data);
else
return this.createSimpleManipulator(data);
if (data.defaults.selection && data.defaults.selection.length) {
return this.createSelectionManipulator(data, callback);
} else {
return this.createSimpleManipulator(data, callback);
}
},
createIntegerManipulator: function(data) {
createIntegerManipulator: function(data, callback) {
// same as float
return this.createFloatManipulator(data);
return this.createFloatManipulator(data, callback);
},
createFloatManipulator: function(data) {
createFloatManipulator: function(data, callback) {
// selection?
if (data.defaults.selection && data.defaults.selection.length)
return this.createSelectionManipulator(data);
return this.createSelectionManipulator(data, callback);
// range?
else if (data.defaults.range && ~[2, 3].indexOf(data.defaults.range.length))
return this.createRangeManipulator(data);
return this.createRangeManipulator(data, callback);
else
return this.createSimpleManipulator(data);
return this.createSimpleManipulator(data, callback);
},
createBooleanManipulator: function(data) {
createBooleanManipulator: function(data, callback) {
var self = this;
this.setLoading(true);
var path = "html/index/preferenceview/boolean_manipulator.html";
var dfd = vispa.getTemplate(path, function(err, tmpl) {
if (err) {
return callback(err);
}
// markup
var manipulator = $(tmpl).appendTo(data.target)
.render(data, {
type: {
text: function() {
return vispa.preferences.parseType(this.type);
}
.render(data, {
type: {
text: function() {
return vispa.preferences.parseType(this.type);
}
});
}
});
// methods
manipulator.setValue = function(value) {
......@@ -716,26 +716,37 @@ define(["jquery", "vispa/module", "vispa/view"], function($, VispaModule, VispaV
});
self.setLoading(false);
callback(null);
});
return dfd;
return this;
},
createListManipulator: function(data) {
return this.createSimpleManipulator(data, true);
createListManipulator: function(data, callback) {
return this.createSimpleManipulator(data, true, callback);
},
createObjectManipulator: function(data) {
return this.createSimpleManipulator(data, true);
createObjectManipulator: function(data, callback) {
return this.createSimpleManipulator(data, true, callback);
},
createSimpleManipulator: function(data, stringify) {
createSimpleManipulator: function(data, stringify, callback) {
var self = this;
if (callback === undefined) {
callback = stringify;
stringify = false;
}
this.setLoading(true);
var path = "html/index/preferenceview/simple_manipulator.html";
var dfd = vispa.getTemplate(path, function(err, tmpl) {
vispa.getTemplate(path, function(err, tmpl) {
if (err) {
return callback(err);
}
// markup
var manipulator = $(tmpl).appendTo(data.target)
.render(data, {
......@@ -822,18 +833,24 @@ define(["jquery", "vispa/module", "vispa/view"], function($, VispaModule, VispaV
});
self.setLoading(false);
callback(null);
});
return dfd;
return this;
},
createSelectionManipulator: function(data) {
createSelectionManipulator: function(data, callback) {
var self = this;
this.setLoading(true);
var path = "html/index/preferenceview/selection_manipulator.html";
var dfd = vispa.getTemplate(path, function(err, tmpl) {
vispa.getTemplate(path, function(err, tmpl) {
if (err) {
return callback(err);
}
// markup
var manipulator = $(tmpl).appendTo(data.target)
.render(data, {
......@@ -905,18 +922,24 @@ define(["jquery", "vispa/module", "vispa/view"], function($, VispaModule, VispaV
});
self.setLoading(false);
callback(null);
});
return dfd;
return this;
},
createRangeManipulator: function(data) {
createRangeManipulator: function(data, callback) {
var self = this;
this.setLoading(true);
var path = "html/index/preferenceview/range_manipulator.html";
var dfd = vispa.getTemplate(path, function(err, tmpl) {
vispa.getTemplate(path, function(err, tmpl) {
if (err) {
return callback(err);
}
// markup
var manipulator = $(tmpl).appendTo(data.target)
.render(data, {
......@@ -1034,9 +1057,11 @@ define(["jquery", "vispa/module", "vispa/view"], function($, VispaModule, VispaV
});
self.setLoading(false);
callback(null);
});
return dfd;
return this;
}
});
......
......@@ -44,9 +44,16 @@ define([ "jquery", "emitter", "vispa/module", "vispa/ui"], function($, Emitter,
if (this.loaded())
return this;
var dfd1 = vispa.getTemplate("html/index/navbutton.html", function(err, template) {
self.nodes.button = $(template)
.render({label: self.label}, {
var tasks = [];
tasks.push(function(callback) {
vispa.getTemplate("html/index/navbutton.html", function(err, tmpl) {
if (err) {
return callback(err);
}
self.nodes.button = $(tmpl)
.render({ label: self.label }, {
icon: {
class: function() {
return "glyphicon glyphicon-cog";
......@@ -56,38 +63,48 @@ define([ "jquery", "emitter", "vispa/module", "vispa/ui"], function($, Emitter,
event.preventDefault();
self.focus();
});
$(".link-close", self.nodes.button).click(function(event) {
event.preventDefault();
event.stopPropagation();
self.close();
$(".link-close", self.nodes.button).click(function(event) {
event.preventDefault();
event.stopPropagation();
self.close();
});
callback(null);
});
});
var dfd2 = $.Deferred();
vispa.getTemplate("html/index/view.html", function(err, template) {
self.nodes.wrapper = $(template)
.render({}, {
"loader-img": {
tasks.push(function(callback) {
vispa.getTemplate("html/index/view.html", function(err, tmpl) {
if (err) {
return callback(err);
}
self.nodes.wrapper = $(tmpl).render({}, {
"loader-img": {
src: function() {
return vispa.url.static("img/maingui/loader6.gif");
}
}
});
self.nodes.loader = $(".vispa-modal", self.nodes.wrapper).first();
if (self.templatePath)
vispa.getTemplate(self.templatePath, function(err, template) {
self.nodes.content = $(template).appendTo(self.nodes.wrapper);
dfd2.resolve();
});
else {
self.nodes.content = $("<div>").appendTo(self.nodes.wrapper);
dfd2.resolve();
}
self.nodes.loader = $(".vispa-modal", self.nodes.wrapper).first();
if (self.templatePath) {
vispa.getTemplate(self.templatePath, function(err, tmpl) {
if (err) {
return callback(null);
}
self.nodes.content = $(tmpl).appendTo(self.nodes.wrapper);
callback(null);
});
} else {
self.nodes.content = $("<div>").appendTo(self.nodes.wrapper);
callback(null);
}
});
});
$.when(dfd1, dfd2).done(function() {
if ($.isFunction(callback))
callback();
async.parallel(tasks, function(err) {
vispa.applyFirst(null, [err], callback);
});
return this;
......
<
......@@ -38,7 +38,7 @@ define([ "jquery", "vispa/extensions" ], function($, Ext) {
var nodes = {};
// menu filler callback
var fillMenu = function(menu, dropdown) {
var fillMenu = function(menu, dropdown) {
var _fillMenu = function() {
// close event
$("#close", menu).click(function(event) {
......@@ -103,176 +103,188 @@ define([ "jquery", "vispa/extensions" ], function($, Ext) {
});
};
// get all templates, then call _fillMenu
vispa.getTemplate("html/index/menuentry.html", function(err, menuEntryTmpl) {
if (err)
return;
vispa.getTemplate("html/index/submenu.html", function(err, submenuTmpl) {
if (err)
return;
self._tmpl.menuEntryTmpl = menuEntryTmpl;
self._tmpl.submenuTmpl = submenuTmpl;
_fillMenu();
});
var tasks = ["menuentry.html", "submenu.html"].forEach(function(path) {
return function(callback) {
vispa.getTemplate("html/index/" + path, callback);
};
});
async.parallel(tasks, function(err, results) {
self._tmpl.menuEntryTmpl = results[0];
self._tmpl.submenuTmpl = results[1];
_fillMenu();
});
};
// content
var path = "html/index/centerview/content.html";
var dfd1 = vispa.getTemplate(path, function(err, tmpl) {
nodes.contentWrapper = $(tmpl)
.render({}, {
"loader-img": {
src: function() {
return vispa.url.static("img/maingui/loader6.gif");
}
}
});
nodes.modal = $(".vispa-modal", nodes.contentWrapper).first();
nodes.content = $(".vispa-centerview-content", nodes.contentWrapper);
nodes.fastMenu = $(".vispa-fastmenu", nodes.contentWrapper);
nodes.fastMenuButton = $(".vispa-centerview-tabs-menu-button a:first", nodes.contentWrapper);
nodes.fastMenuDropdown = $(".vispa-centerview-tabs-menu-button ul", nodes.contentWrapper);
// add the view name as a class to nodes.content
nodes.content.addClass(self.getName());
// fastmenu tab button
$(".vispa-centerview-tabs-menu-button", nodes.contentWrapper).click(function(event) {
if (!self.isLoading()) {
nodes.fastMenuButton.dropdown("toggle");
var tasks = [];
// task 1: content
tasks.push(function(callback) {
vispa.getTemplate("html/index/centerview/content.html", function(err, tmpl) {
if (err) {
return callback(err);
}
event.stopPropagation();
});
// fill this menu aswell
fillMenu(nodes.fastMenuDropdown, nodes.fastMenuButton);
// the fast menu becomes droppable and sortable
var deletable = function(event) {
// height(header + tabs) = 90
var offset = 90;
return event.clientY > 2.5 * offset;
}
nodes.fastMenu.droppable({
accept: function(node) {
if (!node.hasClass("draggable-fastmenu-" + self.getId()))
return false;
var entries = self.getPreference("fastMenuEntries");
return !~entries.indexOf(node.data("entry"));
},
activeClass: "highlight",
hoverClass: "accept",
drop: function(event, ui) {
self._addFastMenuEntry(ui.draggable.data("entry"));
nodes.contentWrapper = $(tmpl)
.render({}, {
"loader-img": {
src: function() {
return vispa.url.static("img/maingui/loader6.gif");
}
}
});
nodes.modal = $(".vispa-modal", nodes.contentWrapper).first();
nodes.content = $(".vispa-centerview-content", nodes.contentWrapper);
nodes.fastMenu = $(".vispa-fastmenu", nodes.contentWrapper);
nodes.fastMenuButton = $(".vispa-centerview-tabs-menu-button a:first", nodes.contentWrapper);
nodes.fastMenuDropdown = $(".vispa-centerview-tabs-menu-button ul", nodes.contentWrapper);
// add the view name as a class to nodes.content
nodes.content.addClass(self.getName());
// fastmenu tab button
$(".vispa-centerview-tabs-menu-button", nodes.contentWrapper).click(function(event) {
if (!self.isLoading()) {
nodes.fastMenuButton.dropdown("toggle");
}
event.stopPropagation();
});
// fill this menu aswell
fillMenu(nodes.fastMenuDropdown, nodes.fastMenuButton);
// the fast menu becomes droppable and sortable
var deletable = function(event) {
// height(header + tabs) = 90
var offset = 90;
return event.clientY > 2.5 * offset;
}
}).sortable({
axis: "x",
distance: 20,
cursor: "move",
forcePlaceholderSize: true,
sort: function(event, ui) {
ui.item
.toggleClass("deletable", deletable(event))
.toggleClass("keepable", !deletable(event));
},
stop: function(event, ui) {
if (deletable(event)) {
self._removeFastMenuEntry(ui.item.data("entryId"));
return;
nodes.fastMenu.droppable({
accept: function(node) {
if (!node.hasClass("draggable-fastmenu-" + self.getId()))
return false;
var entries = self.getPreference("fastMenuEntries");
return !~entries.indexOf(node.data("entry"));
},
activeClass: "highlight",
hoverClass: "accept",
drop: function(event, ui) {
self._addFastMenuEntry(ui.draggable.data("entry"));
}
}).sortable({
axis: "x",
distance: 20,
cursor: "move",
forcePlaceholderSize: true,
sort: function(event, ui) {
ui.item
.toggleClass("deletable", deletable(event))
.toggleClass("keepable", !deletable(event));
},
stop: function(event, ui) {
if (deletable(event)) {
self._removeFastMenuEntry(ui.item.data("entryId"));
return;
}
ui.item
.toggleClass("deletable", false)
.toggleClass("keepable", false);
ui.item.toggleClass("deletable", false).toggleClass("keepable", false);
// get the new order and snyc it with the config
// if there is more than one child
var children = nodes.fastMenu.children();
if (children.length < 2)
return;
// get the new order and snyc it with the config
// if there is more than one child
var children = nodes.fastMenu.children();
if (children.length < 2)
return;
var ids = self._preferences.fastMenuEntries;
ids.length = 0;
children.each(function(i, child) {
ids.push($(child).data("entryId"));
});
self.pushPreferences();
}
var ids = self._preferences.fastMenuEntries;
ids.length = 0;
children.each(function(i, child) {
ids.push($(child).data("entryId"));
});
self.pushPreferences();
}
});
callback(null);
});
});
// tab
path = "html/index/centerview/tab.html";
var dfd2 = vispa.getTemplate(path, function(err, tmpl) {
nodes.tab = $(tmpl)
.data("instanceId", self.getId());
nodes.tabIconWrapper = $(".vispa-centerview-tab-icon", nodes.tab);
nodes.tabIconButton = $("a.dropdown", nodes.tabIconWrapper);
nodes.tabIcon = $("a.dropdown > i", nodes.tabIconWrapper);
nodes.tabLabel = $(".vispa-centerview-tab-label", nodes.tab);
nodes.tabCrossWrapper = $(".vispa-centerview-tab-cross", nodes.tab);
nodes.tabCross = $("i", nodes.tabCrossWrapper);
nodes.tabMenu = $("ul", nodes.tabIconWrapper);
nodes.tabBadge = $(".vispa-centerview-tab-badge span.badge", nodes.tab);
// tooltip
nodes.tabLabel.tooltip({
title: "UNTITLED",
placement: "bottom",
delay: {