PageSourceSearch

https://stagingabc.org/DesktopModules/Mandeeps/Libraries/Common/Frameworks/WebAPI/1.0.0/webAPI.min.js?cdv=3798

js stagingabc.org collected 2026-09-29 16:59:07 UTC 10,157 bytes, 186 lines download raw bytes

1//The MIT License (MIT)<br /><br />
2//Copyright (c) 2014 2sic Internet Solutions GmbH<br />
3//<br />
4//Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:<br />
5//<br />
6//The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.<br />
7//<br />
8//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9
10(function () {
11    if (window.___WebAPI)
12        return;
13
14    window.___WebAPI = {
15        Angular: function (Module_Id, Module_API_Name, $http) { return window.___WebAPI.Common(Module_Id, Module_API_Name, "Angular", $http); },
16        jQuery: function (Module_Id, Module_API_Name) { return window.___WebAPI.Common(Module_Id, Module_API_Name, "jQuery"); },
17        Common: function (ModuleId, ModuleFolder, Framework, $http) {
18
19            var controller;
20
21            if (Framework == "jQuery")
22                controller = ___WebAPI.jQueryRepo[ModuleId];
23            else
24                controller = ___WebAPI.AngularRepo[ModuleId];
25
26            if (!controller) {
27                controller = {
28                    ModuleId: ModuleId,
29                    ModuleFolder: ModuleFolder,
30                    webApi: {
31                        get: function (controllerAction, params, data, preventAutoFail, returlUrl) {
32                            return controller.webApi._action(controllerAction, params, data, preventAutoFail, "GET", returlUrl);
33                        },
34                        post: function (controllerAction, params, data, preventAutoFail) {
35                            return controller.webApi._action(controllerAction, params, data, preventAutoFail, "POST");
36                        },
37                        "delete": function (controllerAction, params, data, preventAutoFail) {
38                            return controller.webApi._action(controllerAction, params, data, preventAutoFail, "DELETE");
39                        },
40                        put: function (controllerAction, params, data, preventAutoFail) {
41                            return controller.webApi._action(controllerAction, params, data, preventAutoFail, "PUT");
42                        },
43                        _action: function (settings, params, data, preventAutoFail, method, returlUrl) {
44
45                            // Url parameter: autoconvert a single value (instead of object of values) to an ModuleId=... parameter
46                            if (typeof params != "object" && typeof params != "undefined")
47                                params = params;
48
49                            // If the first parameter is a string, resolve settings
50                            if (typeof settings == 'string') {
51                                var controllerAction = settings.split('/');
52                                var controllerName = controllerAction[0];
53                                var actionName = controllerAction[1];
54
55                                if (controllerName == '' || actionName == '') {
56                                    var errtext = "Error: controller or action not defined. Will continue with likely errors.";
57                                        if (typeof swal !== 'undefined')
58                                            swal(errtext);
59                                        else
60                                            alert(errtext);
61                                }
62                                settings = {
63                                    controller: controllerName,
64                                    action: actionName,
65                                    params: params,
66                                    data: data,
67                                    preventAutoFail: preventAutoFail
68                                };
69                            }
70
71                            var defaults = {
72                                method: method == null ? 'POST' : method,
73                                params: null,
74                                preventAutoFail: false
75                            };
76
77                            settings = $.extend({}, defaults, settings);
78
79                            var sf = $.ServicesFramework(ModuleId);
80
81
82                            if (returlUrl)
83                                return controller.webApi.getActionUrl(settings);
84
85                            var promise
86
87                            if (Framework == "jQuery") {
88                                promise = $.ajax({
89                                    type: settings.method,
90                                    dataType: "json",
91                                    async: true,
92                                    data: JSON.stringify(settings.data),
93                                    contentType: "application/json",
94                                    url: controller.webApi.getActionUrl(settings),
95                                    beforeSend: sf.setModuleHeaders
96                                });
97                            }
98                            else {
99
100                                var _dnnHeaders = {};
101                                var tabID = sf.getTabId();
102                                var afValue = sf.getAntiForgeryValue();
103
104                                if (tabID > -1) {
105                                    _dnnHeaders.ModuleId = ModuleId;
106                                    _dnnHeaders.TabId = tabID;
107                                }
108                                if (afValue)
109                                    _dnnHeaders.RequestVerificationToken = afValue;
110
111                                var req = {
112                                    method: settings.method,
113                                    url: controller.webApi.getActionUrl(settings),
114                                    headers: _dnnHeaders,
115                                    data: JSON.stringify(settings.data),
116                                }
117
118                                promise = $http(req);
119
120
121
122                            }
123
124                            if (!settings.preventAutoFail)
125                                if (Framework == "jQuery") {
126                                    promise.fail(function (result) {
127                                        if (window.console)
128                                            console.log(result);
129                                        var infoText = "Had an error talking to the server (status " + result.status + ").";
130                                        infoText += "\n\nFor further debugging view the JS-console or use fiddler. ";
131                                        if (typeof swal !== 'undefined')
132                                            swal(infoText);
133                                        else
134                                            alert(infoText);
135                                    });
136                                }
137                                else {
138                                    promise.error(function (data, status, headers, config) {
139
140                                        //Handle Licensing
141                                        if (status == 403 && data.Message.length && data.Message.indexOf('#') == 0)
142                                            location.hash = data.Message;
143                                        else if (status != 0) {
144                                            if (typeof swal !== 'undefined')
145                                                swal(data.MessageDetail);
146                                            else
147                                                alert(data.MessageDetail);
148                                        }
149                                    });
150                                }
151                            return promise;
152                        },
153                        getActionUrl: function (settings) {
154                            var sf = $.ServicesFramework(ModuleId);
155                            var ActionUrl;
156
157                            //Framework
158                            if (settings.controller.substring(0, 1) == "~")
159                                ActionUrl = sf.getServiceRoot("mCommonAngularBootstrap") + settings.controller.replace('~', '') + "/" + settings.action;
160                            else
161                                ActionUrl = sf.getServiceRoot(ModuleFolder) + settings.controller + "/" 
161+ settings.action;
162
163                            if (settings.params != null) {
164                                if (typeof settings.params == 'string')
165                                    ActionUrl += "?" + settings.params;
166                                else if (typeof settings.params == 'object')
167                                    ActionUrl += "?" + $.param(settings.params);
168                            }
169                            return ActionUrl;
170                        }
171                    }
172                };
173
174                if (Framework == "jQuery")
175                    ___WebAPI.jQueryRepo[ModuleId] = controller;
176                else
177                    ___WebAPI.AngularRepo[ModuleId] = controller;
178            }
179
180            return controller;
181        },
182
183        jQueryRepo: {},
184        AngularRepo: {}
185    };
186})();

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.