/*
 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
 */

window[esri._dojoScopeName||"dojo"]._xdResourceLoaded(function(_1,_2,_3){return {depends:[["provide","esri.dijit.editing.AttachmentEditor"],["require","dojo.data.ItemFileReadStore"],["require","dojox.grid.DataGrid"]],defineResource:function(_4,_5,_6){if(!_4._hasResource["esri.dijit.editing.AttachmentEditor"]){_4._hasResource["esri.dijit.editing.AttachmentEditor"]=true;_4.provide("esri.dijit.editing.AttachmentEditor");_4.require("dojo.data.ItemFileReadStore");_4.require("dojox.grid.DataGrid");(function(){var _7=[_4.moduleUrl("esri.dijit.editing","css/attachment.css")];var _8=document.getElementsByTagName("head").item(0),_9,i,il=_7.length;for(i=0;i<il;i++){_9=document.createElement("link");_9.type="text/css";_9.rel="stylesheet";_9.href=_7[i];_8.appendChild(_9);}}());_4.declare("esri.dijit.editing.AttachmentEditor",[_5._Widget,_5._Templated],{widgetsInTemplate:true,templateString:"<div class=\"attachmentEditor\">\r\n    <br />\r\n    <div>\r\n        <b>${NLS_attachments}</b>\r\n        <hr />\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>\r\n",basePath:_4.moduleUrl("esri.dijit.editing"),_listHtml:"<span id='node_${oid}_${attid}'><a href='${href}' target='_blank'>${name}</a>(<span style='cursor:pointer;color:red;font-weight:bold;' class='deleteAttachment' id='${attid}');'>X</span>)<br/></span>",_aeConnects:[],constructor:function(_a,_b){_4.mixin(this,esri.bundle.widgets.attachmentEditor);},startup:function(){this.inherited(arguments);this._uploadField_connect=_4.connect(this._uploadField,"onchange",this,"_addAttachment");},destroy:function(){_4.forEach(this._aeConnects,_4.disconnect);_4.disconnect(this._uploadField_connect);this.inherited(arguments);},showAttachments:function(_c,_d){var _e=this._attachmentList;_e.innerHTML=this.NLS_none;this._uploadField.value="";if(!_c){return;}this._featureLayer=_c.getLayer()||_d;if(!this._featureLayer){return;}this._oid=_c.attributes[this._featureLayer.objectIdField];this._getAttachments(_c);},_getAttachments:function(_f){if(!this._featureLayer||!this._featureLayer.queryAttachmentInfos){return;}this._featureLayer.queryAttachmentInfos(this._oid,_4.hitch(this,"_onQueryAttachmentInfosComplete"));},_addAttachment:function(){if(!this._featureLayer||!this._featureLayer.addAttachment){return;}this._featureLayer.addAttachment(this._oid,this._uploadForm,_4.hitch(this,"_onAddAttachmentComplete"));},_deleteAttachment:function(oid,_10){this._featureLayer.deleteAttachments(oid,[_10],_4.hitch(this,"_onDeleteAttachmentComplete"));},_onQueryAttachmentInfosComplete:function(_11){var _12=this._attachmentList,_13=_4.map(_11,_4.hitch(this,function(_14){return esri.substitute({href:_14.url,name:_14.name,oid:_14.objectId,attid:_14.id},this._listHtml);}));_12.innerHTML=_13.join("")||this.NLS_none;this._updateConnects();},_onAddAttachmentComplete:function(_15){var _16=this._uploadField;var _17=_16.value;var pos=_17.lastIndexOf("\\");if(pos>-1){_17=_17.substring(pos+1,_17.length);}_17=_17.replace(/\ /g,"_");var _18=this._attachmentList,_19=_4.objectToQuery({gdbVersion:this._featureLayer.gdbVersion,token:this._featureLayer._getToken()});var _1a=esri.substitute({href:this._featureLayer._url.path+"/"+_15.objectId+"/attachments/"+_15.attachmentId+(_19?("?"+_19):""),name:_17,oid:_15.objectId,attid:_15.attachmentId},this._listHtml);_18.innerHTML=_18.innerHTML==this.NLS_none?_1a:(_18.innerHTML+_1a);this._updateConnects();_16.value="";},_onDeleteAttachmentComplete:function(_1b){var _1c=_4.every(_1b,function(_1d){return _1d.success;});if(_1c){_4.byId("node_"+_1b[0].objectId+"_"+_1b[0].attachmentId).innerHTML="";}},_updateConnects:function(){_4.forEach(this._aeConnects,_4.disconnect);_4.query(".deleteAttachment").forEach(function(_1e){this._aeConnects.push(_4.connect(_1e,"onclick",_4.hitch(this,"_deleteAttachment",this._oid,_1e.id)));},this);}});}}};});