first commit
This commit is contained in:
93
layouts/vlayout/modules/Documents/resources/Detail.js
Normal file
93
layouts/vlayout/modules/Documents/resources/Detail.js
Normal file
@@ -0,0 +1,93 @@
|
||||
/*+***********************************************************************************
|
||||
* The contents of this file are subject to the vtiger CRM Public License Version 1.0
|
||||
* ("License"); You may not use this file except in compliance with the License
|
||||
* The Original Code is: vtiger CRM Open Source
|
||||
* The Initial Developer of the Original Code is vtiger.
|
||||
* Portions created by vtiger are Copyright (C) vtiger.
|
||||
* All Rights Reserved.
|
||||
*************************************************************************************/
|
||||
|
||||
Vtiger_Detail_Js("Documents_Detail_Js", {
|
||||
|
||||
//It stores the CheckFileIntegrity response data
|
||||
checkFileIntegrityResponseCache : {},
|
||||
|
||||
/*
|
||||
* function to trigger CheckFileIntegrity action
|
||||
* @param: CheckFileIntegrity url.
|
||||
*/
|
||||
checkFileIntegrity : function(checkFileIntegrityUrl) {
|
||||
Documents_Detail_Js.getFileIntegrityResponse(checkFileIntegrityUrl).then(
|
||||
function(data){
|
||||
Documents_Detail_Js.displayCheckFileIntegrityResponse(data);
|
||||
}
|
||||
);
|
||||
},
|
||||
|
||||
/*
|
||||
* function to get the CheckFileIntegrity response data
|
||||
*/
|
||||
getFileIntegrityResponse : function(params){
|
||||
var aDeferred = jQuery.Deferred();
|
||||
|
||||
//Check in the cache
|
||||
if(!(jQuery.isEmptyObject(Documents_Detail_Js.checkFileIntegrityResponseCache))) {
|
||||
aDeferred.resolve(Documents_Detail_Js.checkFileIntegrityResponseCache);
|
||||
}
|
||||
else{
|
||||
AppConnector.request(params).then(
|
||||
function(data) {
|
||||
//store it in the cache, so that we dont do multiple request
|
||||
Documents_Detail_Js.checkFileIntegrityResponseCache = data;
|
||||
aDeferred.resolve(Documents_Detail_Js.checkFileIntegrityResponseCache);
|
||||
}
|
||||
);
|
||||
}
|
||||
return aDeferred.promise();
|
||||
},
|
||||
|
||||
/*
|
||||
* function to display the CheckFileIntegrity message
|
||||
*/
|
||||
displayCheckFileIntegrityResponse : function(data) {
|
||||
var result = data['result'];
|
||||
var success = result['success'];
|
||||
var message = result['message'];
|
||||
var params = {};
|
||||
if(success) {
|
||||
params = {
|
||||
text: message,
|
||||
type: 'success'
|
||||
}
|
||||
} else {
|
||||
params = {
|
||||
text: message,
|
||||
type: 'error'
|
||||
}
|
||||
}
|
||||
Documents_Detail_Js.showNotify(params);
|
||||
},
|
||||
|
||||
//This will show the messages of CheckFileIntegrity using pnotify
|
||||
showNotify : function(customParams) {
|
||||
var params = {
|
||||
title: app.vtranslate('JS_CHECK_FILE_INTEGRITY'),
|
||||
text: customParams.text,
|
||||
type: customParams.type,
|
||||
width: '30%',
|
||||
delay: '2000'
|
||||
};
|
||||
Vtiger_Helper_Js.showPnotify(params);
|
||||
},
|
||||
|
||||
triggerSendEmail : function(recordIds) {
|
||||
var params = {
|
||||
"module" : "Documents",
|
||||
"view" : "ComposeEmail",
|
||||
"documentIds" : recordIds
|
||||
};
|
||||
var emailEditInstance = new Emails_MassEdit_Js();
|
||||
emailEditInstance.showComposeEmailForm(params);
|
||||
}
|
||||
|
||||
},{});
|
||||
168
layouts/vlayout/modules/Documents/resources/Edit.js
Normal file
168
layouts/vlayout/modules/Documents/resources/Edit.js
Normal file
@@ -0,0 +1,168 @@
|
||||
/*+***********************************************************************************
|
||||
* The contents of this file are subject to the vtiger CRM Public License Version 1.0
|
||||
* ("License"); You may not use this file except in compliance with the License
|
||||
* The Original Code is: vtiger CRM Open Source
|
||||
* The Initial Developer of the Original Code is vtiger.
|
||||
* Portions created by vtiger are Copyright (C) vtiger.
|
||||
* All Rights Reserved.
|
||||
*************************************************************************************/
|
||||
|
||||
Vtiger_Edit_Js("Documents_Edit_Js", {} ,{
|
||||
|
||||
INTERNAL_FILE_LOCATION_TYPE : 'I',
|
||||
EXTERNAL_FILE_LOCATION_TYPE : 'E',
|
||||
|
||||
getMaxiumFileUploadingSize : function(container) {
|
||||
//TODO : get it from the server
|
||||
return container.find('.maxUploadSize').data('value');
|
||||
},
|
||||
|
||||
isFileLocationInternalType : function(fileLocationElement) {
|
||||
if(fileLocationElement.val() == this.INTERNAL_FILE_LOCATION_TYPE) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
},
|
||||
|
||||
isFileLocationExternalType : function(fileLocationElement) {
|
||||
if(fileLocationElement.val() == this.EXTERNAL_FILE_LOCATION_TYPE) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
},
|
||||
|
||||
convertFileSizeInToDisplayFormat : function(fileSizeInBytes) {
|
||||
var i = -1;
|
||||
var byteUnits = [' kB', ' MB', ' GB', ' TB', 'PB', 'EB', 'ZB', 'YB'];
|
||||
do {
|
||||
fileSizeInBytes = fileSizeInBytes / 1024;
|
||||
i++;
|
||||
} while (fileSizeInBytes > 1024);
|
||||
|
||||
return Math.max(fileSizeInBytes, 0.1).toFixed(1) + byteUnits[i];
|
||||
|
||||
},
|
||||
|
||||
registerFileLocationTypeChangeEvent : function(container) {
|
||||
var thisInstance = this;
|
||||
container.on('change', 'select[name="filelocationtype"]', function(e){
|
||||
var fileLocationTypeElement = container.find('[name="filelocationtype"]');
|
||||
var fileNameElement = container.find('[name="filename"]');
|
||||
if(thisInstance.isFileLocationInternalType(fileLocationTypeElement)) {
|
||||
var newFileNameElement = jQuery('<input type="file"/>');
|
||||
}else{
|
||||
var newFileNameElement = jQuery('<input type="text" />');
|
||||
}
|
||||
var oldElementAttributeList = fileNameElement.get(0).attributes;
|
||||
|
||||
for(var index=0; index<oldElementAttributeList.length; index++) {
|
||||
var attributeObject = oldElementAttributeList[index];
|
||||
//Dont update the type attribute
|
||||
if(attributeObject.name=='type' || attributeObject.name == 'value'){
|
||||
continue;
|
||||
}
|
||||
var value = attributeObject.value
|
||||
if(attributeObject.name=='data-fieldinfo') {
|
||||
value = JSON.parse(value);
|
||||
if(thisInstance.isFileLocationExternalType(fileLocationTypeElement)) {
|
||||
value['type'] = 'url';
|
||||
}else{
|
||||
value['type'] = 'file';
|
||||
}
|
||||
value = JSON.stringify(value);
|
||||
}
|
||||
newFileNameElement.attr(attributeObject.name, value);
|
||||
}
|
||||
fileNameElement.replaceWith(newFileNameElement);
|
||||
var fileNameElementTd = newFileNameElement.closest('td');
|
||||
var uploadFileDetails = fileNameElementTd.find('.uploadedFileDetails');
|
||||
if(thisInstance.isFileLocationExternalType(fileLocationTypeElement)) {
|
||||
uploadFileDetails.addClass('hide').removeClass('show');
|
||||
}else{
|
||||
uploadFileDetails.addClass('show').removeClass('hide');
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
registerFileChangeEvent : function(container) {
|
||||
var thisInstance = this;
|
||||
container.on('change', 'input[name="filename"]', function(e){
|
||||
if(e.target.type == "text") return false;
|
||||
file = e.target.files[0];
|
||||
var element = container.find('[name="filename"]');
|
||||
//ignore all other types than file
|
||||
if(element.attr('type') != 'file'){
|
||||
return ;
|
||||
}
|
||||
var uploadFileSizeHolder = element.closest('.fileUploadContainer').find('.uploadedFileSize');
|
||||
var fileSize = element.get(0).files[0].size;
|
||||
var maxFileSize = thisInstance.getMaxiumFileUploadingSize(container);
|
||||
if(fileSize > maxFileSize) {
|
||||
alert(app.vtranslate('JS_EXCEEDS_MAX_UPLOAD_SIZE'));
|
||||
element.val('');
|
||||
uploadFileSizeHolder.text('');
|
||||
}else{
|
||||
uploadFileSizeHolder.text(thisInstance.convertFileSizeInToDisplayFormat(fileSize));
|
||||
}
|
||||
|
||||
});
|
||||
},
|
||||
/**
|
||||
* Function to register event for ckeditor for description field
|
||||
*/
|
||||
registerEventForCkEditor : function(){
|
||||
var form = this.getForm();
|
||||
var noteContentElement = form.find('[name="notecontent"]');
|
||||
if(noteContentElement.length > 0){
|
||||
noteContentElement.removeAttr('data-validation-engine').addClass('ckEditorSource');
|
||||
var ckEditorInstance = new Vtiger_CkEditor_Js();
|
||||
ckEditorInstance.loadCkEditor(noteContentElement);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Function to save the quickcreate module
|
||||
* @param accepts form element as parameter
|
||||
* @return returns deferred promise
|
||||
*/
|
||||
quickCreateSave: function(form) {
|
||||
var thisInstance = this;
|
||||
var aDeferred = jQuery.Deferred();
|
||||
//Using formData object to send data to server as a multipart/form-data form submit
|
||||
var formData = new FormData(form[0]);
|
||||
var fileLocationTypeElement = form.find('[name="filelocationtype"]');
|
||||
if(typeof file != "undefined" && thisInstance.isFileLocationInternalType(fileLocationTypeElement)){
|
||||
formData.append("filename", file);
|
||||
delete file;
|
||||
}
|
||||
if (formData) {
|
||||
var params = {
|
||||
url: "index.php",
|
||||
type: "POST",
|
||||
data: formData,
|
||||
processData: false,
|
||||
contentType: false
|
||||
};
|
||||
AppConnector.request(params).then(
|
||||
function(data){
|
||||
aDeferred.resolve(data);
|
||||
},
|
||||
function(textStatus, errorThrown){
|
||||
aDeferred.reject(textStatus, errorThrown);
|
||||
});
|
||||
}
|
||||
return aDeferred.promise();
|
||||
},
|
||||
registerBasicEvents : function(container) {
|
||||
this._super(container);
|
||||
this.registerFileLocationTypeChangeEvent(container);
|
||||
this.registerFileChangeEvent(container);
|
||||
},
|
||||
|
||||
registerEvents : function() {
|
||||
this.registerEventForCkEditor();
|
||||
this._super();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
319
layouts/vlayout/modules/Documents/resources/List.js
Normal file
319
layouts/vlayout/modules/Documents/resources/List.js
Normal file
@@ -0,0 +1,319 @@
|
||||
/*+***********************************************************************************
|
||||
* The contents of this file are subject to the vtiger CRM Public License Version 1.0
|
||||
* ("License"); You may not use this file except in compliance with the License
|
||||
* The Original Code is: vtiger CRM Open Source
|
||||
* The Initial Developer of the Original Code is vtiger.
|
||||
* Portions created by vtiger are Copyright (C) vtiger.
|
||||
* All Rights Reserved.
|
||||
*************************************************************************************/
|
||||
|
||||
Vtiger_List_Js("Documents_List_Js", {
|
||||
|
||||
triggerAddFolder : function(url) {
|
||||
var params = url;
|
||||
var progressIndicatorElement = jQuery.progressIndicator();
|
||||
AppConnector.request(params).then(
|
||||
function(data) {
|
||||
progressIndicatorElement.progressIndicator({'mode' : 'hide'});
|
||||
var callBackFunction = function(data){
|
||||
jQuery('#addDocumentsFolder').validationEngine({
|
||||
// to prevent the page reload after the validation has completed
|
||||
'onValidationComplete' : function(form,valid){
|
||||
return valid;
|
||||
}
|
||||
});
|
||||
Vtiger_List_Js.getInstance().folderSubmit().then(function(data){
|
||||
app.hideModalWindow();
|
||||
if(data.success){
|
||||
var result = data.result;
|
||||
if(result.success){
|
||||
var info = result.info;
|
||||
Vtiger_List_Js.getInstance().updateCustomFilter(info);
|
||||
var params = {
|
||||
title : app.vtranslate('JS_NEW_FOLDER'),
|
||||
text : result.message,
|
||||
delay: '2000',
|
||||
type: 'success'
|
||||
}
|
||||
Vtiger_Helper_Js.showPnotify(params);
|
||||
} else {
|
||||
var result = result.message;
|
||||
var folderNameElement = jQuery('#documentsFolderName');
|
||||
folderNameElement.validationEngine('showPrompt', result , 'error','topLeft',true);
|
||||
}
|
||||
} else {
|
||||
var params = {
|
||||
title : app.vtranslate('JS_ERROR'),
|
||||
text : data.error.message,
|
||||
type: 'error'
|
||||
}
|
||||
Vtiger_Helper_Js.showPnotify(params);
|
||||
}
|
||||
});
|
||||
};
|
||||
app.showModalWindow(data,function(data){
|
||||
if(typeof callBackFunction == 'function'){
|
||||
callBackFunction(data);
|
||||
}
|
||||
});
|
||||
}
|
||||
)
|
||||
},
|
||||
|
||||
massMove : function(url){
|
||||
var listInstance = Vtiger_List_Js.getInstance();
|
||||
var validationResult = listInstance.checkListRecordSelected();
|
||||
if(validationResult != true){
|
||||
var selectedIds = listInstance.readSelectedIds(true);
|
||||
var excludedIds = listInstance.readExcludedIds(true);
|
||||
var cvId = listInstance.getCurrentCvId();
|
||||
var postData = {
|
||||
"selected_ids":selectedIds,
|
||||
"excluded_ids" : excludedIds,
|
||||
"viewname" : cvId
|
||||
};
|
||||
|
||||
var searchValue = listInstance.getAlphabetSearchValue();
|
||||
|
||||
if(searchValue.length > 0) {
|
||||
postData['search_key'] = listInstance.getAlphabetSearchField();
|
||||
postData['search_value'] = searchValue;
|
||||
postData['operator'] = "s";
|
||||
}
|
||||
|
||||
var params = {
|
||||
"url":url,
|
||||
"data" : postData
|
||||
};
|
||||
var progressIndicatorElement = jQuery.progressIndicator();
|
||||
AppConnector.request(params).then(
|
||||
function(data) {
|
||||
progressIndicatorElement.progressIndicator({'mode' : 'hide'});
|
||||
var callBackFunction = function(data){
|
||||
|
||||
listInstance.moveDocuments().then(function(data){
|
||||
if(data){
|
||||
var result = data.result;
|
||||
if(result.success){
|
||||
app.hideModalWindow();
|
||||
var params = {
|
||||
title : app.vtranslate('JS_MOVE_DOCUMENTS'),
|
||||
text : result.message,
|
||||
delay: '2000',
|
||||
type: 'success'
|
||||
}
|
||||
Vtiger_Helper_Js.showPnotify(params);
|
||||
var urlParams = listInstance.getDefaultParams();
|
||||
listInstance.getListViewRecords(urlParams);
|
||||
} else {
|
||||
var params = {
|
||||
title : app.vtranslate('JS_OPERATION_DENIED'),
|
||||
text : result.message,
|
||||
delay: '2000',
|
||||
type: 'error'
|
||||
}
|
||||
Vtiger_Helper_Js.showPnotify(params);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
app.showModalWindow(data,callBackFunction);
|
||||
}
|
||||
)
|
||||
} else{
|
||||
listInstance.noRecordSelectedAlert();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} ,{
|
||||
|
||||
|
||||
folderSubmit : function() {
|
||||
var aDeferred = jQuery.Deferred();
|
||||
jQuery('#addDocumentsFolder').on('submit',function(e){
|
||||
var validationResult = jQuery(e.currentTarget).validationEngine('validate');
|
||||
if(validationResult == true){
|
||||
var formData = jQuery(e.currentTarget).serializeFormData();
|
||||
var foldername = jQuery.trim(formData.foldername);
|
||||
formData.foldername = foldername;
|
||||
AppConnector.request(formData).then(
|
||||
function(data){
|
||||
aDeferred.resolve(data);
|
||||
}
|
||||
);
|
||||
}
|
||||
e.preventDefault();
|
||||
});
|
||||
return aDeferred.promise();
|
||||
},
|
||||
|
||||
updateCustomFilter : function (info){
|
||||
var folderId = info.folderId;
|
||||
var customFilter = jQuery("#customFilter");
|
||||
var constructedOption = this.constructOptionElement(info);
|
||||
var optionId = 'filterOptionId_'+folderId;
|
||||
var optionElement = jQuery('#'+optionId);
|
||||
if(optionElement.length > 0){
|
||||
optionElement.replaceWith(constructedOption);
|
||||
customFilter.trigger("liszt:updated");
|
||||
} else {
|
||||
customFilter.find('#foldersBlock').append(constructedOption).trigger("liszt:updated");
|
||||
}
|
||||
},
|
||||
|
||||
constructOptionElement : function(info){
|
||||
var cvId = this.getCurrentCvId();
|
||||
return '<option data-deletable="1" data-folderid="'+info.folderid+'" data-foldername="'+info.folderName+'" class="filterOptionId_folder'+info.folderid+' folderOption" id="filterOptionId_folder'+info.folderid+'" data-id="'+cvId+'" >'+info.folderName+'</option>';
|
||||
|
||||
},
|
||||
|
||||
moveDocuments : function(){
|
||||
var aDeferred = jQuery.Deferred();
|
||||
jQuery('#moveDocuments').on('submit',function(e){
|
||||
var formData = jQuery(e.currentTarget).serializeFormData();
|
||||
AppConnector.request(formData).then(
|
||||
function(data){
|
||||
aDeferred.resolve(data);
|
||||
}
|
||||
);
|
||||
e.preventDefault();
|
||||
});
|
||||
return aDeferred.promise();
|
||||
},
|
||||
|
||||
getDefaultParams : function() {
|
||||
var search_value = jQuery('#customFilter').find('option:selected').data('foldername');
|
||||
var customParams = {
|
||||
'folder_id' : 'folderid',
|
||||
'folder_value' : search_value
|
||||
}
|
||||
var params = this._super();
|
||||
jQuery.extend(params,customParams);
|
||||
return params;
|
||||
},
|
||||
|
||||
registerDeleteFilterClickEvent: function(){
|
||||
var thisInstance = this;
|
||||
var listViewFilterBlock = this.getFilterBlock();
|
||||
if(listViewFilterBlock != false){
|
||||
//used mouseup event to stop the propagation of customfilter select change event.
|
||||
listViewFilterBlock.on('mouseup','li i.deleteFilter',function(event){
|
||||
//to close the dropdown
|
||||
thisInstance.getFilterSelectElement().data('select2').close();
|
||||
var liElement = jQuery(event.currentTarget).closest('.select2-result-selectable');
|
||||
var message = app.vtranslate('JS_LBL_ARE_YOU_SURE_YOU_WANT_TO_DELETE');
|
||||
if(liElement.hasClass('folderOption')){
|
||||
if(liElement.find('.deleteFilter').hasClass('dull')){
|
||||
Vtiger_Helper_Js.showPnotify(app.vtranslate('JS_FOLDER_IS_NOT_EMPTY'));
|
||||
return;
|
||||
} else {
|
||||
Vtiger_Helper_Js.showConfirmationBox({'message' : message}).then(
|
||||
function(e) {
|
||||
var currentOptionElement = thisInstance.getSelectOptionFromChosenOption(liElement);
|
||||
var folderId = currentOptionElement.data('folderid');
|
||||
var params = {
|
||||
module : app.getModuleName(),
|
||||
mode : 'delete',
|
||||
action : 'Folder',
|
||||
folderid : folderId
|
||||
}
|
||||
AppConnector.request(params).then(function(data) {
|
||||
if(data.success) {
|
||||
currentOptionElement.remove();
|
||||
thisInstance.getFilterSelectElement().trigger('change');
|
||||
}
|
||||
})
|
||||
},
|
||||
function(error, err){
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
} else {
|
||||
Vtiger_Helper_Js.showConfirmationBox({'message' : message}).then(
|
||||
function(e) {
|
||||
var currentOptionElement = thisInstance.getSelectOptionFromChosenOption(liElement);
|
||||
var deleteUrl = currentOptionElement.data('deleteurl');
|
||||
var newEle = '<form action='+deleteUrl+' method="POST"><input type="hidden" name="'+csrfMagicName+'" value="'+csrfMagicToken+'"/></form>';
|
||||
var form = new jQuery(newEle);
|
||||
form.appendTo('body').submit();
|
||||
},
|
||||
function(error, err){
|
||||
}
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
performFilterImageActions : function(liElement) {
|
||||
jQuery('.filterActionImages').clone(true,true).removeClass('filterActionImages').addClass('filterActionImgs').appendTo(liElement.find('.select2-result-label')).show();
|
||||
var currentOptionElement = this.getSelectOptionFromChosenOption(liElement);
|
||||
var deletable = currentOptionElement.data('deletable');
|
||||
if(deletable != '1'){
|
||||
if(liElement.hasClass('folderOption')){
|
||||
liElement.find('.deleteFilter').addClass('dull');
|
||||
}else{
|
||||
liElement.find('.deleteFilter').remove();
|
||||
}
|
||||
}
|
||||
if(liElement.hasClass('defaultFolder')) {
|
||||
liElement.find('.deleteFilter').remove();
|
||||
}
|
||||
var editable = currentOptionElement.data('editable');
|
||||
if(editable != '1'){
|
||||
liElement.find('.editFilter').remove();
|
||||
}
|
||||
var pending = currentOptionElement.data('pending');
|
||||
if(pending != '1'){
|
||||
liElement.find('.approveFilter').remove();
|
||||
}
|
||||
var approve = currentOptionElement.data('public');
|
||||
if(approve != '1'){
|
||||
liElement.find('.denyFilter').remove();
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
Vtiger_Base_Validator_Js("Vtiger_FolderName_Validator_Js",{
|
||||
|
||||
/**
|
||||
*Function which invokes field validation
|
||||
*@param accepts field element as parameter
|
||||
* @return error if validation fails true on success
|
||||
*/
|
||||
invokeValidation: function(field, rules, i, options){
|
||||
var instance = new Vtiger_FieldLabel_Validator_Js();
|
||||
instance.setElement(field);
|
||||
var response = instance.validate();
|
||||
if(response != true){
|
||||
return instance.getError();
|
||||
}
|
||||
}
|
||||
|
||||
},{
|
||||
/**
|
||||
* Function to validate the field label
|
||||
* @return true if validation is successfull
|
||||
* @return false if validation error occurs
|
||||
*/
|
||||
validate: function(){
|
||||
var fieldValue = this.getFieldValue();
|
||||
return this.validateValue(fieldValue);
|
||||
},
|
||||
|
||||
validateValue : function(fieldValue){
|
||||
var specialChars = /[&\<\>\:\'\"\,\_]/ ;
|
||||
|
||||
if (specialChars.test(fieldValue)) {
|
||||
var errorInfo = app.vtranslate('JS_SPECIAL_CHARACTERS')+" & < > ' \" : , _ "+app.vtranslate('JS_NOT_ALLOWED');
|
||||
this.setError(errorInfo);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user