Commit bf46d0a5 authored by Xiaowu Zhang's avatar Xiaowu Zhang

erp5_travel_expense: don't create and insert dom manually

parent 2b79140a
......@@ -9,11 +9,17 @@
<script src="rsvp.js"></script>
<script src="renderjs.js"></script>
<script src="handlebars.js" type="text/javascript"></script>
<script src="gadget_officejs_page_leave_request_record_list.js"></script>
</head>
<script class="page-template" type="text/x-handlebars-template">
{{#if day_left}}
<p data-i18n="Leaves days left: ">Leaves days left: <span>{{day_left}}</span></p>
{{/if}}
<div class="leave_request_listbox"></div>
</script>
</head>
<body>
<div data-gadget-url="gadget_officejs_widget_listbox.html" data-gadget-scope="listbox"></div>
</body>
</html>
......@@ -260,7 +260,7 @@
</item>
<item>
<key> <string>actor</string> </key>
<value> <string>supercedriclen</string> </value>
<value> <string>zope</string> </value>
</item>
<item>
<key> <string>comment</string> </key>
......@@ -274,7 +274,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>955.40831.35926.40840</string> </value>
<value> <string>957.11901.58686.802</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -292,7 +292,7 @@
</tuple>
<state>
<tuple>
<float>1480528773.62</float>
<float>1486546513.23</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -2,8 +2,12 @@
/*jslint indent: 2, nomen: true, maxlen: 80*/
(function (window, RSVP, rJS, document) {
"use strict";
rJS(window)
var gadget_klass = rJS(window),
source = gadget_klass.__template_element
.querySelector(".page-template")
.innerHTML,
template = Handlebars.compile(source);
gadget_klass
.ready(function (g) {
g.props = {};
return g.getElement()
......@@ -31,6 +35,7 @@
});
})
.declareAcquiredMethod("translate", "translate")
.declareAcquiredMethod("translateHtml", "translateHtml")
.declareAcquiredMethod("getUrlFor", "getUrlFor")
.declareAcquiredMethod("updateHeader", "updateHeader")
.declareAcquiredMethod('getSetting', 'getSetting')
......@@ -70,7 +75,21 @@
});
})
.push(function () {
return gadget.getDeclaredGadget("listbox");
return gadget.jio_allDocs({
query: 'portal_type: "Leave Report Record"',
select_list: ["confirmed_leaves_days_left"],
});
})
.push(function (result) {
var options = {};
if (result.data.total_rows > 0) {
options.day_left = result.data.rows[0].value.confirmed_leaves_days_left;
}
return gadget.translateHtml(template(options));
})
.push(function (html) {
gadget.props.element.innerHTML = html;
return gadget.declareGadget("gadget_officejs_widget_listbox.html", {element: gadget.props.element.querySelector('.leave_request_listbox')});
})
.push(function (listbox) {
return listbox.render({
......@@ -96,25 +115,6 @@
sort_on: [["start_date", "descending"]]
}
});
})
.push(function () {
return gadget.jio_allDocs({
query: 'portal_type: "Leave Report Record"',
select_list: ["confirmed_leaves_days_left"],
});
})
.push(function (result) {
var p;
if (result.data.total_rows != 1) {
return;
}
p = document.createElement("p");
p.textContent = "Leaves days left: "
+ result.data.rows[0].value.confirmed_leaves_days_left;
gadget.props.element.insertBefore(
p,
gadget.props.element.querySelector("div")
);
});
});
......
......@@ -256,7 +256,7 @@
</item>
<item>
<key> <string>actor</string> </key>
<value> <string>supercedriclen</string> </value>
<value> <string>zope</string> </value>
</item>
<item>
<key> <string>comment</string> </key>
......@@ -270,7 +270,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>956.57347.13686.32631</string> </value>
<value> <string>957.11870.44460.28228</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -288,7 +288,7 @@
</tuple>
<state>
<tuple>
<float>1485341013.1</float>
<float>1486546441.25</float>
<string>UTC</string>
</tuple>
</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