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

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