function onTemplateLoadedCallback(app) { /* $("button[role=addObject]").click(function() { createObject(app); }); */ } function reloadApp(app) { $("#objects").empty(); var count = parseInt(app.parameters.value("count")); for(var i=0 ; idiv:last"); var left = 0; var top = 0; if(last.size() > 0) { left = parseInt((last.css("left") || "0").replace("px","")) + 10; top = parseInt((last.css("top") || "0").replace("px","")); var count = last.parent().find(">div").size(); log(last.parent().width() +"-"+ (left+last.width() * count)); if(last.parent().width() <= (left+last.width() * count)){ left = -last.width() * count; top += last.height() + 10; } } objectForGUID(app, id, {left: left, top: top}); //TODO Duplication : Recupérer les images du dupliqué } function objectForGUID(app, guid, position) { window.object = guid; var objectUi = $(Mustache.render(objectTemplate, window)); objectUi.css("left", position.left); objectUi.css("top", position.top); objectUi.draggable({ containment: "#scene", scroll: false, revert: app.onEdit ? false : "invalid" }); $("#objects").append(objectUi); if(app.onEdit) { objectUi.bind("dragstop", function(event, ui){ var id = ui.helper.attr("id"); log(id); var left = ui.position.left ; var top = ui.position.top; log(left+"-"+top); setPositionFor(app.parameters, id, ui.position); }); objectUi.find("button[role=remove]").click(function(){ removeObjectWithId(app, guid); objectUi.remove(); }); objectUi.find("button[role=duplicate]").click(function(){ createObject(app, guid); }); } } function getPositionFor(parameters, id) { var left = parameters.value("Object#"+id+"left"); var top = parameters.value("Object#"+id+"top"); if(left === undefined) left = 0; if(top === undefined) top = 0; return {left: parseInt(left), top: parseInt(top)}; } function setPositionFor(parameters, id, position) { parameters.value("Object#"+id+"left", position.left); parameters.value("Object#"+id+"top", position.top); } */ function reloadCallback(parameter) { reloadApp(this); } $(document).ready(function(){ var callbacks = { onTemplatesLoaded: onTemplateLoadedCallback, onEdit: reloadApp, onView: reloadApp }; init(reloadCallback, {toolbar: toolbarTemplate, parameters: parametersTemplate}, callbacks); });