PageSourceSearch

https://backoffice.motorica.io/assets/js/motorica-notify.js?v=1790230257

js motorica.io collected 2026-09-24 15:04:04 UTC 4,272 bytes, 163 lines download raw bytes

1/**
2 * Alertify-Helfer: einheitliche Toasts (Hemutis-Theming) für alle Views.
3 * Meldungstext aus JSON-Response oder jqXHR extrahieren.
4 */
5(function (window) {
6	'use strict';
7
8	var DEFAULT_WAIT = 5;
9
10	function extractMessage(source, fallback) {
11		if (source == null) {
12			return fallback || '';
13		}
14		if (typeof source === 'string') {
15			var s = source.trim();
16			return s || fallback || '';
17		}
18		if (typeof source.message === 'string' && source.message.trim()) {
19			return source.message.trim();
20		}
21		if (source.responseJSON && typeof source.responseJSON.message === 'string') {
22			var m = source.responseJSON.message.trim();
23			if (m) {
24				return m;
25			}
26		}
27		if (typeof source.responseText === 'string' && source.responseText.trim()) {
28			try {
29				var parsed = JSON.parse(source.responseText);
30				if (parsed && typeof parsed.message === 'string' && parsed.message.trim()) {
31					return parsed.message.trim();
32				}
33			} catch (e) {
34				/* ignore */
35			}
36		}
37		return fallback || '';
38	}
39
40	function normalizeType(type) {
41		var t = (type == null) ? '' : String(type).toLowerCase();
42		if (t === 'danger') {
43			return 'error';
44		}
45		return t;
46	}
47
48	function pushNotify(type, text, wait) {
49		if (typeof alertify === 'undefined' || !text) {
50			return;
51		}
52		var w = wait != null && wait !== '' ? wait : DEFAULT_WAIT;
53		var t = normalizeType(type);
54		if (t === 'success') {
55			alertify.success(text, w);
56		} else if (t === 'error') {
57			alertify.error(text, w);
58		} else if (t === 'warning') {
59			alertify.warning(text, w);
60		} else if (t) {
61			alertify.notify(text, t, w);
62		} else {
63			alertify.message(text, w);
64		}
65	}
66
67	function notify(type, source, fallback, wait) {
68		var text = extractMessage(source, fallback);
69		if (!text) {
70			return;
71		}
72		pushNotify(type, text, wait);
73	}
74
75	var dialogVariantClasses = [
76		'alert-primary',
77		'alert-secondary',
78		'alert-success',
79		'alert-danger',
80		'alert-warning',
81		'alert-info',
82		'alert-light',
83		'alert-dark',
84	];
85
86	function applyDialogVariant(instance, variant) {
87		if (!instance || !instance.elements || !instance.elements.dialog) {
88			return;
89		}
90		var dialog = instance.elements.dialog;
91		dialogVariantClasses.forEach(function (cls) {
92			dialog.classList.remove(cls);
93		});
94		if (variant) {
95			dialog.classList.add('alert-' + variant);
96		}
97	}
98
99	function dialogVariantForInstance(instance) {
100		if (!instance || !instance.__internal || !instance.__internal.buttons) {
101			return 'secondary';
102		}
103		return instance.__internal.buttons.length <= 1 ? 'secondary' : 'warning';
104	}
105
106	function installAlertifyDialogTheming() {
107		if (typeof alertify === 'undefined') {
108			return;
109		}
110		var prevPostinit = alertify.defaults.hooks.postinit;
111		alertify.defaults.hooks.postinit = function (instance) {
112			if (typeof prevPostinit === 'function') {
113				prevPostinit(instance);
114			}
115			if (!instance || typeof instance.set !== 'function') {
116				return;
117			}
118			var variant = dialogVariantForInstance(instance);
119			var userOnshow = instance.get('onshow');
120			instance.set('onshow', function () {
121				if (typeof userOnshow === 'function') {
122					userOnshow.call(this);
123				}
124				applyDialogVariant(this, variant);
125			});
126		};
127	}
128
129	installAlertifyDialogTheming();
130
131	window.MotoricaNotify = {
132		messageFrom: extractMessage,
133		success: function (source, fallback, wait) {
134			notify('success', source, fallback || 'Gespeichert', wait);
135		},
136		error: function (source, fallback, wait) {
137			notify('error', source, fallback || 'Fehler', wait);
138		},
139		warning: function (source, fallback, wait) {
140			notify('warning', source, fallback || 'Hinweis', wait);
141		},
142		info: function (source, fallback, wait) {
143			notify('info', source, fallback || '', wait);
144		},
145		secondary: function (source, fallback, wait) {
146			notify('secondary', source, fallback || '', wait);
147		},
148		notify: function (type, source, fallback, wait) {
149			notify(type, source, fallback, wait);
150		},
151		message: function (source, fallback, wait) {
152			var text = extractMessage(source, fallback);
153			if (!text || typeof alertify === 'undefined') {
154				return;
155			}
156			var w = wait != null && wait !== '' ? wait : DEFAULT_WAIT;
157			alertify.message(text, w);
158		},
159		ajaxFail: function (xhr, fallback, wait) {
160			notify('error', xhr, fallback || 'Fehler', wait);
161		},
162	};
163})(window);

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.