1 /*********************************************************************************
2 * SugarCRM Community Edition is a customer relationship management program developed by
3 * SugarCRM, Inc. Copyright (C) 2004-2011 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("Notes", "LBL_REMOVING_ATTACHMENT"));
45 elem.form.deleteAttachment.value=1;
46 elem.form.action.value="EditView";
47 SUGAR.dashlets.postForm(elem.form, SUGAR.field.file.deleteAttachmentCallbackGen(elemBaseName,docTypeName));
48 elem.form.deleteAttachment.value=0;
49 elem.form.action.value="";
51 deleteAttachmentCallbackGen: function(elemBaseName,docTypeName) {
52 return function(text) {
54 document.getElementById(elemBaseName+'_new').style.display = '';
55 ajaxStatus.hideStatus();
56 document.getElementById(elemBaseName+'_old').innerHTML = '';
57 document.getElementById(docTypeName).disabled = false;
58 document.getElementById(elemBaseName).value = '';
60 document.getElementById(elemBaseName+'_new').style.display = 'none';
61 ajaxStatus.flashStatus(SUGAR.language.get('Notes', 'ERR_REMOVING_ATTACHMENT'), 2000);
65 checkEapiLogin: function(res) {
66 var failedLogins = JSON.parse(res.responseText);
67 if ( failedLogins.length == 0 ) { return; }
69 for ( var idx in failedLogins ) {
70 if(confirm(failedLogins[idx].label)) {
71 window.open(failedLogins[idx].checkURL,'EAPM_CHECK_'+idx);
73 document.getElementById(res.argument.docTypeName).value = 'Sugar';
74 document.getElementById(res.argument.docTypeName).onchange();
78 setupEapiShowHide: function(elemBaseName,docTypeName,formName) {
79 var externalSearchToggle = function() {
80 var moreElem = document.getElementById(elemBaseName + "_more");
81 var hideMore = (moreElem.style.display == 'none');
83 // We're hiding the "more" element, so we clicked on the "less" element and want to hide stuff
84 moreElem.style.display = '';
85 document.getElementById(elemBaseName + '_less').style.display = 'none';
86 document.getElementById(elemBaseName + '_remoteNameSpan').style.display = 'none';
87 document.getElementById(elemBaseName + '_file').disabled = false;
89 // We're not hiding the "more" element, so we clicked on the "more" element and want to show stuff
90 moreElem.style.display = 'none';
91 document.getElementById(elemBaseName + '_less').style.display = '';
92 document.getElementById(elemBaseName + '_remoteNameSpan').style.display = '';
93 document.getElementById(elemBaseName + '_file').disabled = true;
97 var showHideFunc = function() {
98 var docShowHideElem = document.getElementById(elemBaseName + "_externalApiSelector");
100 var dropdownValue = document.getElementById(docTypeName).value;
101 if ( typeof(SUGAR.eapm) != 'undefined'
102 && typeof(SUGAR.eapm[dropdownValue]) != 'undefined'
103 && typeof(SUGAR.eapm[dropdownValue].docSearch) != 'undefined'
104 && SUGAR.eapm[dropdownValue].docSearch ) {
105 docShowHideElem.style.display = '';
108 // Double check to make sure their login is valid
109 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}});
111 // Start a refresh of the document cache in the background. Thanks AJAX!
112 YAHOO.util.Connect.asyncRequest('GET', 'index.php?module=EAPM&action=flushFileCache&to_pdf=1&api='+dropdownValue,{});
114 docShowHideElem.style.display = 'none';
115 document.getElementById(elemBaseName + '_file').disabled = false;
117 // Update the quick search
118 sqs_objects[formName+"_"+elemBaseName+"_remoteName"].api = dropdownValue;
121 // Now time to see if we can select security options
122 var secLevelBoxElem = document.getElementById(elemBaseName + '_securityLevelBox');
123 var secLevelElem = document.getElementById(elemBaseName + '_securityLevel');
125 secLevelElem.options.length = 0;
127 if ( SUGAR.eapm[dropdownValue] && SUGAR.eapm[dropdownValue].sharingOptions ) {
128 var opts = SUGAR.eapm[dropdownValue].sharingOptions;
131 for ( idx in opts ) {
132 secLevelElem.options[i] = new Option(SUGAR.language.get('app_strings',opts[idx]),idx,false,false);
136 secLevelBoxElem.style.display='';
138 secLevelBoxElem.style.display='none';
142 document.getElementById(docTypeName).onchange = showHideFunc;
144 document.getElementById(elemBaseName + '_externalApiLabel').onclick = externalSearchToggle;
148 // Select button / popup related functions
149 openPopup: function(elemBaseName) {
150 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');
153 clearRemote: function(elemBaseName) {
154 document.getElementById('doc_id').value = '';
155 document.getElementById(elemBaseName).value = '';
156 document.getElementById(elemBaseName + '_remoteName').value = '';
157 document.getElementById('doc_url').value = '';
160 populateFromPopup: function(elemBaseName, docId, docName, docUrl, docDirectUrl) {
161 document.getElementById('doc_id').value = docId;
162 document.getElementById(elemBaseName).value = docId;
163 document.getElementById(elemBaseName + '_remoteName').value = docName;
164 document.getElementById('doc_url').value = docUrl;
167 getFileExtension:function(fileName) {
168 var lastindex = fileName.lastIndexOf(".");
172 return fileName.substr(++lastindex);
174 isFileExtensionValid: function(fileName) {
175 var docType = document.getElementById('doc_type').value;
176 var fileExtension = this.getFileExtension(fileName);
178 if( typeof(SUGAR.eapm[docType]) == 'undefined' || ! SUGAR.eapm[docType].restrictUploadsByExtension ){
181 var whiteSuffixlist = SUGAR.eapm[docType]['restrictUploadsByExtension'];
182 if(whiteSuffixlist.constructor == Array){
184 for(var i=0;i<whiteSuffixlist.length;i++){
185 if( fileExtension.toLowerCase() == whiteSuffixlist[i].toLowerCase() ){
193 checkFileExtension: function(e,obj) {
194 var sff = SUGAR.field.file; //Scope is set to element.
195 var fileEl = document.getElementById(obj.fileEl);
196 var fileName = fileEl.value;
198 var isValid = sff.isFileExtensionValid(fileName);
199 if( !isValid && fileName != '' ){
200 var errorPannel = new YAHOO.widget.SimpleDialog('sugarMsgWindow', {
201 width: '240px',visible: true, fixedcenter: true,constraintoviewport: true,
202 draggable: true,type:'alert',modal:true,id:'sugarMsgWindow',close:true
204 errorPannel.setBody(SUGAR.language.get("app_strings", "LBL_INVALID_FILE_EXTENSION"));
205 errorPannel.render(document.body);
208 document.getElementById(obj.targEl).value = '';