]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - include/SugarFields/Fields/File/SugarFieldFile.js
Release 6.5.0
[Github/sugarcrm.git] / include / SugarFields / Fields / File / SugarFieldFile.js
1 /*********************************************************************************
2  * SugarCRM Community Edition is a customer relationship management program developed by
3  * SugarCRM, Inc. Copyright (C) 2004-2012 SugarCRM Inc.
4  *
5  * This program is free software; you can redistribute it and/or modify it under
6  * the terms of the GNU Affero General Public License version 3 as published by the
7  * Free Software Foundation with the addition of the following permission added
8  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
9  * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
10  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
11  *
12  * This program is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14  * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
15  * details.
16  *
17  * You should have received a copy of the GNU Affero General Public License along with
18  * this program; if not, see http://www.gnu.org/licenses or write to the Free
19  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20  * 02110-1301 USA.
21  *
22  * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
23  * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
24  *
25  * The interactive user interfaces in modified source and object code versions
26  * of this program must display Appropriate Legal Notices, as required under
27  * Section 5 of the GNU Affero General Public License version 3.
28  *
29  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
30  * these Appropriate Legal Notices must retain the display of the "Powered by
31  * SugarCRM" logo. If the display of the logo is not reasonably feasible for
32  * technical reasons, the Appropriate Legal Notices must display the words
33  * "Powered by SugarCRM".
34  ********************************************************************************/
35 if(typeof(SUGAR.field)=='undefined'){SUGAR.field=new Object();}
36 if(typeof(SUGAR.field.file)=='undefined'){SUGAR.field.file={deleteAttachment:function(elemBaseName,docTypeName,elem){ajaxStatus.showStatus(SUGAR.language.get("app_strings","LBL_REMOVING_ATTACHMENT"));elem.form.deleteAttachment.value=1;elem.form.action.value="deleteattachment";var callback=SUGAR.field.file.deleteAttachmentCallbackGen(elemBaseName,docTypeName);var success=function(data){if(data){callback(data.responseText);}}
37 YAHOO.util.Connect.setForm(elem.form);var cObj=YAHOO.util.Connect.asyncRequest('POST','index.php',{success:success,failure:success});elem.form.deleteAttachment.value=0;elem.form.action.value="";},deleteAttachmentCallbackGen:function(elemBaseName,docTypeName){return function(text){if(text=='true'){document.getElementById(elemBaseName+'_new').style.display='';ajaxStatus.hideStatus();document.getElementById(elemBaseName+'_old').innerHTML='';if(docTypeName){document.getElementById(docTypeName).disabled=false;}
38 document.getElementById(elemBaseName).value='';}else{document.getElementById(elemBaseName+'_new').style.display='none';ajaxStatus.flashStatus(SUGAR.language.get('app_strings','ERR_REMOVING_ATTACHMENT'),2000);}}},checkEapiLogin:function(res){var failedLogins=YAHOO.lang.JSON.parse(res.responseText);if(failedLogins.length==0){return;}
39 for(var idx in failedLogins){if(confirm(failedLogins[idx].label)){window.open(failedLogins[idx].checkURL,'EAPM_CHECK_'+idx);}else{document.getElementById(res.argument.docTypeName).value='Sugar';document.getElementById(res.argument.docTypeName).onchange();}}},setupEapiShowHide:function(elemBaseName,docTypeName,formName){var externalSearchToggle=function(){var moreElem=document.getElementById(elemBaseName+"_more");var hideMore=(moreElem.style.display=='none');if(hideMore){moreElem.style.display='';document.getElementById(elemBaseName+'_less').style.display='none';document.getElementById(elemBaseName+'_remoteNameSpan').style.display='none';document.getElementById(elemBaseName+'_file').disabled=false;}else{moreElem.style.display='none';document.getElementById(elemBaseName+'_less').style.display='';document.getElementById(elemBaseName+'_remoteNameSpan').style.display='';document.getElementById(elemBaseName+'_file').disabled=true;}}
40 var showHideFunc=function(){var docShowHideElem=document.getElementById(elemBaseName+"_externalApiSelector");var dropdownValue=document.getElementById(docTypeName).value;if(typeof(SUGAR.eapm)!='undefined'&&typeof(SUGAR.eapm[dropdownValue])!='undefined'&&typeof(SUGAR.eapm[dropdownValue].docSearch)!='undefined'&&SUGAR.eapm[dropdownValue].docSearch){docShowHideElem.style.display='';YAHOO.util.Connect.asyncRequest('GET','index.php?module=EAPM&action=CheckLogins&to_pdf=1&api='+dropdownValue,{success:SUGAR.field.file.checkEapiLogin,argument:{'elemBaseName':elemBaseName,'docTypeName':docTypeName}});YAHOO.util.Connect.asyncRequest('GET','index.php?module=EAPM&action=flushFileCache&to_pdf=1&api='+dropdownValue,{});}else{docShowHideElem.style.display='none';document.getElementById(elemBaseName+'_file').disabled=false;}
41 sqs_objects[formName+"_"+elemBaseName+"_remoteName"].api=dropdownValue;var secLevelBoxElem=document.getElementById(elemBaseName+'_securityLevelBox');var secLevelElem=document.getElementById(elemBaseName+'_securityLevel');secLevelElem.options.length=0;if(SUGAR.eapm[dropdownValue]&&SUGAR.eapm[dropdownValue].sharingOptions){var opts=SUGAR.eapm[dropdownValue].sharingOptions;var i=0;for(idx in opts){secLevelElem.options[i]=new Option(SUGAR.language.get('app_strings',opts[idx]),idx,false,false);i++;}
42 secLevelBoxElem.style.display='';}else{secLevelBoxElem.style.display='none';}}
43 document.getElementById(docTypeName).onchange=showHideFunc;document.getElementById(elemBaseName+'_externalApiLabel').onclick=externalSearchToggle;showHideFunc();},openPopup:function(elemBaseName){window.open('index.php?module=Documents&action=extdoc&isPopup=1&elemBaseName='+elemBaseName+'&apiName='+document.getElementById('doc_type').value,'sugarPopup','width=600,height=400,menubar=no,toolbar=no,status=no,resizeable=yes,scrollbars=yes');},clearRemote:function(elemBaseName){document.getElementById('doc_id').value='';document.getElementById(elemBaseName).value='';document.getElementById(elemBaseName+'_remoteName').value='';document.getElementById('doc_url').value='';},populateFromPopup:function(elemBaseName,docId,docName,docUrl,docDirectUrl){document.getElementById('doc_id').value=docId;document.getElementById(elemBaseName).value=docId;document.getElementById(elemBaseName+'_remoteName').value=docName;document.getElementById('doc_url').value=docUrl;},getFileExtension:function(fileName){var lastindex=fileName.lastIndexOf(".");if(lastindex==-1)
44 return'';else
45 return fileName.substr(++lastindex);},isFileExtensionValid:function(fileName){var docType=document.getElementById('doc_type').value;var fileExtension=this.getFileExtension(fileName);if(typeof(SUGAR.eapm[docType])=='undefined'||!SUGAR.eapm[docType].restrictUploadsByExtension){return true;}
46 var whiteSuffixlist=SUGAR.eapm[docType]['restrictUploadsByExtension'];if(whiteSuffixlist.constructor==Array){var results=false;for(var i=0;i<whiteSuffixlist.length;i++){if(fileExtension.toLowerCase()==whiteSuffixlist[i].toLowerCase()){return true;}}}
47 return results;},checkFileExtension:function(e,obj){var sff=SUGAR.field.file;var fileEl=document.getElementById(obj.fileEl);var fileName=fileEl.value;var isValid=sff.isFileExtensionValid(fileName);if(!isValid&&fileName!=''){var errorPannel=new YAHOO.widget.SimpleDialog('sugarMsgWindow',{width:'240px',visible:true,fixedcenter:true,constraintoviewport:true,draggable:true,type:'alert',modal:true,id:'sugarMsgWindow',close:true});errorPannel.setBody(SUGAR.language.get("app_strings","LBL_INVALID_FILE_EXTENSION"));errorPannel.render(document.body);errorPannel.show();fileEl.value='';document.getElementById(obj.targEl).value='';}}}}