[ Index ] |
PHP Cross Reference of vtigercrm-6.1.0 |
[Summary view] [Print] [Text view]
1 /*+*********************************************************************************** 2 * The contents of this file are subject to the vtiger CRM Public License Version 1.0 3 * ("License"); You may not use this file except in compliance with the License 4 * The Original Code is: vtiger CRM Open Source 5 * The Initial Developer of the Original Code is vtiger. 6 * Portions created by vtiger are Copyright (C) vtiger. 7 * All Rights Reserved. 8 *************************************************************************************/ 9 10 Vtiger_Edit_Js("Documents_Edit_Js", {} ,{ 11 12 INTERNAL_FILE_LOCATION_TYPE : 'I', 13 EXTERNAL_FILE_LOCATION_TYPE : 'E', 14 15 getMaxiumFileUploadingSize : function(container) { 16 //TODO : get it from the server 17 return container.find('.maxUploadSize').data('value'); 18 }, 19 20 isFileLocationInternalType : function(fileLocationElement) { 21 if(fileLocationElement.val() == this.INTERNAL_FILE_LOCATION_TYPE) { 22 return true; 23 } 24 return false; 25 }, 26 27 isFileLocationExternalType : function(fileLocationElement) { 28 if(fileLocationElement.val() == this.EXTERNAL_FILE_LOCATION_TYPE) { 29 return true; 30 } 31 return false; 32 }, 33 34 convertFileSizeInToDisplayFormat : function(fileSizeInBytes) { 35 var i = -1; 36 var byteUnits = [' kB', ' MB', ' GB', ' TB', 'PB', 'EB', 'ZB', 'YB']; 37 do { 38 fileSizeInBytes = fileSizeInBytes / 1024; 39 i++; 40 } while (fileSizeInBytes > 1024); 41 42 return Math.max(fileSizeInBytes, 0.1).toFixed(1) + byteUnits[i]; 43 44 }, 45 46 registerFileLocationTypeChangeEvent : function(container) { 47 var thisInstance = this; 48 container.on('change', 'select[name="filelocationtype"]', function(e){ 49 var fileLocationTypeElement = container.find('[name="filelocationtype"]'); 50 var fileNameElement = container.find('[name="filename"]'); 51 if(thisInstance.isFileLocationInternalType(fileLocationTypeElement)) { 52 var newFileNameElement = jQuery('<input type="file"/>'); 53 }else{ 54 var newFileNameElement = jQuery('<input type="text" />'); 55 } 56 var oldElementAttributeList = fileNameElement.get(0).attributes; 57 58 for(var index=0; index<oldElementAttributeList.length; index++) { 59 var attributeObject = oldElementAttributeList[index]; 60 //Dont update the type attribute 61 if(attributeObject.name=='type' || attributeObject.name == 'value'){ 62 continue; 63 } 64 var value = attributeObject.value 65 if(attributeObject.name=='data-fieldinfo') { 66 value = JSON.parse(value); 67 if(thisInstance.isFileLocationExternalType(fileLocationTypeElement)) { 68 value['type'] = 'url'; 69 }else{ 70 value['type'] = 'file'; 71 } 72 value = JSON.stringify(value); 73 } 74 newFileNameElement.attr(attributeObject.name, value); 75 } 76 fileNameElement.replaceWith(newFileNameElement); 77 var fileNameElementTd = newFileNameElement.closest('td'); 78 var uploadFileDetails = fileNameElementTd.find('.uploadedFileDetails'); 79 if(thisInstance.isFileLocationExternalType(fileLocationTypeElement)) { 80 uploadFileDetails.addClass('hide').removeClass('show'); 81 }else{ 82 uploadFileDetails.addClass('show').removeClass('hide'); 83 } 84 }); 85 }, 86 87 registerFileChangeEvent : function(container) { 88 var thisInstance = this; 89 container.on('change', 'input[name="filename"]', function(e){ 90 if(e.target.type == "text") return false; 91 file = e.target.files[0]; 92 var element = container.find('[name="filename"]'); 93 //ignore all other types than file 94 if(element.attr('type') != 'file'){ 95 return ; 96 } 97 var uploadFileSizeHolder = element.closest('.fileUploadContainer').find('.uploadedFileSize'); 98 var fileSize = element.get(0).files[0].size; 99 var maxFileSize = thisInstance.getMaxiumFileUploadingSize(container); 100 if(fileSize > maxFileSize) { 101 alert(app.vtranslate('JS_EXCEEDS_MAX_UPLOAD_SIZE')); 102 element.val(''); 103 uploadFileSizeHolder.text(''); 104 }else{ 105 uploadFileSizeHolder.text(thisInstance.convertFileSizeInToDisplayFormat(fileSize)); 106 } 107 108 }); 109 }, 110 /** 111 * Function to register event for ckeditor for description field 112 */ 113 registerEventForCkEditor : function(){ 114 var form = this.getForm(); 115 var noteContentElement = form.find('[name="notecontent"]'); 116 if(noteContentElement.length > 0){ 117 noteContentElement.removeAttr('data-validation-engine').addClass('ckEditorSource'); 118 var ckEditorInstance = new Vtiger_CkEditor_Js(); 119 ckEditorInstance.loadCkEditor(noteContentElement); 120 } 121 }, 122 123 /** 124 * Function to save the quickcreate module 125 * @param accepts form element as parameter 126 * @return returns deferred promise 127 */ 128 quickCreateSave: function(form) { 129 var thisInstance = this; 130 var aDeferred = jQuery.Deferred(); 131 //Using formData object to send data to server as a multipart/form-data form submit 132 var formData = new FormData(form[0]); 133 var fileLocationTypeElement = form.find('[name="filelocationtype"]'); 134 if(typeof file != "undefined" && thisInstance.isFileLocationInternalType(fileLocationTypeElement)){ 135 formData.append("filename", file); 136 delete file; 137 } 138 if (formData) { 139 var params = { 140 url: "index.php", 141 type: "POST", 142 data: formData, 143 processData: false, 144 contentType: false 145 }; 146 AppConnector.request(params).then( 147 function(data){ 148 aDeferred.resolve(data); 149 }, 150 function(textStatus, errorThrown){ 151 aDeferred.reject(textStatus, errorThrown); 152 }); 153 } 154 return aDeferred.promise(); 155 }, 156 registerBasicEvents : function(container) { 157 this._super(container); 158 this.registerFileLocationTypeChangeEvent(container); 159 this.registerFileChangeEvent(container); 160 }, 161 162 registerEvents : function() { 163 this.registerEventForCkEditor(); 164 this._super(); 165 } 166 }); 167 168
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 20:08:37 2014 | Cross-referenced by PHPXref 0.7.1 |