Commit a88c5183 authored by Ivan Tyagov's avatar Ivan Tyagov

Reorganize code.

User require.js to load dependencies.
Allow tabs to be switched using dynamic hashable routes.
parent 9cdeea19
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_body</string> </key>
<value> <string>from json import dumps\n
return dumps(d)\n
</string> </value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>d</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Base_asJSON</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="ZopePageTemplate" module="Products.PageTemplates.ZopePageTemplate"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_text</string> </key>
<value> <unicode>\074html\076\n
\074head\076\n
\074title tal:content="template/title"\076The title\074/title\076\n
\074meta http-equiv="content-type" content="text/html;charset=utf-8"\076\n
\074/head\076\n
\074body\076\n
\n
\074script type="text/javascript" language="javascript"\076\n
//\074![CDATA[\n
$(document).ready(function() {\n
gadget = RenderJs.getSelfGadget();\n
\n
// default tab should be openned fist\n
gadget.redirect = function () {\n
$.url.redirect(\'/\' + gadget.default_tab_url + \'/\');\n
};\n
\n
// default route\n
RenderJs.RouteGadget.add(\'\', gadget.redirect, 1);\n
\n
$.each(gadget.action_id_list, function(index, value) {\n
// add dynamic function to gadget that will take care to render tab using gadgets\n
gadget[value] = function () {\n
ERP5Form.openFormInTabbularGadget(gadget.tab_container_id, value);\n
};\n
//add dynamic route\n
RenderJs.RouteGadget.add(\'/\' + value + \'/\', gadget[value], 1);\n
});\n
});\n
//]]\076\n
\074/script\076\n
\n
\074/body\076\n
\074/html\076</unicode> </value>
</item>
<item>
<key> <string>content_type</string> </key>
<value> <string>text/html</string> </value>
</item>
<item>
<key> <string>expand</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>erp5_tabbular_form_renderer</string> </value>
</item>
<item>
<key> <string>output_encoding</string> </key>
<value> <string>utf-8</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <unicode></unicode> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -46,13 +46,18 @@
current_form_id python: request.get(\'current_form_id\', \'view\');\n
current_url python: \'%s/%s\' % (url, current_form_id);\n
current_action python: portal.ERP5Site_getCurrentAction(current_url, actions);\n
actions actions/object_view | python: [];">\n
actions actions/object_view | python: [];\n
action_id_list python:[x[\'url\'].split(\'/\')[-1] for x in actions];\n
data_gadget_property python: {\'tab_container_id\': \'form_gadget\',\n
\'default_tab_url\': action_id_list[0],\n
\'action_id_list\': action_id_list}">\n
\n
\n
<!-- XXX: use portal_status_message gadget -->\n
<div id="portal_status_message" style="height:20px; display:none;">\n
<p style="color:red; font-weight: bold;"></p>\n
</div>\n
\n
\n
<div class="document">\n
\n
<div class="actions">\n
......@@ -62,16 +67,10 @@
<span class="description">Save</span>\n
</button>\n
\n
<script type="text/javascript"\n
tal:content="python:\'\'\'ERP5Form.setCurrentFormId(\'%s\');;\n
RenderJs.TabbularGadget.addNewTabGadget(\n
\'form_gadget\',\n
\'gadget-%s\',\n
\'%s/Form_asRenderJSGadget\',\n
\'ERP5Form.update\',\n
\'Form_asJSON?form_id=%s\', false);;\n
\'\'\' %(current_form_id, current_form_id, current_form_id, current_form_id)">\n
</script>\n
<!-- Test -->\n
<div data-gadget="erp5_tabbular_form_renderer"\n
id="erp5_tabbular_form_renderer"\n
tal:attributes="data-gadget-property python: here.Base_asJSON(data_gadget_property);"> </div>\n
\n
<!-- get all tabs from server -->\n
<ul class="tabs">\n
......@@ -80,8 +79,7 @@
tal:define="action_form python: action[\'url\'].split(\'/\')[-1]"\n
tal:attributes="id action_form;\n
class python: action == current_action and \'selected\' or \'not_selected\'">\n
\n
<a tal:attributes="onclick python: \'\'\'javascript: ERP5Form.openFormInTabbularGadget(\'form_gadget\', \'%s\');; return false ;;\'\'\' %(action_form)">\n
<a tal:attributes="href python: \'view#/%s/\' %action_form">\n
<span i18n:translate=""\n
i18n:domain="ui"\n
tal:content="action/name">action_name</span>\n
......@@ -93,13 +91,13 @@
</div>\n
\n
<div class="content editable">\n
\n
\n
<!--Form rendered content goes here -->\n
<div id="form_gadget"></div>\n
\n
</div>\n
</div>\n
\n
\n
</div>
]]></unicode> </value>
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Folder" module="OFS.Folder"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_objects</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>lib</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="File" module="OFS.Image"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_EtagSupport__etag</string> </key>
<value> <string>ts62754937.18</string> </value>
</item>
<item>
<key> <string>__name__</string> </key>
<value> <string>require-erp5.js</string> </value>
</item>
<item>
<key> <string>content_type</string> </key>
<value> <string>application/javascript</string> </value>
</item>
<item>
<key> <string>data</string> </key>
<value> <string>// JavaScript file that is used to load ERP5\'s JavaScript depenencies\n
require.config({\n
paths: {\n
"erp5_form": "lib/erp5_form",\n
route: "lib/route",\n
url: "lib/url",\n
jquery: "jquery/core/jquery",\n
renderjs: "jquery/plugin/renderjs/renderjs",\n
"jquery-ui": "jquery/ui/js/jquery-ui.min",\n
"jquery.jqGrid.src": "jquery/plugin/jqgrid/jquery.jqGrid.src",\n
"grid.locale-en": "jquery/plugin/jqgrid/i18n/grid.locale-en"\n
},\n
shim: {\n
erp5: ["jquery"],\n
erp5_xhtml_appearance: ["erp5"],\n
erp5_knowledge_box: ["jquery", "jquery-ui"],\n
route: ["jquery"],\n
url: ["jquery"],\n
"jquery-ui": ["jquery"],\n
"jquery.jqGrid.src": ["jquery"],\n
"grid.locale-en": ["jquery.jqGrid.src"]\n
}\n
});\n
\n
require(["erp5_xhtml_appearance", "erp5_knowledge_box", "erp5", "erp5_form",\n
"renderjs", "jquery", "jquery-ui", "route", "url",\n
"jquery.jqGrid.src", "grid.locale-en"],\n
function(domReady) {\n
RenderJs.init();\n
RenderJs.bindReady(function (){\n
$.url.onhashchange(function () {\n
//console.log("go to route", $.url.getPath());\n
RenderJs.RouteGadget.go($.url.getPath(),\n
function () {\n
//console.log("bad route");\n
// All routes have been deleted by fail.\n
// So recreate the default routes using RouteGadget\n
RenderJs.RouteGadget.init();\n
});\n
});\n
});\n
});\n
</string> </value>
</item>
<item>
<key> <string>precondition</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>size</string> </key>
<value> <int>1474</int> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="File" module="OFS.Image"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_Cacheable__manager_id</string> </key>
<value> <string>http_cache</string> </value>
</item>
<item>
<key> <string>_EtagSupport__etag</string> </key>
<value> <string>ts62728561.31</string> </value>
</item>
<item>
<key> <string>__name__</string> </key>
<value> <string>route.js</string> </value>
</item>
<item>
<key> <string>content_type</string> </key>
<value> <string>application/javascript</string> </value>
</item>
<item>
<key> <string>data</string> </key>
<value> <string encoding="cdata"><![CDATA[
/*global window, jQuery */\n
/*!\n
* route.js v1.0.0\n
*\n
* Copyright 2012, Romain Courteaud\n
* Dual licensed under the MIT or GPL Version 2 licenses.\n
*\n
* Date: Mon Jul 16 2012\n
*/\n
"use strict";\n
(function (window, $) {\n
\n
$.extend({\n
StatelessDeferred: function () {\n
var doneList = $.Callbacks("memory"),\n
promise = {\n
done: doneList.add,\n
\n
// Get a promise for this deferred\n
// If obj is provided, the promise aspect is added to the object\n
promise: function (obj) {\n
var i,\n
keys = [\'done\', \'promise\'];\n
if (obj === undefined) {\n
obj = promise;\n
} else {\n
for (i = 0; i < keys.length; i += 1) {\n
obj[keys[i]] = promise[keys[i]];\n
}\n
}\n
return obj;\n
}\n
},\n
deferred = promise.promise({});\n
\n
deferred.resolveWith = doneList.fireWith;\n
\n
// All done!\n
return deferred;\n
}\n
});\n
\n
var routes = [],\n
current_priority = 0,\n
methods = {\n
add: function (pattern, priority) {\n
var i = 0,\n
inserted = false,\n
length = routes.length,\n
dfr = $.StatelessDeferred(),\n
context = $(this),\n
escapepattern,\n
matchingpattern;\n
\n
if (priority === undefined) {\n
priority = 0;\n
}\n
if (pattern !== undefined) {\n
\n
// http://simonwillison.net/2006/Jan/20/escape/\n
escapepattern = pattern.replace(/[\\-\\[\\]{}()*+?.,\\\\\\^$|#\\s]/g, "\\\\$&");\n
matchingpattern = escapepattern\n
.replace(/<int:\\w+>/g, "(\\\\d+)")\n
.replace(/<path:\\w+>/g, "(.+)")\n
.replace(/<\\w+>/g, "([^/]+)");\n
\n
while (!inserted) {\n
if ((i === length) || (priority >= routes[i][2])) {\n
routes.splice(i, 0, [new RegExp(\'^\' + matchingpattern + \'$\'), dfr, priority, context]);\n
inserted = true;\n
} else {\n
i += 1;\n
}\n
}\n
}\n
return dfr.promise();\n
},\n
go: function (path, min_priority) {\n
var dfr = $.Deferred(),\n
context = $(this),\n
result;\n
\n
if (min_priority === undefined) {\n
min_priority = 0;\n
}\n
setTimeout(function () {\n
var i = 0,\n
found = false,\n
slice_index = -1,\n
slice_priority = -1;\n
for (i = 0; i < routes.length; i += 1) {\n
if (slice_priority !== routes[i][2]) {\n
slice_priority = routes[i][2];\n
slice_index = i;\n
}\n
if (routes[i][2] < min_priority) {\n
break;\n
} else if (routes[i][0].test(path)) {\n
result = routes[i][0].exec(path);\n
dfr = routes[i][1];\n
context = routes[i][3];\n
current_priority = routes[i][2];\n
found = true;\n
break;\n
}\n
}\n
if (i === routes.length) {\n
slice_index = i;\n
}\n
if (slice_index > -1) {\n
routes = routes.slice(slice_index);\n
}\n
if (found) {\n
dfr.resolveWith(\n
context,\n
result.slice(1)\n
);\n
} else {\n
dfr.rejectWith(context);\n
}\n
});\n
return dfr.promise();\n
},\n
};\n
\n
\n
$.routereset = function () {\n
routes = [];\n
current_priority = 0;\n
};\n
\n
$.routepriority = function () {\n
return current_priority;\n
};\n
\n
$.fn.route = function (method) {\n
var result;\n
if (methods.hasOwnProperty(method)) {\n
result = methods[method].apply(\n
this,\n
Array.prototype.slice.call(arguments, 1)\n
);\n
} else {\n
$.error(\'Method \' + method +\n
\' does not exist on jQuery.route\');\n
}\n
return result;\n
};\n
\n
}(window, jQuery));\n
]]></string> </value>
</item>
<item>
<key> <string>precondition</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>size</string> </key>
<value> <int>3939</int> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>route.js</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="File" module="OFS.Image"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_Cacheable__manager_id</string> </key>
<value> <string>http_cache</string> </value>
</item>
<item>
<key> <string>_EtagSupport__etag</string> </key>
<value> <string>ts62728569.21</string> </value>
</item>
<item>
<key> <string>__name__</string> </key>
<value> <string>url.js</string> </value>
</item>
<item>
<key> <string>content_type</string> </key>
<value> <string>application/javascript</string> </value>
</item>
<item>
<key> <string>data</string> </key>
<value> <string encoding="cdata"><![CDATA[
/*!\n
* url.js v1.0.0\n
*\n
* Copyright 2012, Romain Courteaud\n
* Dual licensed under the MIT or GPL Version 2 licenses.\n
*\n
* Date: Mon Jul 16 2012\n
*/\n
"use strict";\n
(function (window, $) {\n
\n
var hashchangeinitialized = false,\n
previousurl,\n
currentcallback,\n
getRawHash = function () {\n
return window.location.toString().split(\'#\')[1];\n
},\n
callbackwrapper = function () {\n
if (previousurl !== window.location.hash) {\n
previousurl = window.location.hash;\n
if (currentcallback !== undefined) {\n
currentcallback();\n
}\n
}\n
},\n
timeoutwrapper = function () {\n
callbackwrapper();\n
window.setTimeout(timeoutwrapper, 500);\n
};\n
\n
function UrlHandler() {}\n
\n
UrlHandler.prototype = {\n
\'generateUrl\': function (path, options) {\n
var pathhash,\n
hash = \'#\',\n
key;\n
if (path !== undefined) {\n
hash += encodeURIComponent(path);\n
}\n
hash = hash.replace(/%2F/g, \'/\');\n
pathhash = hash;\n
for (key in options) {\n
if (options.hasOwnProperty(key)) {\n
if (hash === pathhash) {\n
hash = hash + \'?\';\n
} else {\n
hash = hash + \'&\';\n
}\n
hash += encodeURIComponent(key) +\n
\'=\' + encodeURIComponent(options[key]);\n
}\n
}\n
return hash;\n
},\n
\n
\'go\': function (path, options) {\n
window.location.hash = this.generateUrl(path, options);\n
},\n
\n
\'redirect\': function (path, options) {\n
var host = window.location.protocol + \'//\' +\n
window.location.host +\n
window.location.pathname +\n
window.location.search;\n
window.location.replace(host + this.generateUrl(path, options));\n
// window.location.replace(window.location.href.replace(/#.*/, ""));\n
},\n
\n
\'getPath\': function () {\n
var hash = getRawHash(),\n
result = \'\';\n
if (hash !== undefined) {\n
result = decodeURIComponent(hash.split(\'?\')[0]);\n
}\n
return result;\n
},\n
\n
\'getOptions\': function () {\n
var options = {},\n
hash = getRawHash(),\n
subhashes,\n
subhash,\n
index,\n
keyvalue;\n
if (hash !== undefined) {\n
hash = hash.split(\'?\')[1];\n
if (hash !== undefined) {\n
subhashes = hash.split(\'&\');\n
for (index in subhashes) {\n
if (subhashes.hasOwnProperty(index)) {\n
subhash = subhashes[index];\n
if (subhash !== \'\') {\n
keyvalue = subhash.split(\'=\');\n
if (keyvalue.length === 2) {\n
options[decodeURIComponent(keyvalue[0])] =\n
decodeURIComponent(keyvalue[1]);\n
}\n
}\n
}\n
}\n
}\n
}\n
return options;\n
},\n
\n
\'onhashchange\': function (callback) {\n
previousurl = undefined;\n
currentcallback = callback;\n
\n
if (!hashchangeinitialized) {\n
if (window.onhashchange !== undefined) {\n
$(window).bind(\'hashchange\', callbackwrapper);\n
window.setTimeout(callbackwrapper);\n
} else {\n
timeoutwrapper();\n
}\n
hashchangeinitialized = true;\n
}\n
},\n
};\n
\n
// Expose to the global object\n
$.url = new UrlHandler();\n
\n
}(window, jQuery));\n
]]></string> </value>
</item>
<item>
<key> <string>precondition</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>size</string> </key>
<value> <int>3293</int> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>url.js</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -57,6 +57,7 @@
</div>\n
</tal:block>\n
\n
<!-- XXX add portal_status_message gadget -->\n
<div tal:content="request/portal_status_message | nothing" id="transition_message"\n
class="transition_message"/>\n
\n
......
16
\ No newline at end of file
17
\ No newline at end of file
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