/*
 COPYRIGHT 2009 ESRI

 TRADE SECRETS: ESRI PROPRIETARY AND CONFIDENTIAL
 Unpublished material - all rights reserved under the
 Copyright Laws of the United States and applicable international
 laws, treaties, and conventions.

 For additional information, contact:
 Environmental Systems Research Institute, Inc.
 Attn: Contracts and Legal Services Department
 380 New York Street
 Redlands, California, 92373
 USA

 email: contracts@esri.com
 */
//>>built
require({cache:{"url:esri/dijit/editing/templates/AttachmentEditor.html":"<div class=\"attachmentEditor\">\r\n    <br />\r\n    <div>\r\n        <b>${NLS_attachments}</b>\r\n        <hr />\r\n        <div dojoAttachPoint=\"_attachmentError\" style='color:red;display:none'></div>\r\n        <br />\r\n        <span dojoAttachPoint='_attachmentList' style='word-wrap: break-word;'></span>\r\n        <br><br>\r\n        <form dojoAttachPoint='_uploadForm'> ${NLS_add}:&nbsp;&nbsp;<input type='file' name='attachment' dojoAttachPoint='_uploadField' /> </form>\r\n    </div>\r\n</div>"}});define("esri/dijit/editing/AttachmentEditor",["require","dojo/_base/declare","dojo/_base/lang","dojo/_base/connect","dojo/_base/array","dojo/_base/kernel","dojo/has","dojo/query","dojo/io-query","dojo/dom-attr","dijit/_Widget","dijit/_Templated","esri/kernel","esri/lang","esri/domUtils","dojo/text!esri/dijit/editing/templates/AttachmentEditor.html","dojo/i18n!esri/nls/jsapi","dojo/NodeList-dom"],function(_1,_2,_3,_4,_5,_6,_7,_8,_9,_a,_b,_c,_d,_e,_f,_10,_11){var AE=_2([_b,_c],{declaredClass:"esri.dijit.editing.AttachmentEditor",widgetsInTemplate:true,templateString:_10,basePath:_1.toUrl("esri/dijit/editing")+"/",_listHtml:"<span id='node_${oid}_${attid}'><a href='${href}' target='_blank'>${name}</a>",_deleteBtnHtml:"(<span style='cursor:pointer;color:red;font-weight:bold;' class='deleteAttachment' id='${attid}');'>X</span>)",_endHtml:"<br/></span>",_aeConnects:[],_layerEditingCapChecked:{},_layerEditingCap:{},constructor:function(_12,_13){_3.mixin(this,_11.widgets.attachmentEditor);},startup:function(){this.inherited(arguments);this._uploadField_connect=_4.connect(this._uploadField,"onchange",this,"_addAttachment");this._uploadFieldFocus_connect=_4.connect(this._uploadField,"onfocus",_3.hitch(this,function(e){_f.hide(this._attachmentError);}));},destroy:function(){_5.forEach(this._aeConnects,_4.disconnect);_4.disconnect(this._uploadField_connect);_4.disconnect(this._uploadFieldFocus_connect);this.inherited(arguments);},showAttachments:function(_14,_15){var _16=this._attachmentList;_16.innerHTML=this.NLS_none;this._uploadField.value="";_5.forEach(this.domNode.children,function(_17,idx){_f.show(_17);});_f.hide(this._attachmentError);if(!_14){return;}this._featureLayer=_14.getLayer()||_15;if(!this._featureLayer){return;}if(this._featureLayer.declaredClass!=="esri.layers.FeatureLayer"||!this._featureLayer.getEditCapabilities){_f.hide(this._uploadForm);_5.forEach(this.domNode.children,function(_18,idx){_f.hide(_18);});return;}this._currentLayerId=this._featureLayer.id;if(!this._layerEditingCapChecked[this._currentLayerId]){this._layerEditingCap[this._currentLayerId]=this._featureLayer.getEditCapabilities();this._layerEditingCapChecked[this._currentLayerId]=true;}this._featureCanUpdate=this._featureLayer.getEditCapabilities({feature:_14}).canUpdate;this._oid=_14.attributes[this._featureLayer.objectIdField];this._getAttachments(_14);},_getAttachments:function(_19){if(!this._featureLayer||!this._featureLayer.queryAttachmentInfos){return;}this._featureLayer.queryAttachmentInfos(this._oid,_3.hitch(this,"_onQueryAttachmentInfosComplete"));},_addAttachment:function(){_f.hide(this._attachmentError);if(!this._featureLayer||!this._featureLayer.addAttachment){return;}this._featureLayer.addAttachment(this._oid,this._uploadForm,_3.hitch(this,"_onAddAttachmentComplete"),_3.hitch(this,"_onAddAttachmentError"));},_deleteAttachment:function(oid,_1a){this._featureLayer.deleteAttachments(oid,[_1a],_3.hitch(this,"_onDeleteAttachmentComplete"));},_onQueryAttachmentInfosComplete:function(_1b){var _1c=this._listHtml+this._deleteBtnHtml+this._endHtml;this._uploadForm.style.display="block";if((!this._featureCanUpdate&&this._layerEditingCap[this._currentLayerId].canUpdate)||(!this._layerEditingCap[this._currentLayerId].canCreate&&!this._layerEditingCap[this._currentLayerId].canUpdate)){_1c=this._listHtml+this._endHtml;this._uploadForm.style.display="none";}else{if(this._layerEditingCap[this._currentLayerId].canCreate&&!this._layerEditingCap[this._currentLayerId].canUpdate){_1c=this._listHtml+this._endHtml;}}var _1d=this._attachmentList,_1e=_5.map(_1b,_3.hitch(this,function(_1f){return _e.substitute({href:_1f.url,name:_1f.name,oid:_1f.objectId,attid:_1f.id},_1c);}));_1d.innerHTML=_1e.join("")||this.NLS_none;this._updateConnects();},_onAddAttachmentComplete:function(_20){var _21=this._uploadField;var _22=_21.value;var pos=_22.lastIndexOf("\\");if(pos>-1){_22=_22.substring(pos+1,_22.length);}_22=_22.replace(/\ /g,"_");var _23=this._attachmentList,_24=_9.objectToQuery({gdbVersion:this._featureLayer.gdbVersion,token:this._featureLayer._getToken()});var _25=this._listHtml+this._deleteBtnHtml+this._endHtml;if(this._layerEditingCap[this._currentLayerId].canCreate&&!this._layerEditingCap[this._currentLayerId].canUpdate){_25=this._listHtml+this._endHtml;}var _26=_e.substitute({href:this._featureLayer._url.path+"/"+_20.objectId+"/attachments/"+_20.attachmentId+(_24?("?"+_24):""),name:_22,oid:_20.objectId,attid:_20.attachmentId},_25);_23.innerHTML=_23.innerHTML==this.NLS_none?_26:(_23.innerHTML+_26);this._updateConnects();_21.value="";},_onAddAttachmentError:function(_27){if(_27&&_e.isDefined(_27.code)){var _28,_29=this._attachmentError;if(_27.code===400){_28=this.NLS_fileNotSupported;}else{_28=_27.message||(_27.details&&_27.details.length&&_27.details[0]);}_a.set(_29,"innerHTML",(_28||this.NLS_error));_f.show(_29);}},_onDeleteAttachmentComplete:function(_2a){var _2b=_5.every(_2a,function(_2c){return _2c.success;}),_2d=this._attachmentList;if(_2b){_6.query("#node_"+_2a[0].objectId+"_"+_2a[0].attachmentId).orphan();if(!_2d.children||!_2d.children.length){_2d.innerHTML=this.NLS_none;}}},_updateConnects:function(){_5.forEach(this._aeConnects,_4.disconnect);_6.query(".deleteAttachment").forEach(function(_2e){this._aeConnects.push(_4.connect(_2e,"onclick",_3.hitch(this,"_deleteAttachment",this._oid,_2e.id)));},this);}});if(_7("extend-esri")){_3.setObject("dijit.editing.AttachmentEditor",AE,_d);}return AE;});