@doyosi/laraisy 1.0.1 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/package.json +1 -1
- package/src/CodeInput.js +48 -48
- package/src/DSAlert.js +352 -352
- package/src/DSAvatar.js +207 -207
- package/src/DSDelete.js +274 -274
- package/src/DSForm.js +568 -568
- package/src/DSGridOrTable.js +453 -453
- package/src/DSLocaleSwitcher.js +239 -239
- package/src/DSLogout.js +293 -293
- package/src/DSNotifications.js +365 -365
- package/src/DSRestore.js +181 -181
- package/src/DSSelect.js +1071 -1071
- package/src/DSSelectBox.js +563 -563
- package/src/DSSimpleSlider.js +517 -517
- package/src/DSSvgFetch.js +69 -69
- package/src/DSTable/DSTableExport.js +68 -68
- package/src/DSTable/DSTableFilter.js +224 -224
- package/src/DSTable/DSTablePagination.js +136 -136
- package/src/DSTable/DSTableSearch.js +40 -40
- package/src/DSTable/DSTableSelection.js +192 -192
- package/src/DSTable/DSTableSort.js +58 -58
- package/src/DSTable.js +353 -353
- package/src/DSTabs.js +488 -488
- package/src/DSUpload.js +887 -887
- package/dist/CodeInput.d.ts +0 -10
- package/dist/DSAlert.d.ts +0 -112
- package/dist/DSAvatar.d.ts +0 -45
- package/dist/DSDelete.d.ts +0 -61
- package/dist/DSForm.d.ts +0 -151
- package/dist/DSGridOrTable/DSGOTRenderer.d.ts +0 -60
- package/dist/DSGridOrTable/DSGOTViewToggle.d.ts +0 -26
- package/dist/DSGridOrTable.d.ts +0 -296
- package/dist/DSLocaleSwitcher.d.ts +0 -71
- package/dist/DSLogout.d.ts +0 -76
- package/dist/DSNotifications.d.ts +0 -54
- package/dist/DSRestore.d.ts +0 -56
- package/dist/DSSelect.d.ts +0 -221
- package/dist/DSSelectBox.d.ts +0 -123
- package/dist/DSSimpleSlider.d.ts +0 -136
- package/dist/DSSvgFetch.d.ts +0 -17
- package/dist/DSTable/DSTableExport.d.ts +0 -11
- package/dist/DSTable/DSTableFilter.d.ts +0 -40
- package/dist/DSTable/DSTablePagination.d.ts +0 -12
- package/dist/DSTable/DSTableSearch.d.ts +0 -8
- package/dist/DSTable/DSTableSelection.d.ts +0 -46
- package/dist/DSTable/DSTableSort.d.ts +0 -8
- package/dist/DSTable.d.ts +0 -116
- package/dist/DSTabs.d.ts +0 -156
- package/dist/DSUpload.d.ts +0 -220
- package/dist/index.d.ts +0 -17
package/src/DSRestore.js
CHANGED
|
@@ -1,181 +1,181 @@
|
|
|
1
|
-
import { DSAlert } from './DSAlert.js';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* DSRestore
|
|
5
|
-
*
|
|
6
|
-
* A plugin to handle restore actions with confirmation dialogs and AJAX requests.
|
|
7
|
-
* Integrates with DSAlert for UI.
|
|
8
|
-
*/
|
|
9
|
-
export class DSRestore {
|
|
10
|
-
static defaults = {
|
|
11
|
-
selector: '[data-restore]',
|
|
12
|
-
method: 'PATCH',
|
|
13
|
-
ajaxFunction: 'axios', // axios | fetch
|
|
14
|
-
|
|
15
|
-
// Confirmation Dialog
|
|
16
|
-
title: 'Are you sure?',
|
|
17
|
-
text: "You are about to restore this item.",
|
|
18
|
-
icon: 'question',
|
|
19
|
-
confirmButtonText: 'Yes, restore it!',
|
|
20
|
-
cancelButtonText: 'Cancel',
|
|
21
|
-
confirmButtonColor: 'btn btn-sm btn-success', // Positive action for restore
|
|
22
|
-
|
|
23
|
-
// Success Dialog
|
|
24
|
-
successTitle: 'Restored!',
|
|
25
|
-
successText: 'Item has been restored successfully.',
|
|
26
|
-
successIcon: 'success',
|
|
27
|
-
|
|
28
|
-
// Error Dialog
|
|
29
|
-
errorTitle: 'Error!',
|
|
30
|
-
errorText: 'Something went wrong.',
|
|
31
|
-
errorIcon: 'error',
|
|
32
|
-
|
|
33
|
-
// Callbacks
|
|
34
|
-
onSuccess: null, // function(response, element)
|
|
35
|
-
onError: null, // function(error, element)
|
|
36
|
-
onRestore: null, // function(element) - before restore, return false to cancel
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
constructor(options = {}) {
|
|
40
|
-
this.config = { ...DSRestore.defaults, ...options };
|
|
41
|
-
this._init();
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
_init() {
|
|
45
|
-
// Event Delegation
|
|
46
|
-
document.addEventListener('click', (e) => {
|
|
47
|
-
const trigger = e.target.closest(this.config.selector);
|
|
48
|
-
if (trigger) {
|
|
49
|
-
e.preventDefault();
|
|
50
|
-
this._handleRestore(trigger);
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
async _handleRestore(element) {
|
|
56
|
-
// Allow cancellation via hook
|
|
57
|
-
if (this.config.onRestore && this.config.onRestore(element) === false) {
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
const url = element.dataset.restore || element.getAttribute('href');
|
|
62
|
-
const id = element.dataset.restoreId;
|
|
63
|
-
|
|
64
|
-
if (!url) {
|
|
65
|
-
console.error('DSRestore: No restore URL found on element', element);
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
const contentTitle = element.dataset.restoreTitle ? `"${element.dataset.restoreTitle}"` : '';
|
|
70
|
-
const confirmText = contentTitle ? `${this.config.text} ${contentTitle}` : this.config.text;
|
|
71
|
-
|
|
72
|
-
const confirmed = await DSAlert.fire({
|
|
73
|
-
title: this.config.title,
|
|
74
|
-
text: confirmText,
|
|
75
|
-
icon: this.config.icon,
|
|
76
|
-
showCancelButton: true,
|
|
77
|
-
confirmButtonText: this.config.confirmButtonText,
|
|
78
|
-
cancelButtonText: this.config.cancelButtonText,
|
|
79
|
-
confirmButtonColor: this.config.confirmButtonColor
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
if (confirmed.isConfirmed) {
|
|
83
|
-
this._performRestore(url, id, element);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
async _performRestore(url, id, element) {
|
|
88
|
-
try {
|
|
89
|
-
this._emit('restore:start', { element, url, id });
|
|
90
|
-
|
|
91
|
-
let response;
|
|
92
|
-
const data = id ? { id } : {};
|
|
93
|
-
|
|
94
|
-
if (this.config.ajaxFunction === 'axios' && window.axios) {
|
|
95
|
-
response = await window.axios({
|
|
96
|
-
method: this.config.method,
|
|
97
|
-
url: url,
|
|
98
|
-
data: data
|
|
99
|
-
});
|
|
100
|
-
// Axios returns data in response.data
|
|
101
|
-
await this._handleSuccess(response.data, element);
|
|
102
|
-
} else if (this.config.ajaxFunction === 'fetch' || window.fetch) {
|
|
103
|
-
const options = {
|
|
104
|
-
method: this.config.method,
|
|
105
|
-
headers: {
|
|
106
|
-
'Content-Type': 'application/json',
|
|
107
|
-
'Accept': 'application/json',
|
|
108
|
-
'X-CSRF-TOKEN': document.querySelector('meta[name="csrf-token"]')?.content
|
|
109
|
-
},
|
|
110
|
-
body: JSON.stringify(data)
|
|
111
|
-
};
|
|
112
|
-
const res = await fetch(url, options);
|
|
113
|
-
const json = await res.json();
|
|
114
|
-
|
|
115
|
-
if (!res.ok) throw { response: res, data: json };
|
|
116
|
-
|
|
117
|
-
await this._handleSuccess(json, element);
|
|
118
|
-
} else {
|
|
119
|
-
throw new Error('DSRestore: No valid ajax function found');
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
} catch (error) {
|
|
123
|
-
this._handleError(error, element);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
async _handleSuccess(response, element) {
|
|
128
|
-
// Standard Laravel response: { success: true, message: '...' }
|
|
129
|
-
const message = response.message || this.config.successText;
|
|
130
|
-
|
|
131
|
-
// Fire Success Alert
|
|
132
|
-
await DSAlert.fire({
|
|
133
|
-
title: this.config.successTitle,
|
|
134
|
-
text: message,
|
|
135
|
-
icon: this.config.successIcon,
|
|
136
|
-
timer: 2000,
|
|
137
|
-
timerProgressBar: true
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
if (this.config.onSuccess) {
|
|
141
|
-
this.config.onSuccess(response, element);
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
this._emit('restore:success', { response, element });
|
|
145
|
-
|
|
146
|
-
// Optional: Remove row from table if inside one (assuming we are in trash view)
|
|
147
|
-
const row = element.closest('tr');
|
|
148
|
-
if (row) {
|
|
149
|
-
row.remove();
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
_handleError(error, element) {
|
|
154
|
-
console.error('DSRestore Error:', error);
|
|
155
|
-
|
|
156
|
-
let message = this.config.errorText;
|
|
157
|
-
if (error.response && error.response.data && error.response.data.message) {
|
|
158
|
-
message = error.response.data.message;
|
|
159
|
-
} else if (error.data && error.data.message) {
|
|
160
|
-
message = error.data.message;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
DSAlert.fire({
|
|
164
|
-
title: this.config.errorTitle,
|
|
165
|
-
text: message,
|
|
166
|
-
icon: this.config.errorIcon
|
|
167
|
-
});
|
|
168
|
-
|
|
169
|
-
if (this.config.onError) {
|
|
170
|
-
this.config.onError(error, element);
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
this._emit('restore:error', { error, element });
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
_emit(event, detail = {}) {
|
|
177
|
-
document.dispatchEvent(new CustomEvent(`ds:${event}`, { bubbles: true, detail }));
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
export default DSRestore;
|
|
1
|
+
import { DSAlert } from './DSAlert.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* DSRestore
|
|
5
|
+
*
|
|
6
|
+
* A plugin to handle restore actions with confirmation dialogs and AJAX requests.
|
|
7
|
+
* Integrates with DSAlert for UI.
|
|
8
|
+
*/
|
|
9
|
+
export class DSRestore {
|
|
10
|
+
static defaults = {
|
|
11
|
+
selector: '[data-restore]',
|
|
12
|
+
method: 'PATCH',
|
|
13
|
+
ajaxFunction: 'axios', // axios | fetch
|
|
14
|
+
|
|
15
|
+
// Confirmation Dialog
|
|
16
|
+
title: 'Are you sure?',
|
|
17
|
+
text: "You are about to restore this item.",
|
|
18
|
+
icon: 'question',
|
|
19
|
+
confirmButtonText: 'Yes, restore it!',
|
|
20
|
+
cancelButtonText: 'Cancel',
|
|
21
|
+
confirmButtonColor: 'btn btn-sm btn-success', // Positive action for restore
|
|
22
|
+
|
|
23
|
+
// Success Dialog
|
|
24
|
+
successTitle: 'Restored!',
|
|
25
|
+
successText: 'Item has been restored successfully.',
|
|
26
|
+
successIcon: 'success',
|
|
27
|
+
|
|
28
|
+
// Error Dialog
|
|
29
|
+
errorTitle: 'Error!',
|
|
30
|
+
errorText: 'Something went wrong.',
|
|
31
|
+
errorIcon: 'error',
|
|
32
|
+
|
|
33
|
+
// Callbacks
|
|
34
|
+
onSuccess: null, // function(response, element)
|
|
35
|
+
onError: null, // function(error, element)
|
|
36
|
+
onRestore: null, // function(element) - before restore, return false to cancel
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
constructor(options = {}) {
|
|
40
|
+
this.config = { ...DSRestore.defaults, ...options };
|
|
41
|
+
this._init();
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
_init() {
|
|
45
|
+
// Event Delegation
|
|
46
|
+
document.addEventListener('click', (e) => {
|
|
47
|
+
const trigger = e.target.closest(this.config.selector);
|
|
48
|
+
if (trigger) {
|
|
49
|
+
e.preventDefault();
|
|
50
|
+
this._handleRestore(trigger);
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
async _handleRestore(element) {
|
|
56
|
+
// Allow cancellation via hook
|
|
57
|
+
if (this.config.onRestore && this.config.onRestore(element) === false) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const url = element.dataset.restore || element.getAttribute('href');
|
|
62
|
+
const id = element.dataset.restoreId;
|
|
63
|
+
|
|
64
|
+
if (!url) {
|
|
65
|
+
console.error('DSRestore: No restore URL found on element', element);
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const contentTitle = element.dataset.restoreTitle ? `"${element.dataset.restoreTitle}"` : '';
|
|
70
|
+
const confirmText = contentTitle ? `${this.config.text} ${contentTitle}` : this.config.text;
|
|
71
|
+
|
|
72
|
+
const confirmed = await DSAlert.fire({
|
|
73
|
+
title: this.config.title,
|
|
74
|
+
text: confirmText,
|
|
75
|
+
icon: this.config.icon,
|
|
76
|
+
showCancelButton: true,
|
|
77
|
+
confirmButtonText: this.config.confirmButtonText,
|
|
78
|
+
cancelButtonText: this.config.cancelButtonText,
|
|
79
|
+
confirmButtonColor: this.config.confirmButtonColor
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
if (confirmed.isConfirmed) {
|
|
83
|
+
this._performRestore(url, id, element);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
async _performRestore(url, id, element) {
|
|
88
|
+
try {
|
|
89
|
+
this._emit('restore:start', { element, url, id });
|
|
90
|
+
|
|
91
|
+
let response;
|
|
92
|
+
const data = id ? { id } : {};
|
|
93
|
+
|
|
94
|
+
if (this.config.ajaxFunction === 'axios' && window.axios) {
|
|
95
|
+
response = await window.axios({
|
|
96
|
+
method: this.config.method,
|
|
97
|
+
url: url,
|
|
98
|
+
data: data
|
|
99
|
+
});
|
|
100
|
+
// Axios returns data in response.data
|
|
101
|
+
await this._handleSuccess(response.data, element);
|
|
102
|
+
} else if (this.config.ajaxFunction === 'fetch' || window.fetch) {
|
|
103
|
+
const options = {
|
|
104
|
+
method: this.config.method,
|
|
105
|
+
headers: {
|
|
106
|
+
'Content-Type': 'application/json',
|
|
107
|
+
'Accept': 'application/json',
|
|
108
|
+
'X-CSRF-TOKEN': document.querySelector('meta[name="csrf-token"]')?.content
|
|
109
|
+
},
|
|
110
|
+
body: JSON.stringify(data)
|
|
111
|
+
};
|
|
112
|
+
const res = await fetch(url, options);
|
|
113
|
+
const json = await res.json();
|
|
114
|
+
|
|
115
|
+
if (!res.ok) throw { response: res, data: json };
|
|
116
|
+
|
|
117
|
+
await this._handleSuccess(json, element);
|
|
118
|
+
} else {
|
|
119
|
+
throw new Error('DSRestore: No valid ajax function found');
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
} catch (error) {
|
|
123
|
+
this._handleError(error, element);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
async _handleSuccess(response, element) {
|
|
128
|
+
// Standard Laravel response: { success: true, message: '...' }
|
|
129
|
+
const message = response.message || this.config.successText;
|
|
130
|
+
|
|
131
|
+
// Fire Success Alert
|
|
132
|
+
await DSAlert.fire({
|
|
133
|
+
title: this.config.successTitle,
|
|
134
|
+
text: message,
|
|
135
|
+
icon: this.config.successIcon,
|
|
136
|
+
timer: 2000,
|
|
137
|
+
timerProgressBar: true
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
if (this.config.onSuccess) {
|
|
141
|
+
this.config.onSuccess(response, element);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
this._emit('restore:success', { response, element });
|
|
145
|
+
|
|
146
|
+
// Optional: Remove row from table if inside one (assuming we are in trash view)
|
|
147
|
+
const row = element.closest('tr');
|
|
148
|
+
if (row) {
|
|
149
|
+
row.remove();
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
_handleError(error, element) {
|
|
154
|
+
console.error('DSRestore Error:', error);
|
|
155
|
+
|
|
156
|
+
let message = this.config.errorText;
|
|
157
|
+
if (error.response && error.response.data && error.response.data.message) {
|
|
158
|
+
message = error.response.data.message;
|
|
159
|
+
} else if (error.data && error.data.message) {
|
|
160
|
+
message = error.data.message;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
DSAlert.fire({
|
|
164
|
+
title: this.config.errorTitle,
|
|
165
|
+
text: message,
|
|
166
|
+
icon: this.config.errorIcon
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
if (this.config.onError) {
|
|
170
|
+
this.config.onError(error, element);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
this._emit('restore:error', { error, element });
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
_emit(event, detail = {}) {
|
|
177
|
+
document.dispatchEvent(new CustomEvent(`ds:${event}`, { bubbles: true, detail }));
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
export default DSRestore;
|