Commit 390b318a authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_jio: Introduce annotated helper gadget

This gadget aims to centralise entire "helper" test on various contexts, in this way translate becomes easy and update information is quite simple.

In order to use the gadget, you should include a template on rjs_gadget_slapos_annotated_helper_html:

<script id="add-new-example-header-text" type="text/x-handlebars-template">
Some text or <details> <summary>Some test<summary> <p>Content...</p></details>
</script>

and include the gadget on the target HTML:

<div data-gadget-url="gadget_slapos_annotated_helper.html"
data-gadget-scope="annotated_helper"
data-template-id="add-new-example-header-text"
data-gadget-sandbox="public">
</div>

This is also supposed to be compatible with GadgetField or usable from getDeclaredGadget(...)
parent 8be15634
Pipeline #9658 failed with stage
in 0 seconds
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Background</title>
<script src="rsvp.js"></script>
<script src="renderjs.js"></script>
<script src="handlebars.js"></script>
<script src="gadget_slapos_annotated_helper.js"></script>
<link href="gadget_slapos_annotated_helper.css" rel="stylesheet" type="text/css"/>
<script id="add-new-login-header-text" type="text/x-handlebars-template">
<details>
<summary>Password Policy</summary>
<ul>
<li> Minimum 7 characters in length </li>
<li> At least one Uppercase Letter</li>
<li> At least one Lowercase Letter </li>
<li> At least one Number (0 to 9)</li>
<li> At least one Symbol out of $!:;_- .</li>
</ul>
</p>
</details>
<p></p>
</script>
</head>
<body>
<div class="annotated_help"></div>
</body>
</html>
\ No newline at end of file
/*globals console, window, rJS, RSVP, loopEventListener, i18n, Handlebars, $*/
/*jslint indent: 2, nomen: true, maxlen: 80*/
(function (window, rJS, RSVP, Handlebars) {
"use strict";
var gadget_klass = rJS(window);
function getTemplateById(template_id) {
var template_source = gadget_klass.__template_element
.getElementById(template_id)
.innerHTML;
return Handlebars.compile(template_source);
}
gadget_klass
.declareAcquiredMethod("getSetting", "getSetting")
.declareAcquiredMethod("translateHtml", "translateHtml")
.ready(function (gadget) {
gadget.props = {};
return gadget.getSetting("hateoas_url")
.push(function (url) {
gadget.props.hateoas_url = url;
})
.push(function () {
gadget.render({});
});
})
.declareMethod("getContent", function () {
return {};
})
.declareMethod("render", function (options) {
var gadget = this,
annotated_message = "",
annotated_message_template,
annotated_template_id;
gadget.options = options;
if (options.template_id === undefined) {
// Verify if template-id is present on the div element
annotated_template_id = gadget.element.getAttribute("data-template-id");
annotated_message_template = getTemplateById(annotated_template_id);
annotated_message = annotated_message_template({});
} else if (options.template_id !== undefined) {
annotated_message_template = getTemplateById(options.template_id);
annotated_message = annotated_message_template({});
}
return gadget.getElement()
.push(function (element) {
var div = element.querySelector('div.annotated_help');
div.innerHTML = annotated_message;
return element;
});
});
}(window, rJS, RSVP, Handlebars));
\ No newline at end of file
......@@ -311,6 +311,9 @@ gadget_erp5_page_slap_hosting_subscription_view.html\n
gadget_erp5_page_slap_hosting_subscription_view.js\n
gadget_erp5_page_slap_intent.html\n
gadget_erp5_page_slap_intent.js\n
gadget_slapos_annotated_helper.js\n
gadget_slapos_annotated_helper.html\n
gadget_slapos_annotated_helper.css\n
gadget_erp5_page_slap_invoice_list.html\n
gadget_erp5_page_slap_invoice_list.js\n
gadget_erp5_page_slap_load_schema.html\n
......@@ -582,7 +585,7 @@ NETWORK:\n
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>983.33875.37805.24183</string> </value>
<value> <string>984.14242.872.36949</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -600,7 +603,7 @@ NETWORK:\n
</tuple>
<state>
<tuple>
<float>1588166780.77</float>
<float>1590781574.81</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -4,6 +4,9 @@ web_page_module/gadget_erp5_page_slap_reject_upgrade_decision_js
web_page_module/rjs_gadget_erp5_attention_point_css
web_page_module/rjs_gadget_erp5_attention_point_html
web_page_module/rjs_gadget_erp5_attention_point_js
web_page_module/rjs_gadget_slapos_annotated_helper_css
web_page_module/rjs_gadget_slapos_annotated_helper_html
web_page_module/rjs_gadget_slapos_annotated_helper_js
web_page_module/rjs_gadget_erp5_page_map_css
web_page_module/rjs_gadget_erp5_page_map_html
web_page_module/rjs_gadget_erp5_page_map_js
......
......@@ -163,6 +163,9 @@ web_page_module/rjs_gadget_erp5_pt_form_slapos_index_js
web_page_module/rjs_gadget_slapos_alert_listbox_field_css
web_page_module/rjs_gadget_slapos_alert_listbox_field_html
web_page_module/rjs_gadget_slapos_alert_listbox_field_js
web_page_module/rjs_gadget_slapos_annotated_helper_css
web_page_module/rjs_gadget_slapos_annotated_helper_html
web_page_module/rjs_gadget_slapos_annotated_helper_js
web_page_module/rjs_gadget_slapos_appcache
web_page_module/rjs_gadget_slapos_computer_map_html
web_page_module/rjs_gadget_slapos_computer_map_js
......
  • /cc @tomo @luke

    I introduced a way to centralize the "helper" text into a single gadget, which prevent us duplicate html to translate texts.

    For now it is CSS-less and only contains password policy text (which is what I need for now).

    Edited by Rafael Monnerat
  • Thank you.

    Shall I drop my experiments and adapt to your way? Also does it make nexedi/erp5!1131 obsolete?

  • This is just to centralize the content, so this can replace your experiments but nexedi/erp5!1131 is something else.

    "Annotated helper" is just a way to centralize messages, to make translation easy, and a simple API to select the message, on erp5js/renderjs is an API/standard for display the help itself which seems interesting to be finished from erp5js point of view.

    /cc @romain

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