Commit c0f6c7a7 authored by Xiaowu Zhang's avatar Xiaowu Zhang

erp5_travel_expense: group common functions and don't call several setSetting in rsvp.all

parent 8101fa34
......@@ -66,10 +66,7 @@
<item>
<key> <string>categories</string> </key>
<value>
<tuple>
<string>contributor/person_module/1</string>
<string>contributor/person_module/2</string>
</tuple>
<tuple/>
</value>
</item>
<item>
......@@ -200,12 +197,13 @@ chartist.min.js\n
chartist.min.css\n
gadget_hr_jio.html\n
gadget_hr_jio.js\n
gadget_officejs_jio_text_post.html\n
gadget_officejs_jio_text_post.js\n
gadget_common.js\n
gadget_officejs_page_calendar.js\n
gadget_officejs_page_calendar.html\n
gadget_hr_tool.js\n
\n
\n
\n
>>>>>>> e7eb1b5... erp5_travel_expense: add calendar gadget to display events in a person agenda
NETWORK:\n
*
......@@ -330,7 +328,7 @@ NETWORK:\n
</item>
<item>
<key> <string>actor</string> </key>
<value> <string>supercedriclen</string> </value>
<value> <string>zope</string> </value>
</item>
<item>
<key> <string>comment</string> </key>
......@@ -344,11 +342,7 @@ NETWORK:\n
</item>
<item>
<key> <string>serial</string> </key>
<<<<<<< HEAD
<value> <string>955.64169.17995.61457</string> </value>
=======
<value> <string>956.35741.51905.15616</string> </value>
>>>>>>> e7eb1b5... erp5_travel_expense: add calendar gadget to display events in a person agenda
<value> <string>956.44619.55889.62941</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -366,11 +360,7 @@ NETWORK:\n
</tuple>
<state>
<tuple>
<<<<<<< HEAD
<float>1481818221.17</float>
=======
<float>1484044668.41</float>
>>>>>>> e7eb1b5... erp5_travel_expense: add calendar gadget to display events in a person agenda
<float>1484577398.16</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -13,6 +13,7 @@
<script src="gadget_global.js" ></script>
<script src="handlebars.js"></script>
<script src="alertify.js"></script>
<script src="gadget_officejs_hr_tool.js"></script>
<script id="relation-listview-template" type="text/x-handlebars-template">
......
......@@ -246,7 +246,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>956.40028.61290.1433</string> </value>
<value> <string>956.44329.14852.21316</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -264,7 +264,7 @@
</tuple>
<state>
<tuple>
<float>1484312287.56</float>
<float>1484576962.29</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -64,17 +64,6 @@
return doc;
});
}
function getWorkflowState(id, sync_flag) {
var sync_state;
if(id.indexOf("_module/") > 0){
sync_state = "Synced";
}else if(sync_flag){
sync_state = "Not Synced";
}else{
sync_state = "Not Ready To Sync";
}
return sync_state;
}
function getTypeSelectList(gadget, doc) {
return new RSVP.Queue()
......@@ -104,82 +93,6 @@
});
}
function geoLocationPromise() {
return new Promise(function (resolve, reject) {
var err;
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function (result) {
resolve(result);
}, function (error) {
switch(error.code) {
case error.PERMISSION_DENIED:
err = new Error("User denied the request for Geolocation");
break;
case error.POSITION_UNAVAILABLE:
err = new Error("Location information is unavailable");
break;
case error.TIMEOUT:
err = new Error("The request to get user location timed out");
break;
default:
err = new Error("An unknown error occurred");
break;
}
reject(err);
},
{maximumAge:60000, timeout:20000});
} else {
reject(new Error("Geolocation is not supported by this browser"));
}
});
}
function getSequentialID(gadget, record_type_prefix){
var last_sequential_id,
prefix,
date = new Date(),
date_text = date.getFullYear()+('0'+(date.getMonth()+1)).slice(-2)+('0'+date.getDate()).slice(-2);
return new RSVP.Queue()
.push(function () {
if (gadget.options.doc.source_reference) {
return gadget.options.doc.source_reference;
} else {
return new RSVP.Queue()
.push(function () {
return new RSVP.all([
gadget.getSetting('last_sequential_id'),
gadget.getSetting('sequential_id_prefix')
]);
})
.push(function (result_list) {
if (result_list[0]) {
last_sequential_id = Number(result_list[0]);
} else {
last_sequential_id = 0;
}
last_sequential_id += 1;
if (result_list[1]) {
prefix = result_list[1];
} else {
prefix = getRandomPrefixForID();
}
return RSVP.all([
gadget.setSetting('last_sequential_id', last_sequential_id),
gadget.setSetting('sequential_id_prefix', prefix)
]);
})
.push(function () {
return record_type_prefix + '-' + date_text + '-' + prefix + ('0000'+last_sequential_id).slice(-5);
});
}
});
}
function getRandomPrefixForID(){
function random(){
return 65 + Math.floor( Math.random() * 26 );
}
return String.fromCharCode(random())+String.fromCharCode(random())+String.fromCharCode(random());
}
gadget_klass
.ready(function (g) {
......
......@@ -242,7 +242,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>956.40024.27967.8789</string> </value>
<value> <string>956.44593.2775.8567</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -260,7 +260,7 @@
</tuple>
<state>
<tuple>
<float>1484301997.49</float>
<float>1484576848.98</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -12,6 +12,7 @@
<script src="gadget_global.js" ></script>
<script src="handlebars.js"></script>
<script src="alertify.js"></script>
<script src="gadget_officejs_hr_tool.js"></script>
......
......@@ -246,7 +246,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>956.37052.29099.3498</string> </value>
<value> <string>956.44329.14852.21316</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -264,7 +264,7 @@
</tuple>
<state>
<tuple>
<float>1484240093.48</float>
<float>1484576952.21</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -26,95 +26,6 @@
};
function getWorkflowState(id, sync_flag) {
var sync_state;
if(id.indexOf("_module/") > 0){
sync_state = "Synced";
}else if(sync_flag){
sync_state = "Not Synced";
}else{
sync_state = "Not Ready To Sync";
}
return sync_state;
}
function geoLocationPromise() {
return new Promise(function (resolve, reject) {
var err;
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function (result) {
resolve(result);
}, function (error) {
switch(error.code) {
case error.PERMISSION_DENIED:
err = new Error("User denied the request for Geolocation");
break;
case error.POSITION_UNAVAILABLE:
err = new Error("Location information is unavailable");
break;
case error.TIMEOUT:
err = new Error("The request to get user location timed out");
break;
default:
err = new Error("An unknown error occurred");
break;
}
reject(err);
},
{maximumAge:60000, timeout:20000});
} else {
reject(new Error("Geolocation is not supported by this browser"));
}
});
}
function getSequentialID(gadget, record_type_prefix){
var last_sequential_id,
prefix,
date = new Date(),
date_text = date.getFullYear()+('0'+(date.getMonth()+1)).slice(-2)+('0'+date.getDate()).slice(-2);
return new RSVP.Queue()
.push(function () {
if (gadget.options.doc.source_reference) {
return gadget.options.doc.source_reference;
} else {
return new RSVP.Queue()
.push(function () {
return new RSVP.all([
gadget.getSetting('last_sequential_id'),
gadget.getSetting('sequential_id_prefix')
]);
})
.push(function (result_list) {
if (result_list[0]) {
last_sequential_id = Number(result_list[0]);
} else {
last_sequential_id = 0;
}
last_sequential_id += 1;
if (result_list[1]) {
prefix = result_list[1];
} else {
prefix = getRandomPrefixForID();
}
return RSVP.all([
gadget.setSetting('last_sequential_id', last_sequential_id),
gadget.setSetting('sequential_id_prefix', prefix)
]);
})
.push(function () {
return record_type_prefix + '-' + date_text + '-' + prefix + ('0000'+last_sequential_id).slice(-5);
});
}
});
}
function getRandomPrefixForID(){
function random(){
return 65 + Math.floor( Math.random() * 26 );
}
return String.fromCharCode(random())+String.fromCharCode(random())+String.fromCharCode(random());
}
gadget_klass
.ready(function (g) {
return g.getElement()
......
......@@ -244,7 +244,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>956.38999.14763.58112</string> </value>
<value> <string>956.44329.14852.21316</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -262,7 +262,7 @@
</tuple>
<state>
<tuple>
<float>1484240163.15</float>
<float>1484576839.9</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -12,6 +12,7 @@
<script src="gadget_global.js" ></script>
<script src="handlebars.js"></script>
<script src="alertify.js"></script>
<script src="gadget_officejs_hr_tool.js"></script>
......
......@@ -246,7 +246,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>956.38978.20050.22596</string> </value>
<value> <string>956.44329.14852.21316</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -264,7 +264,7 @@
</tuple>
<state>
<tuple>
<float>1484301861.21</float>
<float>1484576937.72</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -42,95 +42,6 @@
});
}
function getWorkflowState(id, sync_flag) {
var sync_state;
if(id.indexOf("_module/") > 0){
sync_state = "Synced";
}else if(sync_flag){
sync_state = "Not Synced";
}else{
sync_state = "Not Ready To Sync";
}
return sync_state;
}
function geoLocationPromise() {
return new Promise(function (resolve, reject) {
var err;
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function (result) {
resolve(result);
}, function (error) {
switch(error.code) {
case error.PERMISSION_DENIED:
err = new Error("User denied the request for Geolocation");
break;
case error.POSITION_UNAVAILABLE:
err = new Error("Location information is unavailable");
break;
case error.TIMEOUT:
err = new Error("The request to get user location timed out");
break;
default:
err = new Error("An unknown error occurred");
break;
}
reject(err);
},
{maximumAge:60000, timeout:20000});
} else {
reject(new Error("Geolocation is not supported by this browser"));
}
});
}
function getSequentialID(gadget, record_type_prefix){
var last_sequential_id,
prefix,
date = new Date(),
date_text = date.getFullYear()+('0'+(date.getMonth()+1)).slice(-2)+('0'+date.getDate()).slice(-2);
return new RSVP.Queue()
.push(function () {
if (gadget.options.doc.doc_id) {
return gadget.options.doc.doc_id;
} else {
return new RSVP.Queue()
.push(function () {
return new RSVP.all([
gadget.getSetting('last_sequential_id'),
gadget.getSetting('sequential_id_prefix')
]);
})
.push(function (result_list) {
if (result_list[0]) {
last_sequential_id = Number(result_list[0]);
} else {
last_sequential_id = 0;
}
last_sequential_id += 1;
if (result_list[1]) {
prefix = result_list[1];
} else {
prefix = getRandomPrefixForID();
}
return RSVP.all([
gadget.setSetting('last_sequential_id', last_sequential_id),
gadget.setSetting('sequential_id_prefix', prefix)
]);
})
.push(function () {
return record_type_prefix + '-' + date_text + '-' + prefix + ('0000'+last_sequential_id).slice(-5);
});
}
});
}
function getRandomPrefixForID(){
function random(){
return 65 + Math.floor( Math.random() * 26 );
}
return String.fromCharCode(random())+String.fromCharCode(random())+String.fromCharCode(random());
}
gadget_klass
.ready(function (g) {
return g.getElement()
......
......@@ -244,7 +244,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>956.40024.39635.59818</string> </value>
<value> <string>956.44329.14852.21316</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -262,7 +262,7 @@
</tuple>
<state>
<tuple>
<float>1484301994.5</float>
<float>1484576818.21</float>
<string>UTC</string>
</tuple>
</state>
......
/*global window, RSVP, FileReader */
/*jslint indent: 2, maxerr: 3, unparam: true */
(function (window, RSVP) {
"use strict";
window.getWorkflowState = function (id, sync_flag) {
var sync_state;
if(id.indexOf("_module/") > 0){
sync_state = "Synced";
}else if(sync_flag){
sync_state = "Not Synced";
}else{
sync_state = "Not Ready To Sync";
}
return sync_state;
};
window.getLocationPromise = function() {
return new Promise(function (resolve, reject) {
var err;
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function (result) {
resolve(result);
}, function (error) {
switch(error.code) {
case error.PERMISSION_DENIED:
err = new Error("User denied the request for Geolocation");
break;
case error.POSITION_UNAVAILABLE:
err = new Error("Location information is unavailable");
break;
case error.TIMEOUT:
err = new Error("The request to get user location timed out");
break;
default:
err = new Error("An unknown error occurred");
break;
}
reject(err);
},
{maximumAge:60000, timeout:20000});
} else {
reject(new Error("Geolocation is not supported by this browser"));
}
});
};
window.getSequentialID = function (gadget, record_type_prefix){
var last_sequential_id,
prefix,
date = new Date(),
date_text = date.getFullYear()+('0'+(date.getMonth()+1)).slice(-2)+('0'+date.getDate()).slice(-2);
return new RSVP.Queue()
.push(function () {
if (gadget.options.doc.source_reference) {
return gadget.options.doc.source_reference;
} else {
return new RSVP.Queue()
.push(function () {
return new RSVP.all([
gadget.getSetting('last_sequential_id'),
gadget.getSetting('sequential_id_prefix')
]);
})
.push(function (result_list) {
if (result_list[0]) {
last_sequential_id = Number(result_list[0]);
} else {
last_sequential_id = 0;
}
last_sequential_id += 1;
if (result_list[1]) {
prefix = result_list[1];
} else {
prefix = getRandomPrefixForID();
}
return gadget.setSetting('sequential_id_prefix', prefix);
})
.push(function () {
return gadget.setSetting('last_sequential_id', last_sequential_id);
})
.push(function () {
return record_type_prefix + '-' + date_text + '-' + prefix + ('0000'+last_sequential_id).slice(-5);
});
}
});
};
window.getRandomPrefixForID = function(){
function random(){
return 65 + Math.floor( Math.random() * 26 );
}
return String.fromCharCode(random())+String.fromCharCode(random())+String.fromCharCode(random());
};
}(window, RSVP));
\ No newline at end of file
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