1 /*********************************************************************************
2 * SugarCRM Community Edition is a customer relationship management program developed by
3 * SugarCRM, Inc. Copyright (C) 2004-2012 SugarCRM Inc.
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.
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
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
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.
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.
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 ********************************************************************************/
37 if ( typeof(SUGAR.field) == 'undefined' ) {
38 SUGAR.field = new Object();
41 if ( typeof(SUGAR.field.file) == 'undefined' ) {
43 deleteAttachment: function(elemBaseName,docTypeName,elem) {
44 ajaxStatus.showStatus(SUGAR.language.get("app_strings", "LBL_REMOVING_ATTACHMENT"));
45 elem.form.deleteAttachment.value=1;
46 elem.form.action.value="deleteattachment";
48 var callback = SUGAR.field.file.deleteAttachmentCallbackGen(elemBaseName,docTypeName);
49 var success = function(data) {
51 callback(data.responseText);
54 YAHOO.util.Connect.setForm(elem.form);
55 var cObj = YAHOO.util.Connect.asyncRequest('POST', 'index.php', {success: success, failure: success});
57 elem.form.deleteAttachment.value=0;
58 elem.form.action.value="";
60 deleteAttachmentCallbackGen: function(elemBaseName,docTypeName) {
61 return function(text) {
63 document.getElementById(elemBaseName+'_new').style.display = '';
64 ajaxStatus.hideStatus();
65 document.getElementById(elemBaseName+'_old').innerHTML = '';
67 document.getElementById(docTypeName).disabled = false;
69 document.getElementById(elemBaseName).value = '';
71 document.getElementById(elemBaseName+'_new').style.display = 'none';
72 ajaxStatus.flashStatus(SUGAR.language.get('app_strings', 'ERR_REMOVING_ATTACHMENT'), 2000);
76 checkEapiLogin: function(res) {
77 var failedLogins = YAHOO.lang.JSON.parse(res.responseText);
78 if ( failedLogins.length == 0 ) { return; }
80 for ( var idx in failedLogins ) {
81 if(confirm(failedLogins[idx].label)) {
82 window.open(failedLogins[idx].checkURL,'EAPM_CHECK_'+idx);
84 document.getElementById(res.argument.docTypeName).value = 'Sugar';
85 document.getElementById(res.argument.docTypeName).onchange();
89 setupEapiShowHide: function(elemBaseName,docTypeName,formName) {
90 var externalSearchToggle = function() {
91 var moreElem = document.getElementById(elemBaseName + "_more");
92 var hideMore = (moreElem.style.display == 'none');
94 // We're hiding the "more" element, so we clicked on the "less" element and want to hide stuff
95 moreElem.style.display = '';
96 document.getElementById(elemBaseName + '_less').style.display = 'none';
97 document.getElementById(elemBaseName + '_remoteNameSpan').style.display = 'none';
98 document.getElementById(elemBaseName + '_file').disabled = false;
100 // We're not hiding the "more" element, so we clicked on the "more" element and want to show stuff
101 moreElem.style.display = 'none';
102 document.getElementById(elemBaseName + '_less').style.display = '';
103 document.getElementById(elemBaseName + '_remoteNameSpan').style.display = '';
104 document.getElementById(elemBaseName + '_file').disabled = true;
108 var showHideFunc = function() {
109 var docShowHideElem = document.getElementById(elemBaseName + "_externalApiSelector");
111 var dropdownValue = document.getElementById(docTypeName).value;
112 if ( typeof(SUGAR.eapm) != 'undefined'
113 && typeof(SUGAR.eapm[dropdownValue]) != 'undefined'
114 && typeof(SUGAR.eapm[dropdownValue].docSearch) != 'undefined'
115 && SUGAR.eapm[dropdownValue].docSearch ) {
116 docShowHideElem.style.display = '';
119 // Double check to make sure their login is valid
120 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}});
122 // Start a refresh of the document cache in the background. Thanks AJAX!
123 YAHOO.util.Connect.asyncRequest('GET', 'index.php?module=EAPM&action=flushFileCache&to_pdf=1&api='+dropdownValue,{});
125 docShowHideElem.style.display = 'none';
126 document.getElementById(elemBaseName + '_file').disabled = false;
128 // Update the quick search
129 sqs_objects[formName+"_"+elemBaseName+"_remoteName"].api = dropdownValue;
132 // Now time to see if we can select security options
133 var secLevelBoxElem = document.getElementById(elemBaseName + '_securityLevelBox');
134 var secLevelElem = document.getElementById(elemBaseName + '_securityLevel');
136 secLevelElem.options.length = 0;
138 if ( SUGAR.eapm[dropdownValue] && SUGAR.eapm[dropdownValue].sharingOptions ) {
139 var opts = SUGAR.eapm[dropdownValue].sharingOptions;
142 for ( idx in opts ) {
143 secLevelElem.options[i] = new Option(SUGAR.language.get('app_strings',opts[idx]),idx,false,false);
147 secLevelBoxElem.style.display='';
149 secLevelBoxElem.style.display='none';
153 document.getElementById(docTypeName).onchange = showHideFunc;
155 document.getElementById(elemBaseName + '_externalApiLabel').onclick = externalSearchToggle;
159 // Select button / popup related functions
160 openPopup: function(elemBaseName) {
161 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');
164 clearRemote: function(elemBaseName) {
165 document.getElementById('doc_id').value = '';
166 document.getElementById(elemBaseName).value = '';
167 document.getElementById(elemBaseName + '_remoteName').value = '';
168 document.getElementById('doc_url').value = '';
171 populateFromPopup: function(elemBaseName, docId, docName, docUrl, docDirectUrl) {
172 document.getElementById('doc_id').value = docId;
173 document.getElementById(elemBaseName).value = docId;
174 document.getElementById(elemBaseName + '_remoteName').value = docName;
175 document.getElementById('doc_url').value = docUrl;
178 getFileExtension:function(fileName) {
179 var lastindex = fileName.lastIndexOf(".");
183 return fileName.substr(++lastindex);
185 isFileExtensionValid: function(fileName) {
186 var docType = document.getElementById('doc_type').value;
187 var fileExtension = this.getFileExtension(fileName);
189 if( typeof(SUGAR.eapm[docType]) == 'undefined' || ! SUGAR.eapm[docType].restrictUploadsByExtension ){
192 var whiteSuffixlist = SUGAR.eapm[docType]['restrictUploadsByExtension'];
193 if(whiteSuffixlist.constructor == Array){
195 for(var i=0;i<whiteSuffixlist.length;i++){
196 if( fileExtension.toLowerCase() == whiteSuffixlist[i].toLowerCase() ){
204 checkFileExtension: function(e,obj) {
205 var sff = SUGAR.field.file; //Scope is set to element.
206 var fileEl = document.getElementById(obj.fileEl);
207 var fileName = fileEl.value;
209 var isValid = sff.isFileExtensionValid(fileName);
210 if( !isValid && fileName != '' ){
211 var errorPannel = new YAHOO.widget.SimpleDialog('sugarMsgWindow', {
212 width: '240px',visible: true, fixedcenter: true,constraintoviewport: true,
213 draggable: true,type:'alert',modal:true,id:'sugarMsgWindow',close:true
215 errorPannel.setBody(SUGAR.language.get("app_strings", "LBL_INVALID_FILE_EXTENSION"));
216 errorPannel.render(document.body);
219 document.getElementById(obj.targEl).value = '';