Skip to content

Commit 0886991

Browse files
committed
Enhances the formModal to allow event callback for checking if there are changes on the content of the formModel and also for taking action for reverting the data. See #71241
1 parent daa1524 commit 0886991

File tree

3 files changed

+27
-5
lines changed

3 files changed

+27
-5
lines changed

public/cui.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45070,6 +45070,12 @@ CUI.FormModal = (function(superClass) {
4507045070
};
4507145071
})(this)
4507245072
}
45073+
},
45074+
hasChanges: {
45075+
check: Function
45076+
},
45077+
revertData: {
45078+
check: Function
4507345079
}
4507445080
});
4507545081
};
@@ -45093,7 +45099,7 @@ CUI.FormModal = (function(superClass) {
4509345099
}
4509445100
opts.pane.footer_right = btn;
4509545101
mod = new CUI.Modal(opts);
45096-
if (this.__orig_set_data) {
45102+
if (this.__orig_set_data || this._hasChanges) {
4509745103
CUI.Events.listen({
4509845104
type: "data-changed",
4509945105
node: mod,
@@ -45112,6 +45118,10 @@ CUI.FormModal = (function(superClass) {
4511245118
};
4511345119

4511445120
FormModal.prototype.revertData = function() {
45121+
if (this._revertData) {
45122+
this._revertData(this);
45123+
return this;
45124+
}
4511545125
CUI.util.assert(this.__orig_set_data, "Form.revertData", "Only supported with opts.name set and opts.data PlainObject.", {
4511645126
opts: this.opts
4511745127
});
@@ -45150,6 +45160,9 @@ CUI.FormModal = (function(superClass) {
4515045160
};
4515145161

4515245162
FormModal.prototype.hasChanges = function() {
45163+
if (this._hasChanges) {
45164+
return this._hasChanges(this, this.getData());
45165+
}
4515345166
if (this.__orig_set_data) {
4515445167
return JSON.stringify(this.__orig_data) !== JSON.stringify(this.__orig_set_data[this._name]);
4515545168
} else {
@@ -45160,7 +45173,7 @@ CUI.FormModal = (function(superClass) {
4516045173
FormModal.prototype.getPopoverOpts = function() {
4516145174
var onCancel, pop_opts;
4516245175
pop_opts = CUI.util.copyObject(this._modal, true);
45163-
if (pop_opts.cancel && this.__orig_set_data) {
45176+
if (pop_opts.cancel && (this.__orig_set_data || this._hasChanges)) {
4516445177
onCancel = pop_opts.onCancel;
4516545178
pop_opts.onCancel = (function(_this) {
4516645179
return function(ev, modal) {

public/cui.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/elements/FormModal/FormModal.coffee

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ class CUI.FormModal extends CUI.FormPopover
2525
text: "Ok"
2626
check: (v) =>
2727
CUI.util.isPlainObject(v)
28+
hasChanges:
29+
check: Function
30+
revertData:
31+
check: Function
2832

2933
initPopover: (opts) ->
3034

@@ -48,7 +52,7 @@ class CUI.FormModal extends CUI.FormPopover
4852

4953
mod = new CUI.Modal(opts)
5054

51-
if @__orig_set_data
55+
if @__orig_set_data or @_hasChanges
5256
CUI.Events.listen
5357
type: "data-changed"
5458
node: mod
@@ -61,6 +65,9 @@ class CUI.FormModal extends CUI.FormPopover
6165
mod
6266

6367
revertData: ->
68+
if @_revertData
69+
@_revertData(@)
70+
return @
6471
CUI.util.assert(@__orig_set_data, "Form.revertData", "Only supported with opts.name set and opts.data PlainObject.", opts: @opts)
6572
delete(@__data)
6673
if @__orig_data
@@ -92,6 +99,8 @@ class CUI.FormModal extends CUI.FormPopover
9299
super()
93100

94101
hasChanges: ->
102+
if @_hasChanges
103+
return @_hasChanges(@, @getData())
95104
if @__orig_set_data
96105
JSON.stringify(@__orig_data) != JSON.stringify(@__orig_set_data[@_name])
97106
else
@@ -100,7 +109,7 @@ class CUI.FormModal extends CUI.FormPopover
100109
getPopoverOpts: ->
101110
pop_opts = CUI.util.copyObject(@_modal, true)
102111

103-
if pop_opts.cancel and @__orig_set_data
112+
if pop_opts.cancel and (@__orig_set_data or @_hasChanges)
104113
onCancel = pop_opts.onCancel
105114
pop_opts.onCancel = (ev, modal) =>
106115
dfr = new CUI.Deferred()

0 commit comments

Comments
 (0)