Commit 08b6c32d authored by Yusei Tahara's avatar Yusei Tahara

erp5_travel_expense: Add excel download button as an example and rename...

erp5_travel_expense: Add excel download button as an example and rename megapixel javascript name to travel expense dependent one to avoid confliction.
parent 91e86db4
......@@ -13,7 +13,7 @@
<link rel="stylesheet" href="https://cdn.jsdelivr.net/chartist.js/0.9.8/chartist.min.css">
<script src="https://cdn.jsdelivr.net/chartist.js/0.9.8/chartist.min.js"></script>
<script src="travel_expense_excellentexport.min.js"></script>
<script class="view-report-template" type="text/x-handlebars-template">
......@@ -25,7 +25,8 @@
<div class="ct-chart ct-perfect-fourth"></div>
<input data-inline="true" type="submit" name="save" value="Save" data-theme="b" data-i18n="[value]Save">
<a name="download" data-role="button" data-i18n="Download">Download</a>
<a download="travel_expense.xls" name="hidden_download" style="visibility: hidden"></a>
</form>
......
......@@ -246,7 +246,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>953.46487.56947.2389</string> </value>
<value> <string>953.46555.12202.29593</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -264,7 +264,7 @@
</tuple>
<state>
<tuple>
<float>1473065777.57</float>
<float>1473070206.39</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -124,7 +124,7 @@
/////////////////////////////////////////
// Form submit
// Export data as excel
/////////////////////////////////////////
.declareService(function () {
var gadget = this;
......@@ -134,18 +134,50 @@
return gadget.props.deferred.promise;
})
.push(function () {
return promiseEventListener(
gadget.props.element.querySelector('form.view-report-form'),
'submit',
false
return loopEventListener(
gadget.props.element.querySelector('a[name=download]'),
'click',
false,
function (click_event){
var currency_dict = {};
return gadget.allDocs({
query: 'portal_type: "Currency" AND validation_state: "validated"',
select_list: ["title", "relative_url"],
limit: [0, 1234567890]
})
.push(function(result){
for (var i = 0; i < result.data.total_rows; i += 1) {
currency_dict[result.data.rows[i].value.relative_url] = result.data.rows[i].value.title;
}
return new RSVP.Queue();
})
.push(function(){
return gadget.allDocs({
query: 'visible_in_html5_app_flag:1 AND portal_type:("Expense Record" OR "Expense Record Temp")',
select_list: ["date", "resource", "quantity", "comment"],
limit: [0, 1234567890]
})
})
.push(function(result){
var data_list = [];
for (var i=0; i<result.data.total_rows; i++) {
var currency = currency_dict[result.data.rows[i].value.resource];
var date = result.data.rows[i].value.date;
var quantity = parseFloat(result.data.rows[i].value.quantity);
var comment = result.data.rows[i].value.comment;
data_list.push({currency:currency, date:date, quantity:quantity, comment:comment})
}
data_list.sort(function(a, b){if(a.date>b.date){return 1;}else if(a.date<b.date){return -1;}else{return 0;}})
var table = $("<table><tr><td>date</td><td>comment</td><td>currency</td><td>quantity</td></tr></table>");
for(var data of data_list){
table.append('<tr><td>'+data.date+'</td><td>'+comment+'</td><td>'+data.currency+'</td><td>'+data.quantity+'</td></tr>');
}
ExcellentExport.excel(gadget.props.element.querySelector('a[name="hidden_download"]'), table[0], 'Travel Expense');
gadget.props.element.querySelector('a[name="hidden_download"]').click();
})
}
);
})
.push(function (submit_event) {
gadget.props.element.querySelector("input[type=submit]").disabled = true;
})
.push(function () {
});
})
......
......@@ -242,7 +242,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>953.46462.30849.58624</string> </value>
<value> <string>953.46555.60478.6468</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -260,7 +260,7 @@
</tuple>
<state>
<tuple>
<float>1473064520.76</float>
<float>1473070102.21</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -122,7 +122,8 @@ gadget_jio.js\n
travel_expense_app.css\n
travel_expense_js_cookie.js\n
travel_expense_utility.js\n
megapix-image.js\n
travel_expense_megapix_image.js\n
travel_expense_excellentexport.min.js\n
handlebars.js\n
i18next.js\n
jiodev.js\n
......@@ -293,7 +294,7 @@ NETWORK:\n
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>953.41954.28591.13226</string> </value>
<value> <string>953.46532.22360.47496</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -311,7 +312,7 @@ NETWORK:\n
</tuple>
<state>
<tuple>
<float>1473065774.89</float>
<float>1473070350.4</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -19,7 +19,7 @@
<script src="gadget_global.js" ></script>
<script src="gadget_travel_expense_record_application.js"></script>
<script src="travel_expense_utility.js"></script>
<script src="megapix-image.js"></script>
<script src="travel_expense_megapix_image.js"></script>
<script class="edit-template" type="text/x-handlebars-template">
<h1 class="ui-title">{{title}}</h1>
......
......@@ -248,7 +248,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>953.39337.46159.3891</string> </value>
<value> <string>953.41948.23139.48452</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -266,7 +266,7 @@
</tuple>
<state>
<tuple>
<float>1472793381.11</float>
<float>1473070335.74</float>
<string>UTC</string>
</tuple>
</state>
......
var n=String.fromCharCode,p;a:{try{document.createElement("$")}catch(q){p=q;break a}p=void 0} window.btoa||(window.btoa=function(b){for(var g,c,f,h,e,a,d=0,r=b.length,s=Math.max,l="";d<r;){g=b.charCodeAt(d++)||0;c=b.charCodeAt(d++)||0;a=b.charCodeAt(d++)||0;if(255<s(g,c,a))throw p;f=g>>2&63;g=(g&3)<<4|c>>4&15;h=(c&15)<<2|a>>6&3;e=a&63;c?a||(e=64):h=e=64;l+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".charAt(f)+"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".charAt(g)+"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".charAt(h)+"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".charAt(e)}return l}); window.atob||(window.atob=function(b){b=b.replace(/=+$/,"");var g,c,f,h,e=0,a=b.length,d=[];if(1===a%4)throw p;for(;e<a;)g="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(b.charAt(e++)),c="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(b.charAt(e++)),f="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(b.charAt(e++)),h="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(b.charAt(e++)),g=(g&63)<< 2|c>>4&3,c=(c&15)<<4|f>>2&15,f=(f&3)<<6|h&63,d.push(n(g)),c&&d.push(n(c)),f&&d.push(n(f));return d.join("")}); ExcellentExport=function(){function b(e,a){return e.replace(RegExp("{(\\w+)}","g"),function(d,e){return a[e]})}var g={excel:"data:application/vnd.ms-excel;base64,",csv:"data:application/csv;base64,"},c={excel:'<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">\x3c!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>{worksheet}</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--\x3e</head><body><table>{table}</table></body></html>'},f= ",",h="\r\n";return{excel:function(e,a,d){a=a.nodeType?a:document.getElementById(a);var f=g.excel;a=b(c.excel,{a:d||"Worksheet",table:a.innerHTML});a=window.btoa(window.unescape(encodeURIComponent(a)));e.href=f+a;return!0},csv:function(e,a,d,b){void 0!==d&&d&&(f=d);void 0!==b&&b&&(h=b);a=a.nodeType?a:document.getElementById(a);var c="",l,k;for(d=0;d<a.rows.length;d++){l=a.rows[d];for(b=0;b<l.cells.length;b++){k=l.cells[b];var c=c+(b?f:""),m=k.textContent.trim();k=m;var t=-1!==m.indexOf(f)||-1!==m.indexOf("\r")|| -1!==m.indexOf("\n");(m=-1!==m.indexOf('"'))&&(k=k.replace(/"/g,'""'));if(t||m)k='"'+k+'"';c+=k}c+=h}a=g.csv+window.btoa(window.unescape(encodeURIComponent(c)));e.href=a;return!0}}}();
\ No newline at end of file
......@@ -75,7 +75,7 @@
</item>
<item>
<key> <string>default_reference</string> </key>
<value> <string>megapix-image.js</string> </value>
<value> <string>travel_expense_excellentexport.min.js</string> </value>
</item>
<item>
<key> <string>description</string> </key>
......@@ -85,7 +85,7 @@
</item>
<item>
<key> <string>id</string> </key>
<value> <string>megapix-image.js</string> </value>
<value> <string>travel_expense_excellentexport.min.js</string> </value>
</item>
<item>
<key> <string>language</string> </key>
......@@ -104,223 +104,18 @@
</value>
</item>
<item>
<key> <string>version</string> </key>
<key> <string>title</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>workflow_history</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="PersistentMapping" module="Persistence.mapping"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>data</string> </key>
<key> <string>version</string> </key>
<value>
<dictionary>
<item>
<key> <string>document_publication_workflow</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value>
</item>
<item>
<key> <string>edit_workflow</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAQ=</string> </persistent>
</value>
</item>
<item>
<key> <string>processing_status_workflow</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAU=</string> </persistent>
</value>
</item>
</dictionary>
<none/>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/>
</pickle>
<pickle>
<tuple>
<none/>
<list>
<dictionary>
<item>
<key> <string>action</string> </key>
<value> <string>publish_alive</string> </value>
</item>
<item>
<key> <string>actor</string> </key>
<value> <string>zope</string> </value>
</item>
<item>
<key> <string>comment</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>error_message</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>time</string> </key>
<value>
<object>
<klass>
<global name="DateTime" module="DateTime.DateTime"/>
</klass>
<tuple>
<none/>
</tuple>
<state>
<tuple>
<float>1472536123.39</float>
<string>UTC</string>
</tuple>
</state>
</object>
</value>
</item>
<item>
<key> <string>validation_state</string> </key>
<value> <string>published_alive</string> </value>
</item>
</dictionary>
</list>
</tuple>
</pickle>
</record>
<record id="4" aka="AAAAAAAAAAQ=">
<pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/>
</pickle>
<pickle>
<tuple>
<none/>
<list>
<dictionary>
<item>
<key> <string>action</string> </key>
<value> <string>edit</string> </value>
</item>
<item>
<key> <string>actor</string> </key>
<value> <string>zope</string> </value>
</item>
<item>
<key> <string>comment</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>error_message</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>953.37659.14085.40465</string> </value>
</item>
<item>
<key> <string>state</string> </key>
<value> <string>current</string> </value>
</item>
<item>
<key> <string>time</string> </key>
<value>
<object>
<klass>
<global name="DateTime" module="DateTime.DateTime"/>
</klass>
<tuple>
<none/>
</tuple>
<state>
<tuple>
<float>1472536090.8</float>
<string>UTC</string>
</tuple>
</state>
</object>
</value>
</item>
</dictionary>
</list>
</tuple>
</pickle>
</record>
<record id="5" aka="AAAAAAAAAAU=">
<pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/>
</pickle>
<pickle>
<tuple>
<none/>
<list>
<dictionary>
<item>
<key> <string>action</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>actor</string> </key>
<value> <string>zope</string> </value>
</item>
<item>
<key> <string>comment</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>error_message</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>external_processing_state</string> </key>
<value> <string>empty</string> </value>
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>0.0.0.0</string> </value>
</item>
<item>
<key> <string>time</string> </key>
<value>
<object>
<klass>
<global name="DateTime" module="DateTime.DateTime"/>
</klass>
<tuple>
<none/>
</tuple>
<state>
<tuple>
<float>1472536023.11</float>
<string>UTC</string>
</tuple>
</state>
</object>
</value>
</item>
</dictionary>
</list>
</tuple>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Web Script" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_Access_contents_information_Permission</string> </key>
<value>
<tuple>
<string>Anonymous</string>
<string>Assignee</string>
<string>Assignor</string>
<string>Associate</string>
<string>Auditor</string>
<string>Manager</string>
<string>Owner</string>
</tuple>
</value>
</item>
<item>
<key> <string>_Add_portal_content_Permission</string> </key>
<value>
<tuple>
<string>Assignee</string>
<string>Assignor</string>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>_Change_local_roles_Permission</string> </key>
<value>
<tuple>
<string>Assignor</string>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>_Modify_portal_content_Permission</string> </key>
<value>
<tuple>
<string>Assignee</string>
<string>Assignor</string>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>_View_Permission</string> </key>
<value>
<tuple>
<string>Anonymous</string>
<string>Assignee</string>
<string>Assignor</string>
<string>Associate</string>
<string>Auditor</string>
<string>Manager</string>
<string>Owner</string>
</tuple>
</value>
</item>
<item>
<key> <string>content_md5</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>content_type</string> </key>
<value> <string>text/javascript</string> </value>
</item>
<item>
<key> <string>default_reference</string> </key>
<value> <string>travel_expense_megapix_image.js</string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>travel_expense_megapix_image.js</string> </value>
</item>
<item>
<key> <string>language</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Web Script</string> </value>
</item>
<item>
<key> <string>short_title</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>title</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>version</string> </key>
<value>
<none/>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -25,10 +25,11 @@ web_page_module/gadget_travel_expense_translation.js
web_page_module/gadget_travel_expense_translation_data.js
web_page_module/gadget_travel_expense_widget_listbox.html
web_page_module/gadget_travel_expense_widget_listbox.js
web_page_module/megapix-image.js
web_page_module/travel_expense_app.css
web_page_module/travel_expense_excellentexport.min.js
web_page_module/travel_expense_jiodev_renderjs_storage.js
web_page_module/travel_expense_js_cookie.js
web_page_module/travel_expense_megapix_image.js
web_page_module/travel_expense_renderjs.js
web_page_module/travel_expense_utility.js
web_site_module/travel_expense_app
......
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