.........
survey.ImageUploader = function (configObj) {
var thisObject = this;
configObj = configObj || {};
var fileUploadField = new Ext.form.FileUploadField({
allowBlank: false,
buttonCgf: { text: 'Find' },
emptyText: 'Select a file...',
fieldLabel: 'Select a file',
name: 'file'
});
var referenceField = new Ext.form.TextField({
allowBlank: true,
fieldLabel: 'File Description',
name: 'document.ReferenceNotes',
value: ''
});
var hiddenLocationField = new Ext.form.Hidden({
hidden: true,
hideLabel: true,
name: 'locationCode',
value: configObj.locationCode
});
var hiddenSectionField = new Ext.form.Hidden({
hidden: true,
hideLabel: true,
name: 'sectionName',
value: configObj.sectionName
});
var url = Survey.URL.Survey.addImageToSectionUrl();
Ext.apply(this, {
autoHeight: true,
items: [
fileUploadField,
referenceField,
hiddenLocationField,
hiddenSectionField
],
defaults: { width: 220 },
fileUpload: true,
labelWidth: 200,
standardSubmit: true,
title: 'Add Images to This Section (To upload multiple, repeat the add image process)',
url: url,
buttons: [{
text: 'Add Image',
formBind: true,
handler: function () {
//manually set the ACTION for our form
thisObject.getForm().getEl().dom.action = url;
var submitMask = new Ext.LoadMask(
thisObject.getEl(),
{ msg: 'Uploading...' }
);
submitMask.show();
//submit the form
Ext.Ajax.request({
url: url,
isUpload: true,
form: thisObject.getForm().getEl(),
success: function (response, action) {
submitMask.hide();
if (response.responseXML.title === '') {
//I guess this works for sniffing failure...
referenceField.setValue('');
fileUploadField.setValue('');
Ext.Msg.alert(
'Success!',
'Document uploaded successfully');
}
else {
Ext.Msg.alert(
'Error',
'Error uploading document:<br />' + GFX.Util.getErrorText(response)
);
}
}
});
}
}]
});
Survey.ImageUploader.superclass.constructor.apply(this, arguments);
};
Ext.extend(Survey.ImageUploader, Ext.form.FormPanel, {});
Ext.reg('survey-uploader', Survey.ImageUploader);
///////////////////////////////////////////////////
[HttpPost]
[RequireOperation(SubmitSurvey.OperationName)]
public virtual ActionResult AddImageToSection(Guid locationCode, string sectionName, HttpPostedFileBase file, DocumentDto document)
{
document.Name = file.FileName;
document.MimeType = file.ContentType;
document.ReferenceNotes = GetReferenceNotes(sectionName, document.ReferenceNotes);
var request = NewDocumentRequest.BuildRequest(CharacteristicOwnerType.Location, locationCode, file.InputStream.GetBytes(), document, RequestContext);
var response = (NewEntityResponse)RequestProcessor.Process(request);
// Must use ExtNewEntityFormSubmissionJson since the caller was a form submission
return ExtNewEntityFormSubmissionJson(response.EntityCode);
}