UNPKG

2.13 kBJavaScriptView Raw
1(function() {
2 var AjaxUtils, _3Model,
3 __slice = [].slice;
4
5 _3Model = require("3vot-model");
6
7 AjaxUtils = (function() {
8 function AjaxUtils() {}
9
10 AjaxUtils.getURL = function(object) {
11 return (typeof object.url === "function" ? object.url() : void 0) || object.url;
12 };
13
14 AjaxUtils.getScope = function(object) {
15 return (typeof object.scope === "function" ? object.scope() : void 0) || object.scope;
16 };
17
18 AjaxUtils.generateURL = function() {
19 var args, collection, object, path, scope;
20 object = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
21 if (window && typeof window.Visualforce !== "undefined") {
22 if (object.className) {
23 collection = object.className;
24 scope = AjaxUtils.getScope(object);
25 } else {
26 collection = typeof object.constructor.url === 'string' ? object.constructor.url : object.constructor.className;
27 scope = AjaxUtils.getScope(object) || AjaxUtils.getScope(object.constructor);
28 }
29 } else if (object.className) {
30 collection = object.className.toLowerCase() + 's';
31 scope = AjaxUtils.getScope(object);
32 } else {
33 if (typeof object.constructor.url === 'string') {
34 collection = object.constructor.url;
35 } else {
36 collection = object.constructor.className.toLowerCase() + 's';
37 }
38 scope = AjaxUtils.getScope(object) || AjaxUtils.getScope(object.constructor);
39 }
40 args.unshift(collection);
41 args.unshift(scope);
42 path = args.join('/');
43 path = path.replace(/(\/\/)/g, "/");
44 path = path.replace(/^\/|\/$/g, "");
45 if (path.indexOf("../") !== 0) {
46 return _3Model.Model.host + "/" + path;
47 } else {
48 return path;
49 }
50 };
51
52 AjaxUtils.getCollectionURL = function(object) {
53 if (object) {
54 if (typeof object.url === "function") {
55 return AjaxUtils.generateURL(object);
56 } else {
57 return object.url;
58 }
59 }
60 };
61
62 return AjaxUtils;
63
64 })();
65
66 module.exports = AjaxUtils;
67
68}).call(this);