-
Notifications
You must be signed in to change notification settings - Fork 248
Expand file tree
/
Copy pathbootstrap.js
More file actions
431 lines (379 loc) · 14.4 KB
/
bootstrap.js
File metadata and controls
431 lines (379 loc) · 14.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
import "bootstrap-vue/dist/bootstrap-vue.css";
import { BootstrapVue, BootstrapVueIcons } from "bootstrap-vue";
import * as bootstrap from "bootstrap";
import TenantAwareEcho from "./common/TenantAwareEcho";
import { initSessionSync } from "./common/sessionSync";
import Router from "vue-router";
import ScreenBuilder, { initializeScreenCache } from "@processmaker/screen-builder";
import * as VueDeepSet from "vue-deepset";
/**
* Setup Translations
*/
import i18next from "i18next";
import Backend from "i18next-chained-backend";
import LocalStorageBackend from "i18next-localstorage-backend";
import XHR from "i18next-xhr-backend";
import VueI18Next from "@panter/vue-i18next";
import { install as VuetableInstall } from "vuetable-2";
import MonacoEditor from "vue-monaco";
import Vue from "vue";
import * as vue from "vue";
import VueCookies from "vue-cookies";
import GlobalStore from "./globalStore";
import Pagination from "./components/common/Pagination";
import ScreenSelect from "./processes/modeler/components/inspector/ScreenSelect.vue";
import translator from "./modules/lang.js";
import datetime_format from "./data/datetime_formats.json";
import RequestChannel from "./tasks/components/ProcessRequestChannel";
import Modal from "./components/shared/Modal";
import AccessibilityMixin from "./components/common/mixins/accessibility";
import PmqlInput from "./components/shared/PmqlInput.vue";
import DataTreeToggle from "./components/common/data-tree-toggle.vue";
import TreeView from "./components/TreeView.vue";
import FilterTable from "./components/shared/FilterTable.vue";
import PaginationTable from "./components/shared/PaginationTable.vue";
import PMDropdownSuggest from "./components/PMDropdownSuggest";
import "@processmaker/screen-builder/dist/vue-form-builder.css";
window.__ = translator;
window._ = require("lodash");
window.Popper = require("popper.js").default;
/**
* Give node plugins access to our custom screen builder components
*/
window.ProcessmakerComponents = require("./processes/screen-builder/components");
/**
* Give node plugins access to additional components
*/
window.SharedComponents = require("./components/shared");
window.ProcessesComponents = require("./processes/components");
window.ScreensComponents = require("./processes/screens/components");
window.ScriptsComponents = require("./processes/scripts/components");
window.ProcessesCatalogueComponents = require("./processes-catalogue/components/utils");
window.Utils = require("./utils");
window.PMDropdownSuggest = PMDropdownSuggest;
/**
* Exporting Modeler inspector components
*/
window.ModelerInspector = require("./processes/modeler/components/inspector");
/**
* We'll load jQuery and the Bootstrap jQuery plugin which provides support
* for JavaScript based Bootstrap features such as modals and tabs. This
* code may be modified to fit the specific needs of your application.
*/
window.$ = window.jQuery = require("jquery");
/**
* Vue is a modern JavaScript library for building interactive web interfaces
* using reactive data binding and reusable components. Vue's API is clean
* and simple, leaving you to focus on building your next great project.
*/
window.Vue = Vue;
window.vue = vue;
window.bootstrap = bootstrap;
window.Vue.use(BootstrapVue);
window.Vue.use(BootstrapVueIcons);
window.Vue.use(ScreenBuilder);
window.Vue.use(GlobalStore);
window.Vue.use(VueDeepSet);
window.Vue.use(VueCookies);
if (!document.head.querySelector("meta[name=\"is-horizon\"]")) {
window.Vue.use(Router);
}
window.VueMonaco = require("vue-monaco");
window.ScreenBuilder = require("@processmaker/screen-builder");
window.VueFormElements = require("@processmaker/vue-form-elements");
window.Modeler = require("@processmaker/modeler");
window.VueRouter = Router;
window.Vue.use(VueI18Next);
VuetableInstall(window.Vue);
window.Vue.component("pagination", Pagination);
window.Vue.component("monaco-editor", MonacoEditor);
window.Vue.component("screen-select", ScreenSelect);
window.Vue.component("pm-modal", Modal);
window.Vue.component("pmql-input", PmqlInput);
window.Vue.component("data-tree-toggle", DataTreeToggle);
window.Vue.component("tree-view", TreeView);
window.Vue.component("filter-table", FilterTable);
window.Vue.component("pagination-table", PaginationTable);
let translationsLoaded = false;
const mdates = JSON.parse(
document.head.querySelector("meta[name=\"i18n-mdate\"]")?.content,
);
// Make $t available to all vue instances
Vue.mixin({ i18n: new VueI18Next(i18next) });
Vue.mixin(AccessibilityMixin);
window.ProcessMaker = {
i18n: i18next,
/**
* A general use global event bus that can be used
*/
EventBus: new Vue(),
/**
* A general use global router that can be used
*/
Router: new Router({
mode: "history",
}),
/**
* ProcessMaker Notifications
*/
notifications: [],
/**
* Push a notification.
*
* @param {object} notification
*
* @returns {void}
*/
pushNotification(notification) {
if (this.notifications.filter((x) => x.id === notification).length === 0) {
this.notifications.push(notification);
}
},
/**
* Removes notifications by message ids or urls
*
* @returns {void}
* @param messageIds
*
* @param urls
*/
removeNotifications(messageIds = [], urls = []) {
return window.ProcessMaker.apiClient.put("/read_notifications", { message_ids: messageIds, routes: urls }).then(() => {
messageIds.forEach((messageId) => {
ProcessMaker.notifications.splice(ProcessMaker.notifications.findIndex((x) => x.id === messageId), 1);
});
urls.forEach((url) => {
const messageIndex = ProcessMaker.notifications.findIndex((x) => x.url === url);
if (messageIndex >= 0) {
ProcessMaker.removeNotification(ProcessMaker.notifications[messageIndex].id);
}
});
});
},
/**
* Mark as unread a list of notifications
*
* @returns {void}
* @param messageIds
*
* @param urls
*/
unreadNotifications(messageIds = [], urls = []) {
return window.ProcessMaker.apiClient.put("/unread_notifications", { message_ids: messageIds, routes: urls });
},
missingTranslations: new Set(),
missingTranslation(value) {
if (this.missingTranslations.has(value)) { return; }
this.missingTranslations.add(value);
if (!isProd) {
console.warn("Missing Translation:", value);
}
},
RequestChannel,
$notifications: {
icons: {},
},
};
window.ProcessMaker.setValidatorLanguage = (validator, lang) => {
const availableLanguages = ["ar", "az", "be", "bg", "bs", "ca", "cs", "cy", "da", "de", "el", "en", "es", "et", "eu", "fa", "fi",
"fr", "hr", "hu", "id", "it", "ja", "ka", "km", "ko", "lt", "lv", "mk", "mn", "ms", "nb_NO", "nl", "pl", "pt", "pt_BR", "ro", "ru",
"se", "sl", "sq", "sr", "sv", "tr", "ua", "uk", "uz", "vi", "zh", "zh_TW"];
const selectedLang = availableLanguages.includes(lang) ? lang : "en";
if (validator) {
validator.useLang(selectedLang);
}
};
window.ProcessMaker.i18nPromise = i18next.use(Backend).init({
lng: document.documentElement.lang,
fallbackLng: "en", // default language when no translations
returnEmptyString: false, // When a translation is an empty string, return the default language, not empty
nsSeparator: false,
keySeparator: false,
parseMissingKeyHandler(value) {
if (!translationsLoaded) { return value; }
// Report that a translation is missing
window.ProcessMaker.missingTranslation(value);
// Fallback to showing the english version
return value;
},
backend: {
backends: [
LocalStorageBackend, // Try cache first
XHR,
],
backendOptions: [
{ versions: mdates },
{ loadPath: "/i18next/fetch/{{lng}}/_default" },
],
},
});
window.ProcessMaker.i18nPromise.then(() => { translationsLoaded = true; });
/**
* Create a axios instance which any vue component can bring in to call
* REST api endpoints through oauth authentication
*
*/
window.ProcessMaker.apiClient = require("axios");
window.ProcessMaker.apiClient.defaults.headers.common["X-Requested-With"] = "XMLHttpRequest";
/**
* Next we will register the CSRF Token as a common header with Axios so that
* all outgoing HTTP requests automatically have it attached. This is just
* a simple convenience so we don't have to attach every token manually.
*/
const token = document.head.querySelector("meta[name=\"csrf-token\"]");
const isProd = document.head.querySelector("meta[name=\"is-prod\"]")?.content === "true";
if (token) {
window.ProcessMaker.apiClient.defaults.headers.common["X-CSRF-TOKEN"] = token.content;
} else {
console.error("CSRF token not found: https://laravel.com/docs/csrf#csrf-x-csrf-token");
}
// Setup api versions
const apiVersionConfig = [
{ version: "1.0", baseURL: "/api/1.0/" },
{ version: "1.1", baseURL: "/api/1.1/" },
];
window.ProcessMaker.apiClient.defaults.baseURL = apiVersionConfig[0].baseURL;
window.ProcessMaker.apiClient.interceptors.request.use((config) => {
if (typeof config.url !== "string" || !config.url) {
throw new Error("Invalid URL in the request configuration");
}
apiVersionConfig.forEach(({ version, baseURL }) => {
const versionPrefix = `/api/${version}/`;
if (config.url.startsWith(versionPrefix)) {
// eslint-disable-next-line no-param-reassign
config.baseURL = baseURL;
// eslint-disable-next-line no-param-reassign
config.url = config.url.replace(versionPrefix, "");
}
});
return config;
});
// Set the default API timeout
let apiTimeout = 5000;
if (window.Processmaker && window.Processmaker.apiTimeout !== undefined) {
apiTimeout = window.Processmaker.apiTimeout;
}
window.ProcessMaker.apiClient.defaults.timeout = apiTimeout;
// Default alert functionality
window.ProcessMaker.alert = function (text, variant) {
if (typeof text === "string") {
window.alert(text);
}
};
const openAiEnabled = document.head.querySelector("meta[name=\"open-ai-nlq-to-pmql\"]");
if (openAiEnabled) {
window.ProcessMaker.openAi = {
enabled: openAiEnabled.content,
};
} else {
window.ProcessMaker.openAi = {
enabled: false,
};
}
const userID = document.head.querySelector("meta[name=\"user-id\"]");
const userFullName = document.head.querySelector("meta[name=\"user-full-name\"]");
const userAvatar = document.head.querySelector("meta[name=\"user-avatar\"]");
const formatDate = document.head.querySelector("meta[name=\"datetime-format\"]");
const timezone = document.head.querySelector("meta[name=\"timezone\"]");
const appUrl = document.head.querySelector("meta[name=\"app-url\"]");
if (appUrl) {
window.ProcessMaker.app = {
url: appUrl.content,
};
}
if (userID) {
window.ProcessMaker.user = {
id: userID.content,
datetime_format: formatDate?.content,
calendar_format: formatDate?.content,
timezone: timezone?.content,
fullName: userFullName?.content,
avatar: userAvatar?.content,
};
datetime_format.forEach((value) => {
if (formatDate.content === value.format) {
window.ProcessMaker.user.datetime_format = value.momentFormat;
window.ProcessMaker.user.calendar_format = value.calendarFormat;
}
});
}
if (window.Processmaker && window.Processmaker.broadcasting) {
const config = window.Processmaker.broadcasting;
if (config.broadcaster == "pusher") {
window.Pusher = require("pusher-js");
window.Pusher.logToConsole = config.debug;
}
window.Echo = new TenantAwareEcho(config);
}
if (userID) {
const timeoutScript = document.head.querySelector("meta[name=\"timeout-worker\"]")?.content;
const accountTimeoutLength = parseInt(eval(document.head.querySelector("meta[name=\"timeout-length\"]")?.content));
const warnSeconds = parseInt(document.head.querySelector("meta[name=\"timeout-warn-seconds\"]")?.content);
const accountTimeoutWarnSeconds = Number.isNaN(warnSeconds) ? 0 : warnSeconds;
const accountTimeoutEnabled = document.head.querySelector("meta[name=\"timeout-enabled\"]") ? parseInt(document.head.querySelector("meta[name=\"timeout-enabled\"]")?.content) : 1;
const sessionSyncState = initSessionSync({
userId: userID.content,
isProd,
timeoutScript,
accountTimeoutLength,
accountTimeoutWarnSeconds,
accountTimeoutEnabled,
Vue,
Echo: window.Echo,
pushNotification: window.ProcessMaker.pushNotification,
alert: window.ProcessMaker.alert,
getSessionModal: () => window.ProcessMaker.sessionModal,
getCloseSessionModal: () => window.ProcessMaker.closeSessionModal,
getNavbar: () => window.ProcessMaker.navbar,
});
if (sessionSyncState) {
window.ProcessMaker.AccountTimeoutLength = sessionSyncState.AccountTimeoutLength;
window.ProcessMaker.AccountTimeoutWarnSeconds = sessionSyncState.AccountTimeoutWarnSeconds;
window.ProcessMaker.AccountTimeoutWarnMinutes = sessionSyncState.AccountTimeoutWarnMinutes;
window.ProcessMaker.AccountTimeoutEnabled = sessionSyncState.AccountTimeoutEnabled;
window.ProcessMaker.AccountTimeoutWorker = sessionSyncState.AccountTimeoutWorker;
window.ProcessMaker.sessionSync = sessionSyncState.sessionSync;
}
}
// Configuration Global object used by ScreenBuilder
// @link https://processmaker.atlassian.net/browse/FOUR-6833 Cache configuration
const screenCacheEnabled = document.head.querySelector("meta[name=\"screen-cache-enabled\"]")?.content ?? "false";
const screenCacheTimeout = document.head.querySelector("meta[name=\"screen-cache-timeout\"]")?.content ?? "5000";
const screenSecureHandlerToggleVisible = document.head.querySelector("meta[name='screen-secure-handler-toggle-visible']");
window.ProcessMaker.screen = {
cacheEnabled: screenCacheEnabled === "true",
cacheTimeout: Number(screenCacheTimeout),
secureHandlerToggleVisible: !!Number(screenSecureHandlerToggleVisible?.content),
};
// Initialize screen-builder cache
initializeScreenCache(window.ProcessMaker.apiClient, window.ProcessMaker.screen);
const clickTab = () => {
const { hash } = window.location;
if (!hash) {
return;
}
const tab = $(`[role="tab"][href="${hash}"]`);
if (tab.length) {
tab.tab("show");
}
};
window.addEventListener("hashchange", clickTab);
// click an active tab after all components have mounted
Vue.use({
install(vue) {
vue.mixin({
mounted() {
if (this.$parent) {
// only run on root
return;
}
// Run after component mounted
this.$nextTick(() => {
clickTab();
});
},
});
},
});
// Send an event when the global Vue and ProcessMaker instance is available
window.dispatchEvent(new Event("app-bootstrapped"));