2016-06-14 11:19:56 +00:00
|
|
|
var _status_catalog = {
|
2016-10-11 14:24:52 +00:00
|
|
|
commands: {},
|
2016-10-20 13:51:37 +00:00
|
|
|
responses: {},
|
|
|
|
functions: {}
|
2016-10-11 14:24:52 +00:00
|
|
|
},
|
|
|
|
status = {};
|
2016-06-14 11:19:56 +00:00
|
|
|
|
|
|
|
function Command() {
|
|
|
|
}
|
|
|
|
function Response() {
|
|
|
|
}
|
|
|
|
|
|
|
|
Command.prototype.addToCatalog = function () {
|
|
|
|
_status_catalog.commands[this.name] = this;
|
|
|
|
};
|
|
|
|
|
|
|
|
Command.prototype.param = function (parameter) {
|
|
|
|
this.params.push(parameter);
|
|
|
|
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
|
|
|
Command.prototype.create = function (com) {
|
|
|
|
this.name = com.name;
|
2016-11-10 08:33:44 +00:00
|
|
|
this.title = com.title;
|
2016-06-14 11:19:56 +00:00
|
|
|
this.description = com.description;
|
|
|
|
this.handler = com.handler;
|
2016-06-30 16:00:44 +00:00
|
|
|
this["has-handler"] = com.handler != null;
|
2016-12-06 23:09:41 +00:00
|
|
|
this["registered-only"] = com.registeredOnly;
|
2016-07-07 16:09:16 +00:00
|
|
|
this.validator = com.validator;
|
2016-06-14 11:19:56 +00:00
|
|
|
this.color = com.color;
|
|
|
|
this.icon = com.icon;
|
|
|
|
this.params = com.params || [];
|
2016-06-14 14:36:39 +00:00
|
|
|
this.preview = com.preview;
|
2016-07-18 07:38:24 +00:00
|
|
|
this["suggestions-trigger"] = com.suggestionsTrigger || "on-change";
|
|
|
|
this.fullscreen = com.fullscreen;
|
2016-10-20 13:51:37 +00:00
|
|
|
this.request = com.request;
|
2016-06-14 11:19:56 +00:00
|
|
|
this.addToCatalog();
|
|
|
|
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
Response.prototype = Object.create(Command.prototype);
|
|
|
|
Response.prototype.addToCatalog = function () {
|
|
|
|
_status_catalog.responses[this.name] = this;
|
|
|
|
};
|
|
|
|
Response.prototype.onReceiveResponse = function (handler) {
|
|
|
|
this.onReceive = handler;
|
|
|
|
};
|
|
|
|
|
2016-10-11 14:24:52 +00:00
|
|
|
var context = {}
|
|
|
|
|
|
|
|
function addContext(ns, key, value) {
|
|
|
|
context[ns][key] = value;
|
|
|
|
}
|
|
|
|
|
2016-06-14 11:19:56 +00:00
|
|
|
function call(pathStr, paramsStr) {
|
|
|
|
var params = JSON.parse(paramsStr),
|
|
|
|
path = JSON.parse(pathStr),
|
2016-10-11 14:24:52 +00:00
|
|
|
fn, callResult, message_id;
|
|
|
|
|
|
|
|
if (typeof params.context !== "undefined" &&
|
|
|
|
typeof params.context["message-id"] !== "undefined") {
|
|
|
|
message_id = params.context["message-id"];
|
|
|
|
} else {
|
|
|
|
message_id = null;
|
|
|
|
}
|
|
|
|
context[message_id] = {};
|
|
|
|
status.message_id = message_id;
|
2016-06-14 11:19:56 +00:00
|
|
|
|
|
|
|
fn = path.reduce(function (catalog, name) {
|
|
|
|
if (catalog && catalog[name]) {
|
|
|
|
return catalog[name];
|
|
|
|
}
|
|
|
|
},
|
|
|
|
_status_catalog
|
|
|
|
);
|
|
|
|
|
2016-07-18 13:22:32 +00:00
|
|
|
if (!fn) {
|
2016-06-25 13:28:45 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2016-11-02 07:20:50 +00:00
|
|
|
context.messages = [];
|
|
|
|
|
2016-10-11 14:24:52 +00:00
|
|
|
callResult = fn(params.parameters, params.context);
|
|
|
|
result = {
|
|
|
|
returned: callResult,
|
2016-11-02 07:20:50 +00:00
|
|
|
context: context[message_id],
|
|
|
|
messages: context.messages
|
2016-10-11 14:24:52 +00:00
|
|
|
};
|
2016-06-14 11:19:56 +00:00
|
|
|
|
2016-10-11 14:24:52 +00:00
|
|
|
return JSON.stringify(result);
|
2016-06-14 11:19:56 +00:00
|
|
|
}
|
|
|
|
|
2016-06-14 12:56:03 +00:00
|
|
|
function text(options, s) {
|
2016-11-02 07:20:50 +00:00
|
|
|
s = Array.isArray(s) ? s : [s];
|
|
|
|
return ['text', options].concat(s);
|
2016-06-14 12:56:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function view(options, elements) {
|
|
|
|
return ['view', options].concat(elements);
|
|
|
|
}
|
|
|
|
|
|
|
|
function image(options) {
|
|
|
|
return ['image', options];
|
|
|
|
}
|
|
|
|
|
|
|
|
function touchable(options, element) {
|
|
|
|
return ['touchable', options, element];
|
|
|
|
}
|
|
|
|
|
|
|
|
function scrollView(options, elements) {
|
|
|
|
return ['scroll-view', options].concat(elements);
|
|
|
|
}
|
|
|
|
|
2016-07-18 07:38:24 +00:00
|
|
|
function webView(url) {
|
|
|
|
return ['web-view', {
|
|
|
|
source: {
|
|
|
|
uri: url
|
|
|
|
},
|
|
|
|
javaScriptEnabled: true
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
|
2016-07-18 13:22:32 +00:00
|
|
|
function validationMessage(titleText, descriptionText) {
|
|
|
|
var titleStyle = {
|
2016-09-20 13:29:23 +00:00
|
|
|
style: {
|
|
|
|
color: "white",
|
|
|
|
fontSize: 12
|
|
|
|
}
|
2016-07-18 13:22:32 +00:00
|
|
|
};
|
|
|
|
var title = status.components.text(titleStyle, titleText);
|
|
|
|
|
|
|
|
var descriptionStyle = {
|
2016-09-20 13:29:23 +00:00
|
|
|
style: {
|
|
|
|
color: "white",
|
|
|
|
fontSize: 12,
|
|
|
|
opacity: 0.9
|
|
|
|
}
|
2016-07-18 13:22:32 +00:00
|
|
|
};
|
|
|
|
var description = status.components.text(descriptionStyle, descriptionText);
|
|
|
|
|
2016-06-30 16:00:44 +00:00
|
|
|
return status.components.view(
|
2016-07-18 13:22:32 +00:00
|
|
|
{
|
|
|
|
backgroundColor: "red",
|
|
|
|
height: 61,
|
|
|
|
paddingLeft: 16,
|
|
|
|
paddingTop: 14,
|
|
|
|
},
|
|
|
|
[title, description]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-06-14 11:19:56 +00:00
|
|
|
var status = {
|
2016-07-07 16:09:16 +00:00
|
|
|
command: function (h) {
|
2016-06-14 11:19:56 +00:00
|
|
|
var command = new Command();
|
2016-07-07 16:09:16 +00:00
|
|
|
return command.create(h);
|
2016-06-14 11:19:56 +00:00
|
|
|
},
|
2016-07-07 16:09:16 +00:00
|
|
|
response: function (h) {
|
2016-06-14 11:19:56 +00:00
|
|
|
var response = new Response();
|
2016-07-07 16:09:16 +00:00
|
|
|
return response.create(h);
|
2016-06-14 11:19:56 +00:00
|
|
|
},
|
2016-10-20 13:51:37 +00:00
|
|
|
registerFunction: function (name, fn){
|
|
|
|
_status_catalog.functions[name] = fn;
|
|
|
|
},
|
2016-08-03 13:15:04 +00:00
|
|
|
autorun: function (commandName) {
|
|
|
|
_status_catalog.autorun = commandName;
|
|
|
|
},
|
2016-06-14 11:19:56 +00:00
|
|
|
types: {
|
2016-06-27 15:38:44 +00:00
|
|
|
TEXT: 'text',
|
|
|
|
NUMBER: 'number',
|
|
|
|
PHONE: 'phone',
|
2016-06-14 11:19:56 +00:00
|
|
|
PASSWORD: 'password'
|
|
|
|
},
|
|
|
|
events: {
|
|
|
|
SET_VALUE: 'set-value'
|
2016-06-14 12:56:03 +00:00
|
|
|
},
|
|
|
|
components: {
|
|
|
|
view: view,
|
|
|
|
text: text,
|
|
|
|
image: image,
|
|
|
|
touchable: touchable,
|
2016-07-18 07:38:24 +00:00
|
|
|
scrollView: scrollView,
|
2016-07-18 13:22:32 +00:00
|
|
|
webView: webView,
|
|
|
|
validationMessage: validationMessage
|
2016-06-14 11:19:56 +00:00
|
|
|
}
|
|
|
|
};
|
2016-11-22 12:50:52 +00:00
|
|
|
|
|
|
|
// i18n.js 3.0.0.rc14
|
|
|
|
!function(a){if("undefined"!=typeof module&&module.exports)module.exports=a(this);else if("function"==typeof define&&define.amd){var b=this;define("i18n",function(){return a(b)})}else this.I18n=a(this)}(function(a){"use strict";var b=a&&a.I18n||{},c=Array.prototype.slice,d=function(a){return("0"+a.toString()).substr(-2)},e=function(a,b){return h("round",a,-b).toFixed(b)},f=function(a){var b=typeof a;return"function"===b||"object"===b&&!!a},g=function(a){return Array.isArray?Array.isArray(a):"[object Array]"===Object.prototype.toString.call(a)},h=function(a,b,c){return"undefined"==typeof c||0===+c?Math[a](b):(b=+b,c=+c,isNaN(b)||"number"!=typeof c||c%1!==0?NaN:(b=b.toString().split("e"),b=Math[a](+(b[0]+"e"+(b[1]?+b[1]-c:-c))),b=b.toString().split("e"),+(b[0]+"e"+(b[1]?+b[1]+c:c))))},i=function(a,b){var c,d;for(c in b)b.hasOwnProperty(c)&&(d=b[c],"[object String]"===Object.prototype.toString.call(d)?a[c]=d:(null==a[c]&&(a[c]={}),i(a[c],d)));return a},j={day_names:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],abbr_day_names:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],month_names:[null,"January","February","March","April","May","June","July","August","September","October","November","December"],abbr_month_names:[null,"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],meridian:["AM","PM"]},k={precision:3,separator:".",delimiter:",",strip_insignificant_zeros:!1},l={unit:"$",precision:2,format:"%u%n",sign_first:!0,delimiter:",",separator:"."},m={unit:"%",precision:3,format:"%n%u",separator:".",delimiter:""},n=[null,"kb","mb","gb","tb"],o={defaultLocale:"en",locale:"en",defaultSeparator:".",placeholder:/(?:\{\{|%\{)(.*?)(?:\}\}?)/gm,fallbacks:!1,translations:{},missingBehaviour:"message",missingTranslationPrefix:""};return b.reset=function(){this.defaultLocale=o.defaultLocale,this.locale=o.locale,this.defaultSeparator=o.defaultSeparator,this.placeholder=o.placeholder,this.fallbacks=o.fallbacks,this.translations=o.translations,this.missingBehaviour=o.missingBehaviour,this.missingTranslationPrefix=o.missingTranslationPrefix},b.initializeOptions=function(){"undefined"==typeof this.defaultLocale&&null!==this.defaultLocale&&(this.defaultLocale=o.defaultLocale),"undefined"==typeof this.locale&&null!==this.locale&&(this.locale=o.locale),"undefined"==typeof this.defaultSeparator&&null!==this.defaultSeparator&&(this.defaultSeparator=o.defaultSeparator),"undefined"==typeof this.placeholder&&null!==this.placeholder&&(this.placeholder=o.placeholder),"undefined"==typeof this.fallbacks&&null!==this.fallbacks&&(this.fallbacks=o.fallbacks),"undefined"==typeof this.translations&&null!==this.translations&&(this.translations=o.translations),"undefined"==typeof this.missingBehaviour&&null!==this.missingBehaviour&&(this.missingBehaviour=o.missingBehaviour),"undefined"==typeof this.missingTranslationPrefix&&null!==this.missingTranslationPrefix&&(this.missingTranslationPrefix=o.missingTranslationPrefix)},b.initializeOptions(),b.locales={},b.locales.get=function(a){var c=this[a]||this[b.locale]||this.default;return"function"==typeof c&&(c=c(a)),g(c)===!1&&(c=[c]),c},b.locales.default=function(a){var e,c=[],d=[];return a&&c.push(a),!a&&b.locale&&c.push(b.locale),b.fallbacks&&b.defaultLocale&&c.push(b.defaultLocale),c.forEach(function(a){e=a.split("-")[0],~d.indexOf(a)||d.push(a),b.fallbacks&&e&&e!==a&&!~d.indexOf(e)&&d.push(e)}),c.length||c.push("en"),d},b.pluralization={},b.pluralization.get=function(a){return this[a]||this[b.locale]||this.default},b.pluralization.default=function(a){switch(a){case 0:return["zero","other"];case 1:return["one"];default:return["other"]}},b.currentLocale=function(){return this.locale||this.defaultLocale},b.isSet=function(a){return void 0!==a&&null!==a},b.lookup=function(a,b){b=this.prepareOptions(b);var e,f,g,c=this.locales.get(b.locale).slice();c[0];for(a=this.getFullScope(a,b);c.length;)if(e=c.shift(),f=a.split(this.defaultSeparator),g=this.translations[e]){for(;f.length&&(g=g[f.shift()],void 0!==g&&null!==g););if(void 0!==g&&null!==g)return g}if(this.isSet(b.defaultVal
|
|
|
|
I18n.defaultLocale = "en";
|
|
|
|
I18n.fallbacks = true;
|