// All material copyright ESRI, All Rights Reserved, unless otherwise specified.
// See http://js.arcgis.com/3.23/esri/copyright.txt for details.
//>>built
require({cache:{"url:esri/dijit/FeatureAttachments/templates/FeatureAttachments.html":'\x3cdiv\x3e\r\n  \x3cdiv class\x3d"${_css.contentContainer}"\x3e\r\n    \x3cdiv class\x3d"${_css.tabContainer}" data-dojo-attach-point\x3d "_tabContainer" data-dojo-type\x3d"dijit/layout/TabContainer"\x3e\r\n      \x3cdiv class\x3d"${_css.viewPane}" data-dojo-attach-point\x3d "_viewPane" data-dojo-type\x3d"dijit/layout/ContentPane" title\x3d"${_i18nStrings.view}" data-dojo-props\x3d"selected:true"\x3e\x3c/div\x3e\r\n      \x3cdiv class\x3d"${_css.addPane}" data-dojo-attach-point\x3d "_addPane" data-dojo-type\x3d"dijit/layout/ContentPane" title\x3d"${_i18nStrings.add}" data-dojo-props\x3d"disabled:true"\x3e\r\n        \x3cdiv class\x3d"${_css.addPaneContent}" data-dojo-attach-point\x3d "_addPaneContent"\x3e\r\n          \x3cinput class\x3d"${_css.dragDrop}" type\x3d"file" name\x3d"ft_attachment_input" size\x3d"40" data-dojo-attach-point\x3d"_fileInput"\x3e\x3c/input\x3e\r\n        \x3c/div\x3e\r\n      \x3c/div\x3e\r\n    \x3c/div\x3e\r\n    \x3cdiv class\x3d"${_css.menuContainer}"\x3e\r\n      \x3cbutton class\x3d\'${_css.formButton} ${_css.uploadButton} ${_css.hidden}\' data-dojo-attach-point\x3d"_uploadButton" data-dojo-type\x3d"dijit/form/Button" data-dojo-props\x3d"disabled:true"\x3e${_i18nStrings.upload}\x3c/button\x3e\r\n      \x3cdiv class\x3d"${_css.feedbackNode}" data-dojo-attach-point\x3d "_feedbackNode"\x3e\x3c/div\x3e\r\n      \x3cdiv class\x3d"${_css.loadingIndicator} ${_css.hidden}" data-dojo-attach-point\x3d"_loadingIndicator"\x3e\x3c/div\x3e\r\n    \x3c/div\x3e\r\n  \x3c/div\x3e\r\n\x3c/div\x3e'}});
define("esri/dijit/FeatureAttachments","../kernel ../lang dojo/_base/array dojo/_base/declare dojo/_base/lang dojo/Deferred dojo/dom-class dojo/dom-construct dojo/has dojo/io-query dojo/on dojo/string dijit/_TemplatedMixin dijit/_WidgetsInTemplateMixin dijit/_WidgetBase dojo/i18n!../nls/jsapi dojo/text!./FeatureAttachments/templates/FeatureAttachments.html dijit/form/Button dijit/layout/BorderContainer dijit/layout/TabContainer dijit/layout/ContentPane".split(" "),function(n,p,k,h,b,y,f,c,q,r,l,m,
t,u,v,w,x,z,A,B,C){h=h([v,t,u],{declaredClass:"esri.dijit.FeatureAttachments",baseClass:"esri-feature-attachments",templateString:x,layer:null,featureId:null,attachments:null,editable:!1,_editable:!1,_i18nStrings:w.widgets.FeatureAttachments,_css:{contentContainer:"esri-feature-attachments-container",menuContainer:"esri-feature-attachments-menu-container",tabContainer:"esri-feature-attachments-tab-container",formButton:"esri-feature-attachments-button dijitButton",uploadButton:"esri-feature-attachments-upload-button",
deleteButton:"icon-ui-close-circled",feedbackNode:"esri-feature-attachments-feedback",dragDrop:"esri-drag-drop",loadingIndicator:"esri-feature-attachments-loading-indicator",viewPane:"esri-feature-attachments-view-pane",viewPaneContent:"esri-feature-attachments-view-pane-content",addPane:"esri-feature-attachments-add-pane",addPaneContent:"esri-feature-attachments-add-pane-content",attachmentNode:"esri-attachment-node",attachmentNodeTextContainer:"esri-attachment-node-text-container",attachmentNodeTextName:"esri-attachment-node-text-name",
attachmentNodeTextSize:"esri-attachment-node-text-size",attachmentNodeDelete:"esri-attachment-node-delete",attachmentNodeIcon:"esri-attachment-node-icon",iconArchive:"esri-attachment-node-icon-archive",iconAudioVideo:"esri-attachment-node-icon-audiovideo",iconDocument:"esri-attachment-node-icon-document",iconImage:"esri-attachment-node-icon-image",iconOther:"esri-attachment-node-icon-other",hidden:"esri-feature-attachments-hidden"},_filetypeInfos:{categories:["archive","audioVideo","document","image",
"other"],groups:["zip 7z gz gtar tar tgz".split(" "),"wmf wps avi mpg mpe mpeg mov wmv aif mid rmi mp2 mp3 mp4 mpa mpv2 qt ra ram wav wma".split(" "),"doc docx dot xls xlsx xlt pdf ppt pptx txt".split(" "),"bmp ecw emf eps ps gif img jp2 jpc j2k jpf jpg jpeg jpe png psd raw sid tif tiff".split(" "),"vrml gml json xml mdb gdb geodatabase".split(" ")],styles:null},constructor:function(){this._updateViewContent=b.hitch(this,this._updateViewContent)},postMixInProperties:function(){this.inherited(arguments);
var a=this._css;this._filetypeInfos.styles={archive:a.iconArchive,audioVideo:a.iconAudioVideo,document:a.iconDocument,image:a.iconImage,other:a.iconOther};this.attachments&&Array.isArray(this.attachments)||this.set("attachments",[])},startup:function(){this.inherited(arguments);var a=this.layer;a&&a.loaded?this._setUpWidget():this.own(l.once(a,"load",b.hitch(this,this._setUpWidget)),l(a,"error",b.hitch(this,this._showError)))},destroy:function(){this.inherited(arguments)},resize:function(){this._tabContainer.resize()},
refresh:function(){this._updateFeedback();this._getAttachments().then(this._updateViewContent)},showAddPane:function(){this._tabContainer.selectChild(this._addPane)},showViewPane:function(){this._tabContainer.selectChild(this._viewPane)},_setUpWidget:function(){this._wireUpEvents();this._checkEditability();this.attachments&&0!==this.attachments.length?this._updateViewContent():this._getAttachments().then(this._updateViewContent)},_wireUpEvents:function(){this.own(l(this._uploadButton,"click",b.hitch(this,
this._addAttachment)),l(this._fileInput,"change",b.hitch(this,this._updateUploadButtonState)),this.watch("featureId",b.hitch(this,this._updateFeatureId)),this._tabContainer.watch("selectedChildWidget",b.hitch(this,this._updateUploadButtonDisplay)))},_checkEditability:function(){this.editable&&this.layer.isEditable&&(this.set("_editable",this.layer.isEditable()),this._addPane.set("disabled",!1))},_getAttachments:function(){this._showLoadingIndicator();return this._queryLayerForAttachments().then(b.hitch(this,
function(a){this.set("attachments",a);return a})).otherwise(b.hitch(this,function(a){this.set("attachements",[]);return[]}))},_updateFeatureId:function(){this.refresh()},_updateFeedback:function(a){this._feedbackNode.textContent=a||""},_showError:function(a){msg=a&&p.isDefined(a.code)&&400===a.code?this._i18nStrings.fileNotSupported:a||this._i18nStrings.uploadFail;this.emit("error",{message:msg});this._updateFeedback(msg);this._hideLoadingIndicator()},_addAttachment:function(){if(this._fileInput.files&&
this._fileInput.files[0]){this._showLoadingIndicator();this._updateFeedback(this._i18nStrings.uploading);this._uploadButton.setDisabled(!0);var a=this._fileInput.files[0],e=new FormData;e.append("attachment",a,a.name);this._addAttachmentToLayer(e).then(b.hitch(this,this._addAttachmentCallback)).otherwise(b.hitch(this,this._showError))}},_addAttachmentCallback:function(a){this._fileInput.value="";a.success?(!0===this._viewPane.disabled&&this._viewPane.set("disabled",!1),this._getAttachments().then(b.hitch(this,
function(){this._updateViewContent();this.emit("add-complete",{attachments:this.attachments,featureId:a.objectId,attachmentId:a.attachmentId})})),this._updateFeedback(this._i18nStrings.uploadSuccess),this._hideLoadingIndicator()):(this._updateFeedback(this._i18nStrings.uploadFail),this._hideLoadingIndicator(),this._showError(a.error))},_deleteAttachment:function(a,e){this._showLoadingIndicator();this._updateFeedback(this._i18nStrings.deleting);this._deleteAttachmentFromLayer(a).then(b.hitch(this,
this._deleteAttachmentCallback)).otherwise(b.hitch(this,this._showError,null))},_deleteAttachmentCallback:function(a){a[0]&&a[0].success?(this._getAttachments().then(b.hitch(this,function(){this._updateViewContent();this.emit("delete-complete",{attachments:this.attachments,featureId:a[0].objectId,attachmentId:a[0].attachmentId})})),this._updateFeedback(this._i18nStrings.deleteSuccess),this._hideLoadingIndicator()):(this._hideLoadingIndicator(),this._updateFeedback(this._i18nStrings.deleteFail),this._showError(a[0].error))},
_updateViewContent:function(){if(this.layer&&!isNaN(this.featureId)&&this.attachments){this.editable&&0===this.attachments.length&&this.showAddPane();var a=this._generateViewContent();this._viewPane.setContent(a);this._hideLoadingIndicator()}},_generateViewContent:function(){var a=this.attachments,e,b,d;e=this.layer._url.path+"/"+this.featureId+"/attachments/";b=this._getQueryString();d=c.create("div",{className:this._css.viewPaneContent});k.forEach(a,function(a){this._generateViewNode({attachment:a,
baseUrl:e,queryUrl:b,contentNode:d})},this);return d},_generateViewNode:function(a){var e=a.attachment,b=e.id,d=e.name,h=e.size,e=a.contentNode,g=this._css,f,k,m;m=a.baseUrl+b+a.queryUrl;a=c.create("div",{className:g.attachmentNode});c.create("div",{className:g.attachmentNodeIcon+" "+this._getIconClass(d)},a);f=c.create("div",{className:g.attachmentNodeTextContainer},a);k=c.create("span",{className:g.attachmentNodeTextName},f);c.create("a",{href:m,title:d,innerHTML:d,target:"_blank"},k);c.create("span",
{className:g.attachmentNodeTextSize,innerHTML:this._parseFileSize(h)},f);this._editable&&(d=c.create("div",{className:g.attachmentNodeDelete},a),c.create("span",{className:g.deleteButton},d),this.own(l(d,"click",this._deleteAttachment.bind(this,b))));c.place(a,e)},_showLoadingIndicator:function(){f.remove(this._loadingIndicator,this._css.hidden)},_hideLoadingIndicator:function(){f.add(this._loadingIndicator,this._css.hidden)},_showUploadButton:function(){f.remove(this._uploadButton.domNode,this._css.hidden)},
_hideUploadButton:function(){f.add(this._uploadButton.domNode,this._css.hidden)},_updateUploadButtonState:function(){this._updateFeedback();this._uploadButton.setDisabled(0===this._fileInput.value.length)},_updateUploadButtonDisplay:function(a,b,c){this._updateFeedback();c===this._addPane?this._showUploadButton():this._hideUploadButton()},_queryLayerForAttachments:function(){return this.layer.queryAttachmentInfos(this.featureId||0)},_addAttachmentToLayer:function(a){return this.layer.addAttachment(this.featureId,
a)},_deleteAttachmentFromLayer:function(a){return this.layer.deleteAttachments(this.featureId,[a])},_getIconClass:function(a){var b=a.substr(a.lastIndexOf(".")+1);a=this._filetypeInfos;var c=a.categories,d=-1;k.some(a.groups,function(a,e){if(-1!==a.indexOf(b.toLowerCase()))return d=e,!0});return a.styles[c[d]?c[d]:c[4]]},_parseFileSize:function(a){var b=this._i18nStrings,c=[b.kB,b.MB,b.GB,b.TB],d=-1;if(1E3>Math.abs(a))return m.substitute(b.B,{fileSize:a});do a/=1E3,++d;while(1E3<=Math.abs(a)&&d<c.length-
1);return m.substitute(c[d],{fileSize:a.toFixed(1)})},_getQueryString:function(){var a=r.objectToQuery({gdbVersion:this.layer.gdbVersion,token:this.layer._getToken()});return a?"?"+a:""}});q("extend-esri")&&b.setObject("dijit.FeatureAttachments",h,n);return h});