Commit 9295c722 authored by Xiaowu Zhang's avatar Xiaowu Zhang

Fix renderjs ui translation and can't save bugs

1. remove catch error in gadget_erp5.js and gadget_translate.js.
2. add acquisition method getTranslationMethod in main gadget.
3. add translaton_look key in configuration to define translation scipt.
4. fix can't save when edit.
parent 359743f1
......@@ -138,10 +138,6 @@
data-gadget-scope="jio_gadget"\n
data-gadget-sandbox="public"></div>\n
\n
<div data-gadget-sandbox="public" \n
data-gadget-url="gadget_translate.html" \n
data-gadget-scope="translate"></div>\n
\n
<div data-gadget-url="gadget_erp5_header.html"\n
data-gadget-scope="header"\n
data-gadget-sandbox="public"></div>\n
......@@ -149,7 +145,7 @@
<div data-gadget-url="gadget_erp5_panel.html"\n
data-gadget-scope="panel"\n
data-gadget-sandbox="public"></div>\n
\n
\n
<article></article>\n
\n
</body>\n
......@@ -276,7 +272,7 @@
</item>
<item>
<key> <string>actor</string> </key>
<value> <string>super_sven</string> </value>
<value> <string>zope</string> </value>
</item>
<item>
<key> <string>comment</string> </key>
......@@ -290,7 +286,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>939.54300.9851.50329</string> </value>
<value> <string>940.10217.40519.44782</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -308,8 +304,8 @@
</tuple>
<state>
<tuple>
<float>1420034261.32</float>
<string>GMT</string>
<float>1420723516.81</float>
<string>UTC</string>
</tuple>
</state>
</object>
......
......@@ -209,6 +209,7 @@
// Init local properties\n
.ready(function (g) {\n
g.props = {\n
translation_lookup: "",\n
hateoas_url: "hateoas/",\n
action_view: "action_object_view",\n
default_view_reference: "view"\n
......@@ -224,7 +225,6 @@
.ready(function (g) {\n
return createJio(g);\n
})\n
\n
.ready(function (g) {\n
return g.getElement()\n
.push(function (element) {\n
......@@ -232,7 +232,6 @@
g.props.article = element.querySelector("article");\n
});\n
})\n
\n
.ready(function (g) {\n
return g.getDeclaredGadget("header")\n
.push(function (header_gadget) {\n
......@@ -242,14 +241,17 @@
$(element).trigger("create");\n
});\n
})\n
\n
/////////////////////////////////////////////////////////////////\n
// handle acquisition\n
/////////////////////////////////////////////////////////////////\n
.declareAcquiredMethod("pleaseRedirectMyHash", "pleaseRedirectMyHash")\n
\n
// bridge translation gadget\n
.allowPublicAcquisition("getTranslationMethod", function () {\n
return this.props.translation_lookup;\n
})\n
.allowPublicAcquisition("changeLanguage", function (param_list) {\n
if (this.setLanguage) {\n
return this.getDeclaredGadget("translate")\n
.push(function (translation_gadget) {\n
return translation_gadget.changeLanguage.apply(\n
......@@ -257,8 +259,10 @@
param_list\n
);\n
});\n
}\n
})\n
.allowPublicAcquisition("getLanguageList", function (param_list) {\n
if (this.setLanguage) {\n
return this.getDeclaredGadget("translate")\n
.push(function (translation_gadget) {\n
return translation_gadget.getLanguageList.apply(\n
......@@ -266,8 +270,11 @@
param_list\n
);\n
});\n
}\n
return JSON.stringify([]);\n
})\n
.allowPublicAcquisition("translateHtml", function (param_list) {\n
if (this.setLanguage) {\n
return this.getDeclaredGadget("translate")\n
.push(function (translation_gadget) {\n
return translation_gadget.translateHtml.apply(\n
......@@ -275,8 +282,9 @@
param_list\n
);\n
});\n
}\n
return param_list;\n
})\n
\n
// Bridge to jio gadget\n
.allowPublicAcquisition("jio_allDocs", function (param_list) {\n
return this.getDeclaredGadget("jio_gadget")\n
......@@ -338,7 +346,6 @@
})\n
\n
.allowPublicAcquisition("renderPageHeader", function (param_list) {\n
\n
// XXX Sven hack: number of _url determine padding for subheader on ui-content \n
function hasSubNavigation(my_param_dict) {\n
var i,\n
......@@ -369,12 +376,8 @@
// update the header once translations are available\n
.allowPublicAcquisition(\'notifyUpdate\', function () {\n
return this.getDeclaredGadget("header")\n
.push(\n
function (header_gadget) {\n
.push(function (header_gadget) {\n
return header_gadget.notifyUpdate();\n
},\n
function () {\n
return;\n
});\n
})\n
.allowPublicAcquisition(\'notifySubmitting\', function () {\n
......@@ -415,7 +418,7 @@
/////////////////////////////////////////////////////////////////\n
// declared methods\n
/////////////////////////////////////////////////////////////////\n
\n
\n
// XXX translate: called before ready(), so props is not available.\n
// Needed to lookup to retrieve HAL to fetch site module/runner languages \n
.declareMethod(\'getSiteRoot\', function () {\n
......@@ -424,13 +427,39 @@
\n
// Render the page\n
.declareMethod(\'configure\', function (options) {\n
var key;\n
var gadget = this,\n
elements,\n
div,\n
key;\n
for (key in options) {\n
if (options.hasOwnProperty(key)) {\n
this.props[key] = options[key];\n
if (key === "translation_lookup") {\n
gadget.setLanguage = true;\n
}\n
gadget.props[key] = options[key];\n
}\n
}\n
if (gadget.setLanguage) {\n
elements = gadget.props.element;\n
div = document.createElement("div");\n
elements.appendChild(div);\n
return new RSVP.Queue()\n
.push(function () {\n
return gadget.declareGadget("gadget_translate.html",\n
{scope: "translate"});\n
})\n
.push(function () {\n
return gadget.dropGadget("panel");\n
})\n
.push(function () {\n
return gadget.declareGadget("gadget_erp5_panel.html",\n
{scope: "panel",\n
element: div});\n
})\n
.push(function () {\n
return createJio(gadget);\n
});\n
}\n
return createJio(this);\n
})\n
\n
// Render the page\n
......@@ -493,9 +522,7 @@
.push(function (fragment) {\n
var element = gadget.props.article,\n
content_container = document.createElement("div");\n
\n
content_container.className = "ui-content " + (gadget.props.sub_header_class || "");\n
\n
// reset subheader indicator\n
delete gadget.props.sub_header_class;\n
\n
......@@ -662,7 +689,7 @@
</item>
<item>
<key> <string>actor</string> </key>
<value> <string>super_sven</string> </value>
<value> <string>zope</string> </value>
</item>
<item>
<key> <string>comment</string> </key>
......@@ -676,7 +703,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>940.1446.34871.22050</string> </value>
<value> <string>940.10219.33899.48998</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -694,8 +721,8 @@
</tuple>
<state>
<tuple>
<float>1420195841.19</float>
<string>GMT</string>
<float>1420722838.8</float>
<string>UTC</string>
</tuple>
</state>
</object>
......
......@@ -99,7 +99,9 @@
</item>
<item>
<key> <string>text_content</string> </key>
<value> <string>/*global window, rJS, RSVP, loopEventListener, URI */\n
<value> <string encoding="cdata"><![CDATA[
/*global window, rJS, RSVP, loopEventListener, URI, document */\n
/*jslint nomen: true, indent: 2, maxerr: 3 */\n
(function (window, rJS, RSVP, loopEventListener, URI) {\n
"use strict";\n
......@@ -195,7 +197,18 @@
return form_gadget.translateHtml(form_gadget.props.element.innerHTML);\n
})\n
.push(function (my_translated_html) {\n
form_gadget.props.element.innerHTML = my_translated_html;\n
//Can\'t use form_gadget.props.element.innerHTML = my_translated_html\n
// which will change dom then service will not be started\n
var temp = document.createElement("div"),\n
elements1,\n
i,\n
elements2;\n
temp.innerHTML = my_translated_html;\n
elements1 = form_gadget.props.element.querySelectorAll("[data-i18n]");\n
elements2 = temp.querySelectorAll("[data-i18n]");\n
for (i = 0; i < elements1.length; i += 1) {\n
elements1[i].innerHTML = elements2[i].innerHTML;\n
}\n
});\n
})\n
\n
......@@ -237,7 +250,9 @@
);\n
});\n
\n
}(window, rJS, RSVP, loopEventListener, URI));</string> </value>
}(window, rJS, RSVP, loopEventListener, URI));
]]></string> </value>
</item>
<item>
<key> <string>title</string> </key>
......@@ -358,7 +373,7 @@
</item>
<item>
<key> <string>actor</string> </key>
<value> <string>super_sven</string> </value>
<value> <string>zope</string> </value>
</item>
<item>
<key> <string>comment</string> </key>
......@@ -372,7 +387,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>939.43978.9403.31744</string> </value>
<value> <string>940.9016.5643.56644</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -390,8 +405,8 @@
</tuple>
<state>
<tuple>
<float>1419417712.26</float>
<string>GMT</string>
<float>1420723492.34</float>
<string>UTC</string>
</tuple>
</state>
</object>
......
......@@ -101,8 +101,8 @@
<key> <string>text_content</string> </key>
<value> <string encoding="cdata"><![CDATA[
/*jslint indent: 2, maxlen: 80, nomen: true, todo: true */\n
/*global window, rJS, document, i18n, UriTemplate */\n
/*jslint indent: 2, maxlen: 80, nomen: true, todo: true, unparam:true*/\n
/*global window, rJS, document, i18n, UriTemplate, fetchLanguage, RSVP*/\n
(function (window, rJS, i18n, UriTemplate) {\n
"use strict";\n
\n
......@@ -127,13 +127,12 @@
return JSON.parse(my_event.target.responseText);\n
});\n
}\n
\n
\n
// XXX: language definitions are not standard compliant!\n
// "zh-CN" is a language, "zh" is not, browser will return the "zh-CN"\n
// on internal i18n methods, which requires this method to "fix"\n
function fetchLanguage() {\n
var lang = i18n.detectLanguage();\n
\n
if (lang.length > 2) {\n
return lang.substring(0, 2);\n
}\n
......@@ -175,18 +174,18 @@
.push(function (my_hateoas) {\n
var url,\n
site_hal = JSON.parse(my_hateoas.target.responseText);\n
\n
// NOTE: at this point createJIO has not been called yet, so allDocs\n
// is not available and must be called "manually"\n
// XXX: Improve\n
url = UriTemplate.parse(site_hal._links.raw_search.href)\n
.expand({\n
query: \'portal_type: "Web Site" AND title: "\' + site_hal._links.parent.name + \'"\',\n
query: \'portal_type: "Web Site" AND title: "\'\n
+ site_hal._links.parent.name + \'"\',\n
select_list: [\n
"available_language_set",\n
"default_available_language"\n
],\n
limit: [0,1]\n
limit: [0, 1]\n
});\n
\n
return my_gadget.jio_ajax({\n
......@@ -198,25 +197,17 @@
.push(function (my_site_configuration) {\n
var response = JSON.parse(my_site_configuration.target.responseText),\n
web_site = response._embedded.contents[0];\n
\n
// set remaining properties\n
my_gadget.property_dict.language_list = web_site.available_language_set;\n
my_gadget.property_dict.default_language = web_site.default_available_language;\n
})\n
// XXX: temporary error handler to not break existing sites without\n
// translation lookup specified\n
.push(undefined, function (error) {\n
my_gadget.property_dict = {\n
"translation_disabled": true,\n
"language_list": []\n
};\n
my_gadget.property_dict.language_list =\n
web_site.available_language_set;\n
my_gadget.property_dict.default_language =\n
web_site.default_available_language;\n
});\n
})\n
\n
\n
// Fetch first dict here, based on info retrieved from ERP5 website object\n
.ready(function (my_gadget) {\n
var props = my_gadget.property_dict;\n
\n
// skip if translations are not available\n
if (props.translation_disabled) {\n
return my_gadget;\n
......@@ -231,7 +222,8 @@
\n
// initialize i18n\n
i18n.init({\n
"customLoad": function (my_lng, my_ns, my_option_dict, my_callback) {\n
"customLoad": function (my_lng, my_ns,\n
my_option_dict, my_callback) {\n
// translations available now\n
my_callback(null, props.current_language_dict);\n
},\n
......@@ -241,12 +233,8 @@
"fallbackLng": false,\n
"ns": \'dict\'\n
});\n
\n
// XXX: To prevent missing translations in header (calls render on \n
// ready) retrigger render now that translations are available.\n
return my_gadget.notifyUpdate();\n
});\n
\n
})\n
\n
\n
......@@ -261,28 +249,26 @@
/////////////////////////////////////////////////////////////////\n
// declared methods\n
/////////////////////////////////////////////////////////////////\n
\n
\n
// expose languages to gadget which want to know (eg panel)\n
.declareMethod(\'getLanguageList\', function () {\n
return JSON.stringify(this.property_dict.language_list);\n
})\n
\n
\n
.declareMethod(\'changeLanguage\', function (my_new_language) {\n
var gadget = this,\n
current_language = fetchLanguage();\n
\n
\n
// XXX: relies on cookie value set by i18n!\n
if (current_language !== my_new_language && gadget.property_dict.translation_disabled === undefined) {\n
\n
if (current_language !== my_new_language &&\n
gadget.property_dict.translation_disabled === undefined) {\n
return RSVP.Queue()\n
.push(function () {\n
return getTranslationDict(gadget, my_new_language);\n
})\n
.push(function (my_language_dict) {\n
gadget.property_dict.current_language_dict = my_language_dict;\n
\n
i18n.setLng(my_new_language);\n
\n
// XXX: for now, reload as the language is stored in cookie\n
window.location.reload();\n
//return gadget.translateElementList();\n
......@@ -291,12 +277,12 @@
\n
return gadget;\n
})\n
\n
\n
// translate a list of elements passed and returned as string\n
.declareMethod(\'translateHtml\', function (my_string) {\n
var temp, element_list, i, i_len, element, lookup, translate_list, target,\n
route_text, has_breaks, l, l_len, gadget;\n
\n
\n
gadget = this;\n
\n
// skip if no translations available\n
......@@ -370,17 +356,15 @@
element.removeChild(element.lastChild);\n
}\n
element.appendChild(document.createTextNode(i18n.t(target[0])));\n
element.appendChild(document.createElement("span"));\n
break;\n
}\n
}\n
}\n
}\n
\n
// return string\n
return temp.innerHTML;\n
});\n
\n
\n
}(window, rJS, i18n, UriTemplate));
]]></string> </value>
......@@ -504,7 +488,7 @@
</item>
<item>
<key> <string>actor</string> </key>
<value> <string>super_sven</string> </value>
<value> <string>zope</string> </value>
</item>
<item>
<key> <string>comment</string> </key>
......@@ -518,7 +502,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>940.1458.30717.61030</string> </value>
<value> <string>940.10185.20882.26419</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -536,8 +520,8 @@
</tuple>
<state>
<tuple>
<float>1420196319.63</float>
<string>GMT</string>
<float>1420723441.28</float>
<string>UTC</string>
</tuple>
</state>
</object>
......
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