function context/scope issue
In my widget I have an instance of UI dialog with button OK which triggers "onOk" event in my widget.
Before triggering my event I set a flag "inProgess" to prevent multiple callbacks.
And there lies my problem.
When i try to call "succededFunction" argument in function attached to onOk event:
- function InfoOk(ev, args) {
- args.succededFunction();
- //setTimeout(args.succededFunction, 1);
- }
It provides (a copy of?) my widget in context but without attached flag and original
widget keeps the flag on and prevents repeated ok callbacks which is the purpose of my widget.
The funny thing is if "succededFunction" is called in setTimeout function it works like expected(shuts down the flag).
Anyone has a clue?
- _create: function () {
- $.myCompany.controlBase.prototype._create.apply(this, arguments);
- var self = this;
- this.dialog = $("#dialog").dialog({
- autoOpen: false,
- buttons: {
- "Ok": function (ev, args) {
- if (!self.inProgress)
- self.inProgress = !(false === self._trigger("onOk", null, {
- dialog: self.dialog,
- succededFunction: function () {
- self.inProgress = false;
- self._trigger('onDialogSucceded', null, { dialog: self.dialog });
- self.dialog.dialog('close');
- },
- failFunction: function (err) {
- self.inProgress = false;
- $.myCompany.controlBase.prototype._onError.apply(self, arguments);
- },
- item: self.item
- }));
- },
- "Cancel": function () { $(this).dialog("close"); }
- },
- title: self.options.title
- });
- },