Commit 54af62b4 authored by Thibaut Frain's avatar Thibaut Frain Committed by Jérome Perrin

Optimize toolbox building (in memory)

parent d494c6b4
...@@ -31,6 +31,12 @@ ...@@ -31,6 +31,12 @@
}) })
.push(function (result_list) { .push(function (result_list) {
return result_list[1].render(result_list[0]); return result_list[1].render(result_list[0]);
})
.push(function () {
return gadget.getDeclaredGadget("productionline_toolbox");
})
.push(function (toolbox_gadget) {
toolbox_gadget.render();
}); });
}) })
......
...@@ -9,12 +9,19 @@ ...@@ -9,12 +9,19 @@
<script src="../<%= curl.jqueryuijs.relative_dest %>"></script> <script src="../<%= curl.jqueryuijs.relative_dest %>"></script>
<script src="../<%= copy.rsvp.relative_dest %>"></script> <script src="../<%= copy.rsvp.relative_dest %>"></script>
<script src="../<%= copy.renderjs.relative_dest %>"></script> <script src="../<%= copy.renderjs.relative_dest %>"></script>
<script src="../<%= copy.handlebars.relative_dest%>"></script>
<script id="tool-template" type="text/x-handlebars-template">
<div id="{{key}}"
class="tool {{key}}">
{{name}}
<ul/>
</div>
</script>
<script src="toolbox.js"></script> <script src="toolbox.js"></script>
</head> </head>
<body> <body>
<div id="tools"> <div class="tools"></div>
<div id="tools-container"></div>
</div>
</body> </body>
</html> </html>
#tools { .tools {
border: 1px solid #999; border: 1px solid #999;
margin: 20px 0; margin: 20px 0;
border-radius: 10px; border-radius: 10px;
padding-bottom: 20px; padding-bottom: 20px;
} }
#tools-container { .tools-container {
margin-bottom: 4px; margin-bottom: 4px;
} }
#tools .ui-button { .tools .ui-button {
margin:4px 0; margin:4px 0;
} }
......
/*global window, RSVP, $, rJS*/ /*global window, document, RSVP, rJS, Handlebars*/
(function (window, RSVP, $, rJS) { (function (window, document, RSVP, rJS, Handlebars) {
"use strict"; "use strict";
rJS(window) /*jslint nomen: true*/
var gadget_klass = rJS(window),
tool_template_source = gadget_klass.__template_element
.getElementById('tool-template').innerHTML,
tool_template = Handlebars.compile(tool_template_source);
gadget_klass
.declareAcquiredMethod("getConfigurationDict", "getConfigurationDict") .declareAcquiredMethod("getConfigurationDict", "getConfigurationDict")
.declareMethod("startService", function () { .declareMethod("render", function () {
var g = this; var g = this;
return RSVP.all([ return new RSVP.Queue()
g.getElement(), .push(function () {
g.getConfigurationDict() return g.getConfigurationDict();
]) })
.then(function (result) { .push(function (config) {
var render_element = $(result[0]).find("#tools-container"); g.tools_container = document.createElement('div');
$.each(result[1], function (key, val) { g.tools_container.className = 'tools-container';
var name = val.name || key.split('-')[1]; Object.keys(config).forEach(function (key) {
var name = config[key].name || key.split('-')[1];
if (key !== 'Dream-Configuration') { if (key !== 'Dream-Configuration') {
render_element.append('<div id="' + key + '" class="tool ' + g.tools_container.innerHTML += tool_template({
key + '">' + key: key,
name + "<ul/></div>"); name: name
});
} }
}); });
}); });
})
.declareMethod('startService', function () {
var g = this;
return g.getElement().then(function (element) {
element.querySelector('.tools')
.appendChild(g.tools_container);
});
}); });
}(window, RSVP, $, rJS));
}(window, document, RSVP, rJS, Handlebars));
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment