Commit 80002630 authored by Tomáš Peterka's avatar Tomáš Peterka

WWIP

parent f4e03d67
...@@ -45,14 +45,14 @@ ...@@ -45,14 +45,14 @@
<script id="listbox-hidden-tbody-template" type="text/x-handlebars-template"> <script id="listbox-hidden-tbody-template" type="text/x-handlebars-template">
<table> <table>
<tbody class="tbody"> <tbody class="tbody">
{{#each body_value}} {{#each row_list}}
<tr> <tr>
{{#if ../show_anchor}} {{#if ../show_anchor}}
<th> <th>
<a class="ui-link ui-btn ui-corner-all ui-icon-carat-r ui-btn-icon-notext" href="{{jump}}"></a> <a class="ui-link ui-btn ui-corner-all ui-icon-carat-r ui-btn-icon-notext" href="{{jump}}"></a>
</th> </th>
{{/if}} {{/if}}
{{#each tr_value}} {{#each cell_list}}
<td> <td>
{{#if type}} {{#if type}}
{{#if editable}} {{#if editable}}
...@@ -82,7 +82,7 @@ ...@@ -82,7 +82,7 @@
<script id="listbox-show-tbody-template" type="text/x-handlebars-template"> <script id="listbox-show-tbody-template" type="text/x-handlebars-template">
<table> <table>
<tbody class="tbody"> <tbody class="tbody">
{{#each body_value}} {{#each row_list}}
<tr> <tr>
{{#if ../show_anchor}} {{#if ../show_anchor}}
<th> <th>
...@@ -92,7 +92,7 @@ ...@@ -92,7 +92,7 @@
<td> <td>
<input value="{{value}}" type="checkbox" checked="true" class="hide_element"> <input value="{{value}}" type="checkbox" checked="true" class="hide_element">
</td> </td>
{{#each tr_value}} {{#each cell_list}}
<td> <td>
{{#if type}} {{#if type}}
{{#if editable}} {{#if editable}}
...@@ -118,7 +118,42 @@ ...@@ -118,7 +118,42 @@
</table> </table>
</script> </script>
<script id="listbox-tfoot-template" type="text/x-handlebars-template"> <script id="listbox-tfoot-sum-template" type="text/x-handlebars-template">
<table>
<tfoot class="ui-bar-inherit tfoot summary">
{{#each row_list}}
<tr>
{{#each cell_list}}
<td>
{{#if type}}
{{#if editable}}
<div class="editable_div" data-column="{{column}}" data-line="{{line}}"></div>
{{else}}
<a href="{{href}}" class="ui-link">
<div class="editable_div" data-column="{{column}}" data-line="{{line}}"></div>
</a>
{{/if}}
{{else}}
<a href="{{href}}" class="ui-link">{{text}}</a>
{{/if}}
</td>
{{/each}}
</tr>
{{/each}}
<th colspan="{{colspan}}">
<div class="ui-controlgroup ui-controlgroup-horizontal ui-corner-all ui-paging-menu">
<div class="ui-controlgroup-controls">
<a class="{{previous_classname}}" data-i18n="Previous" href="{{previous_url}}">Previous</a>
<a class="{{next_classname}}" data-i18n="Next" href="{{next_url}}">Next</a>
<span class="ui-btn ui-disabled" data-i18n="{{record}}">{{record}}</span>
</div>
</div>
</th>
</tfoot>
</table>
</script>
<script id="listbox-tfoot-count-template" type="text/x-handlebars-template">
<table> <table>
<tfoot class="ui-bar-inherit tfoot"> <tfoot class="ui-bar-inherit tfoot">
<th colspan="{{colspan}}"> <th colspan="{{colspan}}">
...@@ -155,9 +190,8 @@ ...@@ -155,9 +190,8 @@
</table> </table>
</div> </div>
</script> </script>
<script id="error-message-template" type="text/x-handlebars-template"> <script id="error-message-template" type="text/x-handlebars-template">
<div class="ui-listbox-error"> <div class="ui-listbox-error">
<a class="ui-btn ui-corner-all ui-btn-inline" href="{{reset_url}}"> <a class="ui-btn ui-corner-all ui-btn-inline" href="{{reset_url}}">
......
...@@ -234,7 +234,7 @@ ...@@ -234,7 +234,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>962.24395.32903.29832</string> </value> <value> <string>963.47536.5989.57173</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -252,7 +252,7 @@ ...@@ -252,7 +252,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1506526285.9</float> <float>1511764805.38</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -19,10 +19,15 @@ ...@@ -19,10 +19,15 @@
.innerHTML, .innerHTML,
listbox_show_tbody_template = Handlebars.compile(listbox_show_tbody_source), listbox_show_tbody_template = Handlebars.compile(listbox_show_tbody_source),
listbox_tfoot_source = gadget_klass.__template_element listbox_tfoot_sum_source = gadget_klass.__template_element
.getElementById("listbox-tfoot-template") .getElementById("listbox-tfoot-sum-template")
.innerHTML, .innerHTML,
listbox_tfoot_template = Handlebars.compile(listbox_tfoot_source), listbox_tfoot_sum_template = Handlebars.compile(listbox_tfoot_sum_source),
listbox_tfoot_count_source = gadget_klass.__template_element
.getElementById("listbox-tfoot-count-template")
.innerHTML,
listbox_tfoot_count_template = Handlebars.compile(listbox_tfoot_count_source),
listbox_source = gadget_klass.__template_element listbox_source = gadget_klass.__template_element
.getElementById("listbox-template") .getElementById("listbox-template")
...@@ -49,14 +54,15 @@ ...@@ -49,14 +54,15 @@
gadget.props.listbox_uid_dict = {}; gadget.props.listbox_uid_dict = {};
gadget.props.cell_gadget_list = []; gadget.props.cell_gadget_list = [];
function renderSubCell(element, sub_field_json) { function renderSubCell(element, sub_field_json) {
sub_field_json.editable = sub_field_json.editable && gadget.state.editable; // XXX sub_field_json.editable = sub_field_json.editable && gadget.state.editable; // XXX
return gadget.declareGadget('gadget_erp5_label_field.html', {element: element, scope: sub_field_json.key}) return gadget.declareGadget('gadget_erp5_label_field.html', {element: element, scope: sub_field_json.key})
.push(function (cell_gadget) { .push(function (cell_gadget) {
gadget.props.cell_gadget_list.push(cell_gadget); gadget.props.cell_gadget_list.push(cell_gadget);
return cell_gadget.render({ return cell_gadget.render({
field_type: sub_field_json.type, field_type: sub_field_json.type,
field_json: sub_field_json, field_json: sub_field_json,
label: false}); label: false
});
}); });
} }
for (i = 0; i < element_list.length; i += 1) { for (i = 0; i < element_list.length; i += 1) {
...@@ -79,41 +85,47 @@ ...@@ -79,41 +85,47 @@
return RSVP.all(promise_list); return RSVP.all(promise_list);
} }
/**Put resulting `row_list` into `template` together with necessary gadget.state parameters.
function renderListboxTbody(gadget, template, body_value) { First, it removes all similar containers from within the table! Currently it is tricky
var tmp, to have multiple tbody/thead/tfoot elements! Feel free to refactor.
Example call: renderListboxTbody(gadget, compiled_template, row_list, "tbody");
**/
function renderListboxTbody(gadget, template, row_list, container_name) {
var container,
column_list = JSON.parse(gadget.state.column_list_json); column_list = JSON.parse(gadget.state.column_list_json);
return gadget.translateHtml(template( return gadget.translateHtml(template(
{ {
"body_value": body_value, "row_list": row_list,
"show_anchor": gadget.state.show_anchor, "show_anchor": gadget.state.show_anchor,
"column_list": column_list "column_list": column_list
} }
)) ))
.push(function (my_html) { .push(function (my_html) {
tmp = document.createElement("tbody"); container = document.createElement(container_name);
tmp.innerHTML = my_html; container.innerHTML = my_html;
return renderEditableField(gadget, tmp, column_list); return renderEditableField(gadget, container, column_list);
}) })
.push(function () { .push(function () {
var table = gadget.element.querySelector("table"), var table = gadget.element.querySelector("table"),
tbody = table.querySelector("tbody"); old_container = table.querySelector(container_name);
table.removeChild(tbody); table.removeChild(old_container);
table.appendChild(tmp); table.appendChild(container);
}); });
} }
function renderListboxTfoot(gadget, foot) { function renderListboxTfoot(gadget, foot_count, foot_sum) {
return gadget.translateHtml(listbox_tfoot_template( return gadget.translateHtml(listbox_tfoot_count_template(
{ {
"colspan": foot.colspan, "colspan": foot_count.colspan,
"previous_classname": foot.previous_classname, "previous_classname": foot_count.previous_classname,
"previous_url": foot.previous_url, "previous_url": foot_count.previous_url,
"record": foot.record, "record": foot_count.record,
"next_classname": foot.next_classname, "next_classname": foot_count.next_classname,
"next_url": foot.next_url "next_url": foot_count.next_url
} }
)); ));
} }
...@@ -455,18 +467,18 @@ ...@@ -455,18 +467,18 @@
}) })
.push(function (result_list) { .push(function (result_list) {
var value, var row_list = [],
body_value = [], value,
tr_value = [], cell_list,
tmp_url, tmp_url,
listbox_tbody_template; listbox_tbody_template;
for (i = 0; i < counter; i += 1) { for (i = 0; i < counter; i += 1) {
tmp_url = result_list[i]; tmp_url = result_list[i];
tr_value = []; cell_list = [];
for (j = 0; j < column_list.length; j += 1) { for (j = 0; j < column_list.length; j += 1) {
value = allDocs_result.data.rows[i].value[column_list[j][0]] || ""; value = allDocs_result.data.rows[i].value[column_list[j][0]] || "";
tr_value.push({ cell_list.push({
"type": value.type, "type": value.type,
"editable": value.editable && gadget.state.editable, "editable": value.editable && gadget.state.editable,
"href": tmp_url, "href": tmp_url,
...@@ -475,10 +487,10 @@ ...@@ -475,10 +487,10 @@
"column": j "column": j
}); });
} }
body_value.push({ row_list.push({
"value": allDocs_result.data.rows[i].value.uid, "value": allDocs_result.data.rows[i].value.uid,
"jump": tmp_url, "jump": tmp_url,
"tr_value": tr_value, "cell_list": cell_list,
"line_icon": gadget.state.line_icon "line_icon": gadget.state.line_icon
}); });
} }
...@@ -489,7 +501,7 @@ ...@@ -489,7 +501,7 @@
listbox_tbody_template = listbox_hidden_tbody_template; listbox_tbody_template = listbox_hidden_tbody_template;
} }
return renderListboxTbody(gadget, listbox_tbody_template, body_value); return renderListboxTbody(gadget, listbox_tbody_template, row_list, "tbody");
}) })
.push(function () { .push(function () {
var prev_param = {}, var prev_param = {},
...@@ -513,28 +525,32 @@ ...@@ -513,28 +525,32 @@
}) })
.push(function (url_list) { .push(function (url_list) {
var foot = {}; var tfoot_count = {
foot.colspan = column_list.length + gadget.state.show_anchor + "previous_url": url_list[0],
"next_url": url_list[1],
"previous_classname": "ui-btn ui-icon-carat-l ui-btn-icon-left responsive ui-first-child",
"next_classname": "ui-btn ui-icon-carat-r ui-btn-icon-right responsive ui-last-child"
},
tfoot_sum = {};
tfoot_count.colspan = column_list.length + gadget.state.show_anchor +
(gadget.state.line_icon ? 1 : 0); (gadget.state.line_icon ? 1 : 0);
foot.previous_classname = "ui-btn ui-icon-carat-l ui-btn-icon-left responsive ui-first-child";
foot.previous_url = url_list[0];
foot.next_classname = "ui-btn ui-icon-carat-r ui-btn-icon-right responsive ui-last-child";
foot.next_url = url_list[1];
if ((gadget.state.begin_from === 0) && (counter === 0)) { if ((gadget.state.begin_from === 0) && (counter === 0)) {
foot.record = variable.translated_no_record; tfoot_count.record = variable.translated_no_record;
} else if ((allDocs_result.data.rows.length <= lines) && (gadget.state.begin_from === 0)) { } else if ((allDocs_result.data.rows.length <= lines) && (gadget.state.begin_from === 0)) {
foot.record = counter + " " + variable.translated_records; tfoot_count.record = counter + " " + variable.translated_records;
} else { } else {
foot.record = variable.translated_records + " " + (((gadget.state.begin_from + lines) / lines - 1) * lines + 1) + " - " + (((gadget.state.begin_from + lines) / lines - 1) * lines + counter); tfoot_count.record = variable.translated_records + " " + (((gadget.state.begin_from + lines) / lines - 1) * lines + 1) + " - " + (((gadget.state.begin_from + lines) / lines - 1) * lines + counter);
} }
if (gadget.state.begin_from === 0) { if (gadget.state.begin_from === 0) {
foot.previous_classname += " ui-disabled"; tfoot_count.previous_classname += " ui-disabled";
} }
if (allDocs_result.data.rows.length <= lines) { if (allDocs_result.data.rows.length <= lines) {
foot.next_classname += " ui-disabled"; tfoot_count.next_classname += " ui-disabled";
} }
return renderListboxTfoot(gadget, foot); return renderListboxTfoot(gadget, tfoot_count, tfoot_sum);
}) })
.push(function (my_html) { .push(function (my_html) {
gadget.element.querySelector(".tfoot").innerHTML = my_html; gadget.element.querySelector(".tfoot").innerHTML = my_html;
......
...@@ -236,7 +236,7 @@ ...@@ -236,7 +236,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>961.56527.16709.20804</string> </value> <value> <string>963.47634.31999.4898</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -254,7 +254,7 @@ ...@@ -254,7 +254,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1506527031.12</float> <float>1511765129.91</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
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