Skip to content

Commit

Permalink
3b7323e2e9630694696b3ca338c2e646420b4648 Fix: Ensure that all confirm…
Browse files Browse the repository at this point in the history
…ation messages quote the state name

Fix: If Ajax loading a state, it wasn't possible to then update it
Fix: Hide the "include" checkbox title if there are no checkboxes to show
Fix: List of state buttons was only showing if the state restore button was the first in the collection

Dev: createButton callback option - not yet publically documented
Dev: createState callback option - also not yet publically documented

1df5de850c73211093120aa18b201de84aae9b3f Merge branch 'master' of github.com:DataTables/StateRestore

Sync to source repo @1df5de850c73211093120aa18b201de84aae9b3f
  • Loading branch information
dtbuild committed Oct 4, 2024
1 parent 3373341 commit a3902ac
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 43 deletions.
2 changes: 1 addition & 1 deletion datatables.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@
],
"src-repo": "http://github.com/DataTables/StateRestore",
"last-tag": "1.4.1",
"last-sync": "169b120d2ff1068804e727c6e89738deddfb620c"
"last-sync": "1df5de850c73211093120aa18b201de84aae9b3f"
}
10 changes: 6 additions & 4 deletions js/StateRestore.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var StateRestore = /** @class */ (function () {
dt: table,
identifier: identifier,
isPreDefined: isPreDefined,
savedState: null,
savedState: state,
tableId: state && state.stateRestore ? state.stateRestore.tableId : undefined
};
this.dom = {
Expand Down Expand Up @@ -750,13 +750,13 @@ var StateRestore = /** @class */ (function () {
duplicateError: 'A state with this name already exists.',
emptyError: 'Name cannot be empty.',
emptyStates: 'No saved states',
removeConfirm: 'Are you sure you want to remove %s?',
removeConfirm: 'Are you sure you want to remove "%s"?',
removeError: 'Failed to remove state.',
removeJoiner: ' and ',
removeSubmit: 'Remove',
removeTitle: 'Remove State',
renameButton: 'Rename',
renameLabel: 'New Name for %s:',
renameLabel: 'New Name for "%s":',
renameTitle: 'Rename State'
},
modalCloseButton: true,
Expand Down Expand Up @@ -797,7 +797,9 @@ var StateRestore = /** @class */ (function () {
searchBuilder: false,
searchPanes: false,
select: false
}
},
createButton: null,
createState: null
};
return StateRestore;
}());
Expand Down
28 changes: 21 additions & 7 deletions js/StateRestoreCollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -428,10 +428,18 @@ var StateRestoreCollection = /** @class */ (function () {
that._collectionRebuild();
};
var loadedState = preDefined[state];
var newState = new StateRestore(this_1.s.dt, $.extend(true, {}, this_1.c, loadedState.c !== undefined ?
{ saveState: loadedState.c.saveState } :
undefined, true), state, loadedState, true, successCallback);
newState.s.savedState = loadedState;
var stateConfig = $.extend(true, {}, this_1.c, loadedState.c !== undefined ?
{
saveState: loadedState.c.saveState,
remove: loadedState.c.remove,
rename: loadedState.c.rename,
save: loadedState.c.save
} :
undefined, true);
if (this_1.c.createState) {
this_1.c.createState(stateConfig, loadedState);
}
var newState = new StateRestore(this_1.s.dt, stateConfig, state, loadedState, true, successCallback);
$(this_1.s.dt.table().node()).on('dtsr-modal-inserted', function () {
newState.dom.confirmation.one('dtsr-remove', function () { return _this._removeCallback(newState.s.identifier); });
newState.dom.confirmation.one('dtsr-rename', function () { return _this._collectionRebuild(); });
Expand Down Expand Up @@ -517,7 +525,7 @@ var StateRestoreCollection = /** @class */ (function () {
if (split.includes('removeState') && (!this.c.remove || !state.c.remove)) {
split.splice(split.indexOf('removeState'), 1);
}
stateButtons.push({
var buttonConfig = {
_stateRestore: state,
attr: {
title: state.s.identifier
Expand All @@ -528,7 +536,11 @@ var StateRestoreCollection = /** @class */ (function () {
extend: 'stateRestore',
text: StateRestore.entityEncode(state.s.identifier),
popoverTitle: StateRestore.entityEncode(state.s.identifier)
});
};
if (this.c.createButton) {
this.c.createButton(buttonConfig, state.s.savedState);
}
stateButtons.push(buttonConfig);
}
}
button.collectionRebuild(stateButtons);
Expand Down Expand Up @@ -1024,7 +1036,9 @@ var StateRestoreCollection = /** @class */ (function () {
searchBuilder: false,
searchPanes: false,
select: false
}
},
createButton: null,
createState: null
};
return StateRestoreCollection;
}());
Expand Down
43 changes: 30 additions & 13 deletions js/dataTables.stateRestore.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ var DataTable = $.fn.dataTable;
dt: table,
identifier: identifier,
isPreDefined: isPreDefined,
savedState: null,
savedState: state,
tableId: state && state.stateRestore ? state.stateRestore.tableId : undefined
};
this.dom = {
Expand Down Expand Up @@ -803,13 +803,13 @@ var DataTable = $.fn.dataTable;
duplicateError: 'A state with this name already exists.',
emptyError: 'Name cannot be empty.',
emptyStates: 'No saved states',
removeConfirm: 'Are you sure you want to remove %s?',
removeConfirm: 'Are you sure you want to remove "%s"?',
removeError: 'Failed to remove state.',
removeJoiner: ' and ',
removeSubmit: 'Remove',
removeTitle: 'Remove State',
renameButton: 'Rename',
renameLabel: 'New Name for %s:',
renameLabel: 'New Name for "%s":',
renameTitle: 'Rename State'
},
modalCloseButton: true,
Expand Down Expand Up @@ -850,7 +850,9 @@ var DataTable = $.fn.dataTable;
searchBuilder: false,
searchPanes: false,
select: false
}
},
createButton: null,
createState: null
};
return StateRestore;
}());
Expand Down Expand Up @@ -1284,10 +1286,18 @@ var DataTable = $.fn.dataTable;
that._collectionRebuild();
};
var loadedState = preDefined[state];
var newState = new StateRestore(this_1.s.dt, $$1.extend(true, {}, this_1.c, loadedState.c !== undefined ?
{ saveState: loadedState.c.saveState } :
undefined, true), state, loadedState, true, successCallback);
newState.s.savedState = loadedState;
var stateConfig = $$1.extend(true, {}, this_1.c, loadedState.c !== undefined ?
{
saveState: loadedState.c.saveState,
remove: loadedState.c.remove,
rename: loadedState.c.rename,
save: loadedState.c.save
} :
undefined, true);
if (this_1.c.createState) {
this_1.c.createState(stateConfig, loadedState);
}
var newState = new StateRestore(this_1.s.dt, stateConfig, state, loadedState, true, successCallback);
$$1(this_1.s.dt.table().node()).on('dtsr-modal-inserted', function () {
newState.dom.confirmation.one('dtsr-remove', function () { return _this._removeCallback(newState.s.identifier); });
newState.dom.confirmation.one('dtsr-rename', function () { return _this._collectionRebuild(); });
Expand Down Expand Up @@ -1373,7 +1383,7 @@ var DataTable = $.fn.dataTable;
if (split.includes('removeState') && (!this.c.remove || !state.c.remove)) {
split.splice(split.indexOf('removeState'), 1);
}
stateButtons.push({
var buttonConfig = {
_stateRestore: state,
attr: {
title: state.s.identifier
Expand All @@ -1384,7 +1394,11 @@ var DataTable = $.fn.dataTable;
extend: 'stateRestore',
text: StateRestore.entityEncode(state.s.identifier),
popoverTitle: StateRestore.entityEncode(state.s.identifier)
});
};
if (this.c.createButton) {
this.c.createButton(buttonConfig, state.s.savedState);
}
stateButtons.push(buttonConfig);
}
}
button.collectionRebuild(stateButtons);
Expand Down Expand Up @@ -1880,7 +1894,9 @@ var DataTable = $.fn.dataTable;
searchBuilder: false,
searchPanes: false,
select: false
}
},
createButton: null,
createState: null
};
return StateRestoreCollection;
}());
Expand Down Expand Up @@ -2147,8 +2163,9 @@ var DataTable = $.fn.dataTable;
0;
});
var button = dt.button('SaveStateRestore:name');
var stateButtons = button[0] !== undefined && button[0].inst.c.buttons[0].buttons !== undefined ?
button[0].inst.c.buttons[0].buttons :
var buttonIndex = parseInt(button.index());
var stateButtons = button[0] !== undefined && button[0].inst.c.buttons[buttonIndex].buttons !== undefined ?
button[0].inst.c.buttons[buttonIndex].buttons :
[];
// remove any states from the previous rebuild - if they are still there they will be added later
for (var i = 0; i < stateButtons.length; i++) {
Expand Down
2 changes: 1 addition & 1 deletion js/dataTables.stateRestore.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions js/dataTables.stateRestore.min.mjs

Large diffs are not rendered by default.

43 changes: 30 additions & 13 deletions js/dataTables.stateRestore.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ let $ = jQuery;
dt: table,
identifier: identifier,
isPreDefined: isPreDefined,
savedState: null,
savedState: state,
tableId: state && state.stateRestore ? state.stateRestore.tableId : undefined
};
this.dom = {
Expand Down Expand Up @@ -763,13 +763,13 @@ let $ = jQuery;
duplicateError: 'A state with this name already exists.',
emptyError: 'Name cannot be empty.',
emptyStates: 'No saved states',
removeConfirm: 'Are you sure you want to remove %s?',
removeConfirm: 'Are you sure you want to remove "%s"?',
removeError: 'Failed to remove state.',
removeJoiner: ' and ',
removeSubmit: 'Remove',
removeTitle: 'Remove State',
renameButton: 'Rename',
renameLabel: 'New Name for %s:',
renameLabel: 'New Name for "%s":',
renameTitle: 'Rename State'
},
modalCloseButton: true,
Expand Down Expand Up @@ -810,7 +810,9 @@ let $ = jQuery;
searchBuilder: false,
searchPanes: false,
select: false
}
},
createButton: null,
createState: null
};
return StateRestore;
}());
Expand Down Expand Up @@ -1244,10 +1246,18 @@ let $ = jQuery;
that._collectionRebuild();
};
var loadedState = preDefined[state];
var newState = new StateRestore(this_1.s.dt, $$1.extend(true, {}, this_1.c, loadedState.c !== undefined ?
{ saveState: loadedState.c.saveState } :
undefined, true), state, loadedState, true, successCallback);
newState.s.savedState = loadedState;
var stateConfig = $$1.extend(true, {}, this_1.c, loadedState.c !== undefined ?
{
saveState: loadedState.c.saveState,
remove: loadedState.c.remove,
rename: loadedState.c.rename,
save: loadedState.c.save
} :
undefined, true);
if (this_1.c.createState) {
this_1.c.createState(stateConfig, loadedState);
}
var newState = new StateRestore(this_1.s.dt, stateConfig, state, loadedState, true, successCallback);
$$1(this_1.s.dt.table().node()).on('dtsr-modal-inserted', function () {
newState.dom.confirmation.one('dtsr-remove', function () { return _this._removeCallback(newState.s.identifier); });
newState.dom.confirmation.one('dtsr-rename', function () { return _this._collectionRebuild(); });
Expand Down Expand Up @@ -1333,7 +1343,7 @@ let $ = jQuery;
if (split.includes('removeState') && (!this.c.remove || !state.c.remove)) {
split.splice(split.indexOf('removeState'), 1);
}
stateButtons.push({
var buttonConfig = {
_stateRestore: state,
attr: {
title: state.s.identifier
Expand All @@ -1344,7 +1354,11 @@ let $ = jQuery;
extend: 'stateRestore',
text: StateRestore.entityEncode(state.s.identifier),
popoverTitle: StateRestore.entityEncode(state.s.identifier)
});
};
if (this.c.createButton) {
this.c.createButton(buttonConfig, state.s.savedState);
}
stateButtons.push(buttonConfig);
}
}
button.collectionRebuild(stateButtons);
Expand Down Expand Up @@ -1840,7 +1854,9 @@ let $ = jQuery;
searchBuilder: false,
searchPanes: false,
select: false
}
},
createButton: null,
createState: null
};
return StateRestoreCollection;
}());
Expand Down Expand Up @@ -2107,8 +2123,9 @@ let $ = jQuery;
0;
});
var button = dt.button('SaveStateRestore:name');
var stateButtons = button[0] !== undefined && button[0].inst.c.buttons[0].buttons !== undefined ?
button[0].inst.c.buttons[0].buttons :
var buttonIndex = parseInt(button.index());
var stateButtons = button[0] !== undefined && button[0].inst.c.buttons[buttonIndex].buttons !== undefined ?
button[0].inst.c.buttons[buttonIndex].buttons :
[];
// remove any states from the previous rebuild - if they are still there they will be added later
for (var i = 0; i < stateButtons.length; i++) {
Expand Down
5 changes: 3 additions & 2 deletions js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,9 @@ DataTable.ext.buttons.createState = {
0;
});
var button = dt.button('SaveStateRestore:name');
var stateButtons = button[0] !== undefined && button[0].inst.c.buttons[0].buttons !== undefined ?
button[0].inst.c.buttons[0].buttons :
var buttonIndex = parseInt(button.index());
var stateButtons = button[0] !== undefined && button[0].inst.c.buttons[buttonIndex].buttons !== undefined ?
button[0].inst.c.buttons[buttonIndex].buttons :
[];
// remove any states from the previous rebuild - if they are still there they will be added later
for (var i = 0; i < stateButtons.length; i++) {
Expand Down

0 comments on commit a3902ac

Please sign in to comment.