Hi,
I am new to Smart UI and try to do a simple experiment on command function. Here is my requirement: I am trying to add a button on the page, when click this button, will trigger "Add" command to open file selection dialog to select files for uploading. After upload successfully, refresh folder to show new added files. I can call "Add" command for addableType "144", but when I tried to refresh folder after upload successfully by promise status, it always refresh before the file selection dialog showing instead of the completion of upload. Could anyone help on it? The following is my code for the upload button click event:
$('#uploadfilebtn').on("click",function () {
// alert('before event');
var status = {
container: node,
collection: node.collection
};
// alert(status.collection);
var options = {
multiple: true,
addableType: 144 //type for adding documents
// addableTypeName: 'document'
};
/*var addCommand = commands.findWhere({
signature: 'Add'
});*/
var addCommand=commands.get('Add');
var promise =addCommand.execute(status, options);
promise.always(function () {
var succeeded = promise.state() === 'reserved';
alert( succeeded );
context.fetch();
});
// The following approach is not working either
/* var promiseFromCommand =addCommand.execute(status, options);
CommandHelper.handleExecutionResults(
promiseFromCommand, {
command: addCommand,
suppressSuccessMessage: status.forwardToTable || status.suppressSuccessMessage,
suppressFailMessage: status.suppressFailMessage
})
.done(function (nodes) {
if (nodes && !nodes[0].cancelled) {
eventArgs.newNodes = nodes;
alert('Add new file');
context.fetch();
//self.trigger('after:execute:command', eventArgs);
}
})
.fail(function (error) {
alert(error);
//self.trigger('after:execute:command', error);
});*/
});