Extjs 3.3 IE8 chained events is breaking - javascript

This one is wired.
This fires from a grid toolbar button click:
// fires when the client hits the add attachment button.
onAddAttachmentClick: function () {
var uploadAttachmentsWindow = new Nipendo.ProformaInvoice.Attachment.UploadWindow({
invoice: this.invoice,
maxFileSizeInMB: this.maxFileSizeInMB
});
uploadAttachmentsWindow.on('uploadcomplete', function (win, message) {
if (message.msg !== 'success') {
return;
}
win.close();
var store = this.getStore();
store.setBaseParam('useCache', false);
store.load();
this.fireEvent(
'attachmentuploaded',
this.invoice.ProformaInvoiceNumber,
this.invoice.VendorSiteID,
this.invoice.CustomerSiteID);
}, this);
uploadAttachmentsWindow.show();
} // eo onAddAttachmentClick
This is what happens on the uploadcomplete event:
this.uploadBtn.on('click', function () {
var form = this.uploadForm.getForm();
if (!form.isValid()) {
return;
}
form.submit({
url: 'XXX.ashx',
waitMsg: Nipendo.Localization.UploadingAttachment,
scope: this,
success: function (form, action) {
this.fireEvent('uploadcomplete', this, {
msg: 'success',
response: action.response
});
},
failure: function (form, action) {
switch (action.failureType) {
case Ext.form.Action.CLIENT_INVALID:
this.fireEvent('uploadcomplete', this, {
msg: 'Form fields may not be submitted with invalid values'
});
break;
case Ext.form.Action.CONNECT_FAILURE:
this.fireEvent('uploadcomplete', this, {
msg: 'Ajax communication failed'
});
break;
case Ext.form.Action.SERVER_INVALID:
Ext.Msg.alert(action.result.title, action.result.message);
this.fireEvent('uploadcomplete', this, {
msg: action.result.message
});
break;
}
}
});
}, this);
On IE 8 I am getting this error in the debugger:
I have no idea what object is missing... from my check they are all defined.
Any idea anyone?
Notice that I have an event firing from a listener (I am suspecting it to be the root of the problem).
It is hard to see but the error occuers in ext-all.js in the fire method.

I have found the answer in : https://stackoverflow.com/a/3584887/395890
Problem was I was listing to events is 2 different windows, that is not possible in Ext.
What I have done to solv it was to call the opner window from the pop up window to notify about changes.

Related

this.up() is not function EXTJS

I want to submit my data to server from controller.
Code is as follows:
renterForms: function() {
var items3 = [{
xtype:'foresto-renterdata',
scrollable: true,
scope: this,
renderTo: 'mainPart',
handler: function() {
this.action3.hide();
}
},{
text: 'Submit',
ui: 'confirm',
scope: this,
handler: function() {
var form = this.up('foresto-rentertype');
if (form.isValid()) {
form.submit({
success: function(form, action) {
Ext.Msg.alert('Success', action.result.msg);
},
failure: function(form, action) {
Ext.Msg.alert('Failed', action.result.msg);
}
});
} else { /
Ext.Msg.alert('Error', 'Please correct form errors.')
}
}
in chrome debugger, I see next error:
Uncaught TypeError: this.up is not a function.
What is wrong? Is this a good way to get and submit data?
P.S. url for POST request define in code of form
scope: this
this is the actual issue which is messing up with scope inside handler function. Remove it and it will resolve the up function.
You can see the behavior with scope with following example fiddle:
https://fiddle.sencha.com/#view/editor&fiddle/2nhv
When "scope: this" is defined, then scope while building the component will be used and injected inside the handler function. It is equivalent to explicitly writing handlerFn.bind(this) which simply binds the different scope and returns a new function.

May i use sendResponce/onMessage within event page? (bug?)

Seems like i can send message, but can't receive response. Everything works fine when i use sendMessage from another context (popup, content script, etc).
Is it bug?
event-page.js
(function (chrome, undefined) {
'use strict';
chrome.runtime.onMessage.addListener(function (message, sender, sendResponse) {
console.info('onMessage: ' + message.method);
switch (message.method) {
case 'withResponseAsync':
setTimeout(function () {
sendResponse({some: 'response'});
}, 1000);
return true;
break;
case 'withResponse':
sendResponse({some: 'response'});
break;
}
});
var showResponse = function (response) {
if (chrome.runtime.lastError) {
console.error(chrome.runtime.lastError.message);
}
console.info(response);
};
// ok. onMessage: noResponse
chrome.runtime.sendMessage({method: 'noResponse'});
// fail. Could not establish connection. Receiving end does not exist.
chrome.runtime.sendMessage({method: 'withResponse'}, showResponse);
// fail. Could not establish connection. Receiving end does not exist.
chrome.runtime.sendMessage({method: 'withResponseAsync'}, showResponse);
})(chrome);

Async operations in modal callback

I'm using the semantic-ui modal to allow users to insert data. It has an onApprove callback which allows you to return false to keep the modal open if there are any problems. My data is inserted into a DB, which returns false if there's any error. What's the best way of keeping the modal open if there's an error during this async operation?
Here's my code (coffeescript):
$('#verification-modal')
.modal('setting', {
detachable: false,
onApprove: validateVerificationForm
closable: false
})
validateVerificationForm = () ->
formData = $('.form').serializeArray()
formatted = format($formData);
ID_Details.insert(formatted, (errs, id) ->
if errs
false
else
true
Obviously the anonymous function is returning true/false into the context of the function. What's the best way to return it to the modal?
You can use a local reactive variable:
var data = new ReactiveDict();
Template.modalTemplate.created = function() {
data.set('isError', false);
};
Template.modalTemplate.helpers({
isError: function() {
return data.get('isError');
},
});
var yourMethodWithAsync = function() {
...
async(..., function(error) {
if(error) {
data.set('isError', true);
}
...
});
};

Validate function is not working in backbone

I'm trying to log an error when an attribute of a variable is changed, but the validate is never being triggered, this is my code:
Person = Backbone.Model.extend({
initialize: function() {
console.log("hello world");
this.bind('change:name', function() {
console.log(this.get('name') + ' is now the value for the name');
});
this.bind('error', function(model, error) {
console.log(error);
});
},
defaults: {
name: 'Bob Hope',
height: 'unknown'
},
validate: function(attributes) {
if(attributes.name == 'blank'){
return 'no';
}
}
});
var person = new Person();
person.set({name: 'blank'});
I have even tried called set like this:
person.set({name: 'blank'}, {validate: true});
but that doesn't work either, I'm using version 1.0.0.
As per the documentation:
By default validate is called before save, but can also be called
before set if {validate:true} is passed.
Also, the event that is triggered is invalid, not error, so try this:
this.bind('invalid', function(model, error) {
console.log(error);
});

How to prevent error alerts on Fine-Uploader?

Is there any way to prevent alerts where the onError callback is fired?
I only need to capture the error and display it in a different way
Yes, simply override the showMessage option.
For example:
var uploader = new qq.FineUploader({
request: {
endpoint: 'my/endpoint'
},
callbacks: {
onError: function(fileId, filename, reason, maybeXhr) {
//do something with the error
}
},
showMessage: function(message) {
//either include an empty body, or some other code to display (error) messages
}
});

Categories

Resources