Advertisement
Guest User

ParameterNewCtrl

a guest
Apr 24th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. gisApp.controller("ParameterNewCtrl", ['$scope', 'searchService', 'reportPageService', 'notificationService', 'apiService', 'modalService', '$translate', '$route', '$filter', '$location', 'membershipService', 'reportingService', '$http', '$sce', function ($scope, searchService, reportPageService, notificationService, apiService, modalService, $translate, $route, $filter, $location, membershipService, reportingService, http, sce) {
  2.     var translate = $filter('translate');
  3.     var allJsonTemp = [];
  4.     $scope.addFieldOnClick = addFieldOnClick;
  5.     $scope.back = back;
  6.     $scope.Add = Add;
  7.     $scope.Save = Save;
  8.     $scope.updateMasterParaChange = updateMasterParaChange;
  9.     $scope.SaveJsonReport = SaveJsonReport;
  10.     $scope.NewField = NewField;
  11.     $scope.reset = reset;
  12.     $scope.ClearFields = ClearFields;
  13.     $scope.DefualtValues = DefualtValues;
  14.     $scope.deleteParameter = deleteParameter;
  15.     $scope.params = [];
  16.     $scope.control = [];
  17.     $scope.reportKey = reportPageService.selectedRowId;
  18.     var saveflag = true;
  19.     $scope.SaveBtn = translate('Save');
  20.     $scope.NoMapping = true;
  21.     $scope.hasError = true;
  22.     var PreFunction = [];
  23.     $scope.AddtoStaticList = AddtoStaticList;
  24.     $scope.paramProperties = false;
  25.     var deleteParam = '';
  26.     var staticListData = [];
  27.  
  28.  
  29.     function AddtoStaticList() {
  30.         if ($scope.StaticValue != '' && $scope.StaticValue != undefined && $scope.Statickey != '' && $scope.Statickey != undefined) {
  31.             var DDL = { DDLValue: $scope.StaticValue, DDLKey: $scope.Statickey };
  32.             staticListData.push(DDL)
  33.             $scope.staticList = staticListData;
  34.             $scope.StaticValue = '';
  35.             $scope.Statickey = '';
  36.         }
  37.         else {
  38.             notificationService.displayError('Static Value and Static key are required');
  39.         }
  40.  
  41.  
  42.     }
  43.  
  44.     function deleteParameter(paramName) {
  45.         /*deleting the params from master json */
  46.         deleteParam = paramName;
  47.         modalService.confirm("Are you sure want to delete this Parameter? Please be aware this parameter will be removed from all files").then(function (result) {
  48.             var modal = {
  49.                 ParameterName: paramName
  50.             };
  51.             modalService.startProgress();
  52.             apiService.post(rootDir + 'Api/ReportApi/DeleteParamter/', modal, DeleteParamterLoadCompleted, DeleteParamterLoadFailed);
  53.  
  54.         });
  55.     }
  56.     function DeleteParamterLoadFailed(result) {
  57.         modalService.stopProgress();
  58.         notificationService.displaySuccess("Failed to perform operation.");
  59.     }
  60.     function DeleteParamterLoadCompleted(result) {
  61.         modalService.stopProgress();
  62.         notificationService.displaySuccess("Operation performed successfully.");
  63.  
  64.         $scope.masterControls = result.data.jsonParameters;
  65.         NewField();
  66.         $scope.removeField(deleteParam);
  67.  
  68.     }
  69.  
  70.     function updateMasterParaChange() {
  71.         if ($scope.updateMasterPara) {
  72.  
  73.             for (j = 0; j < $scope.reportControls.length; j++) {
  74.                 if ($scope.reportControls[j].ParameterName == $scope.ParameterName) {
  75.                     allJsonTemp.push($scope.reportControls[j]);
  76.                 }
  77.             }
  78.         }
  79.         else {
  80.             for (j = 0; j < $scope.reportControls.length; j++) {
  81.                 if ($scope.reportControls[j].ParameterName == $scope.ParameterName) {
  82.                     allJsonTemp.splice($scope.reportControls[j], 1);
  83.                 }
  84.             }
  85.         }
  86.     }
  87.  
  88.     function ClearFields() {
  89.         $scope.MaxValue = null;
  90.         $scope.MaxLength = null;
  91.         $scope.MinValue = null;
  92.         $scope.FieldType = 'Text';
  93.         $scope.Search = null;
  94.         $scope.Required = false;
  95.         $scope.TableName = null;
  96.         $scope.TableKey = null;
  97.         $scope.TableValue = null;
  98.         $scope.TableFilters = null;
  99.         $scope.StaticValue = null;
  100.         $scope.Statickey = null;
  101.         $scope.LanguageValue = null;
  102.  
  103.     }
  104.     function NewField() {
  105.         $scope.paramProperties = true;
  106.         $scope.EditMode = false;
  107.         $scope.Caption = '';
  108.         $scope.ParameterName = '';
  109.         $scope.DefaultValue = null;
  110.         $scope.ControlType = 'Text';
  111.         $scope.Caption = null;
  112.         $scope.MaxValue = null;
  113.         $scope.MaxLength = null;
  114.         $scope.MinValue = null;
  115.         $scope.FieldType = 'Text';
  116.         $scope.Search = null;
  117.         $scope.Required = false;
  118.         $scope.TableName = null;
  119.         $scope.TableKey = null;
  120.         $scope.TableValue = null;
  121.         $scope.TableFilters = null;
  122.         $scope.LookupSource = null;
  123.         $scope.refTables = null;
  124.         $scope.LanguageFilter = null;
  125.         $scope.updateMasterPara = null;
  126.         $scope.DDLLanguageFilter = null;
  127.         $scope.LanguageValue = null;
  128.         staticListData = [];
  129.         $scope.staticList = []
  130.         $scope.StaticValue = null;
  131.         $scope.Statickey = null;
  132.         $scope.SaveBtn = translate('Save');
  133.         saveflag = true;
  134.         $scope.myForm.$setPristine();
  135.     }
  136.  
  137.     $scope.removeField = function (paramName) {
  138.         //removing the control from control
  139.         $scope.PRT_REF_NOList = [];
  140.         saveflag = false;
  141.         for (i = 0; i < $scope.reportControls.length; i++) {
  142.             if ($scope.reportControls[i].ParameterName == paramName) {
  143.                 $scope.reportControls.splice(i, 1);
  144.             }
  145.         }
  146.         NewField();
  147.  
  148.     };
  149.  
  150.     $scope.mouseEnter = function (control) {
  151.         control.Active = true;
  152.     }
  153.     $scope.mouseLeave = function (control) {
  154.         control.Active = false;
  155.     }
  156.     $scope.activeField = function (control) {
  157.         // setting data the selected control
  158.  
  159.         for (var x in $scope.refTablesList) {
  160.             if ($scope.refTablesList[x].TableName == control.RefTableName) $scope.refTables = $scope.refTablesList[x]
  161.         }
  162.  
  163.         $scope.paramProperties = true;
  164.         $scope.SaveBtn = 'Edit';
  165.         $scope.Caption = control.Caption;
  166.         $scope.ParameterName = control.ParameterName;
  167.         $scope.DefaultValue = control.DefaultValue;
  168.         $scope.ControlType = control.Type;
  169.         $scope.Caption = control.Caption;
  170.         $scope.MinValue = control.Min;
  171.         $scope.MaxValue = control.Max;
  172.         $scope.MaxLength = control.MaxLength;
  173.         $scope.FieldType = control.FieldType;
  174.         $scope.Search = control.Search;
  175.         $scope.Required = control.Required;
  176.         $scope.TableName = control.DDLTableName;
  177.         $scope.TableKey = control.DDLKey;
  178.         $scope.TableValue = control.DDLValue;
  179.         $scope.TableFilters = control.DDLFilters;
  180.         $scope.LookupSource = control.LookupSource;
  181.         $scope.updateMasterPara = control.updateMasterPara;
  182.         $scope.staticList = control.StaticList;
  183.         staticListData = control.StaticList;
  184.         $scope.LanguageFilter = control.LanguageFilter;
  185.         $scope.LanguageValue = control.DDLLanguageFilter;
  186.         $scope.staticListData
  187.         saveflag = false;
  188.         $scope.EditMode = true;
  189.  
  190.         if (control.Search != '') {
  191.             $scope.DataSource = 'Search';
  192.         }
  193.  
  194.  
  195.  
  196.  
  197.  
  198.     };
  199.     $scope.setTabOrder = function (control, value) {
  200.         //reorder the list based on user select
  201.         for (i = 0; i < $scope.reportControls.length; i++) {
  202.             if ($scope.reportControls[i] == control) {
  203.                 var newIndex = value === 'up' ? i - 1 : i + 1;
  204.                 var temp = $scope.reportControls[i];
  205.                 if ($scope.reportControls[newIndex] != undefined) {
  206.                     $scope.reportControls[i] = $scope.reportControls[newIndex];
  207.                     $scope.reportControls[newIndex] = temp;
  208.                 }
  209.                 return;
  210.             }
  211.         }
  212.  
  213.     };
  214.  
  215.     $scope.SelectedReport = reportPageService.selectedReport;
  216.     function Add() {
  217.         if ($scope.myForm.$valid) {
  218.             var filter = null;
  219.             if ($scope.ControlType == 'Lookup') $scope.FieldType = 'Lookup';
  220.             if ($scope.ControlType == 'DateTime') $scope.FieldType = 'DateTime';
  221.             if ($scope.ControlType == 'Checkbox') $scope.FieldType = 'Checkbox';
  222.             if ($scope.ControlType == 'Radio') $scope.FieldType = 'Radio';
  223.             var ParameterNameNoSpaces = $scope.ParameterName.replace(/ /g, "");
  224.             if (!$scope.LanguageFilter) $scope.LanguageValue = null;
  225.             if ($scope.TableFilters != '' && $scope.TableFilters != null) filter = $scope.TableFilters.replace(/(\r\n|\n|\r)/gm, "");
  226.             if ($scope.refTables == null) var reftable = null
  227.             else reftable = $scope.refTables.TableName;
  228.  
  229.             var model = {
  230.                 Caption: $scope.Caption,
  231.                 ParameterName: ParameterNameNoSpaces,
  232.                 Value: $scope.DefaultValue,
  233.                 Type: $scope.ControlType,
  234.                 Max: $scope.MaxValue,
  235.                 Min: $scope.MinValue,
  236.                 MaxLength: $scope.MaxLength,
  237.                 FieldType: $scope.FieldType,
  238.                 DDLTableName: $scope.TableName,
  239.                 DDLKey: $scope.TableKey,
  240.                 DDLValue: $scope.TableValue,
  241.                 DDLFilters: filter,
  242.                 Search: $scope.Search,
  243.                 Required: $scope.Required,
  244.                 LookupSource: $scope.LookupSource,
  245.                 RefTableName: reftable,
  246.                 StaticList: staticListData,
  247.                 LanguageFilter: $scope.LanguageFilter,
  248.                 DDLLanguageFilter: $scope.LanguageValue
  249.  
  250.             };
  251.  
  252.             apiService.post(rootDir + 'Api/ReportApi/UpdateMasterJson/', model, masterJsonSaveCompleted, masterJsonSaveFailed);
  253.  
  254.         }
  255.  
  256.     }
  257.     function addFieldOnClick(p) {
  258.         $scope.PRT_REF_NOList = [];
  259.         $scope.SaveBtn = 'Edit';
  260.         for (i = 0; i < $scope.reportControls.length; i++) {
  261.             if ($scope.reportControls[i].ParameterName == p) {
  262.                 return;
  263.  
  264.             }
  265.         }
  266.  
  267.         for (i = 0; i < $scope.masterControls.length; i++) {
  268.             if ($scope.masterControls[i].ParameterName == p) {
  269.                 $scope.reportControls.push($scope.masterControls[i]);
  270.  
  271.                 $scope.activeField($scope.masterControls[i]);
  272.             }
  273.         }
  274.  
  275.     }
  276.  
  277.     function ReadJSON() {
  278.  
  279.         var modal = {
  280.             reportKey: $scope.reportKey
  281.         };
  282.         apiService.post(rootDir + 'Api/ReportApi/ReadJsonTemplate/', modal, ReadJSONLoadCompleted, ReadJSONLoadFailed);
  283.     }
  284.  
  285.  
  286.     function ReadJSONLoadFailed(result) {
  287.         notificationService.displayError(result.data.ExceptionMessage);
  288.     }
  289.  
  290.  
  291.     function DefualtValues() {
  292.         //restting the data to defualt incase of seleting ddl
  293.  
  294.         $scope.TableName = $scope.refTables.TableName;
  295.         var editedNoTxt = $scope.TableName.replace('_TXT', '');
  296.  
  297.         if ($scope.refTables.TablePrefix != '') {
  298.             $scope.TableKey = editedNoTxt + '_Key';
  299.             $scope.TableValue = $scope.refTables.TablePrefix + '_DESC';
  300.             $scope.LanguageValue = $scope.refTables.TablePrefix + '_LANG_CDE';
  301.         }
  302.         else {
  303.             $scope.TableKey = editedNoTxt + '_Key';
  304.             $scope.TableValue = editedNoTxt + '_DESC';
  305.             $scope.LanguageValue = editedNoTxt + '_LANG_CDE';
  306.         }
  307.  
  308.     }
  309.  
  310.     function back() {
  311.         $location.path('reports/ReportList');
  312.     }
  313.     function ReadJSONLoadCompleted(result) {
  314.         $scope.masterControls = result.data.masterjson;
  315.         $scope.reportControls = result.data.jsonParameters.ParameterList;
  316.         $scope.PRT_REF_NO = result.data.jsonParameters.PrtRefNo;
  317.         $scope.PRT_REF_NO_SEQ = result.data.jsonParameters.PrtRefNoSeq;
  318.         $scope.refTablesList = result.data.reftables;
  319.         var PreTrigger = $scope.SelectedReport.PreTrigger; if (PreTrigger != "") PreFunction.push(PreTrigger);
  320.         var preCretria = $scope.SelectedReport.Criteria; if (preCretria != "") PreFunction.push(preCretria);
  321.         var postTrigger = $scope.SelectedReport.PostTrigger; if (postTrigger != "") PreFunction.push(postTrigger);
  322.  
  323.  
  324.         /// displaying mapping ddl if the pre/post trigger and precretria has data
  325.         if (PreTrigger.indexOf("#PRT_REF_NO#") !== -1 || PreTrigger.indexOf("#PRT_REF_NO_SEQ#") !== -1) $scope.NoMapping = false;
  326.         else if (preCretria.indexOf("#PRT_REF_NO#") !== -1 || preCretria.indexOf("#PRT_REF_NO_SEQ#") !== -1) $scope.NoMapping = false;
  327.         else if (postTrigger.indexOf("#PRT_REF_NO#") !== -1 || postTrigger.indexOf("#PRT_REF_NO_SEQ#") !== -1) $scope.NoMapping = false;
  328.  
  329.  
  330.         $scope.PRT_REF_NOList = $scope.reportControls;
  331.  
  332.         // mapping the ddl data based on paramter name to ddl
  333.         var data = result.data.DDLlist;
  334.         if (data.length > 0) {
  335.             for (i = 0; i < $scope.reportControls.length; i++) {
  336.                 var DDLdata = [];
  337.                 for (x = 0; x < data.length; x++) {
  338.                     if (data[x].ParameterName == $scope.reportControls[i].ParameterName) DDLdata.push(data[x]);
  339.                 }
  340.                 $scope.reportControls[i].DDL = DDLdata;
  341.             }
  342.         }
  343.  
  344.  
  345.         $scope.FieldType = 'Text';
  346.         $scope.ControlType = 'Text';
  347.  
  348.  
  349.     }
  350.  
  351.     function verifySelect() {
  352.         var edited = '';
  353.         var ParameterNameNoSpaces = $scope.ParameterName.replace(/ /g, "");
  354.  
  355.         let regExp = new RegExp(/(#[a-z0-9][a-z0-9\-_]*#)/ig);
  356.         if ($scope.TableFilters != '' && $scope.TableFilters != null) {
  357.             var filter = $scope.TableFilters.replace(/(\r\n|\n|\r)/gm, "");
  358.  
  359.             var params = filter.match(regExp);
  360.             if (params != null) {
  361.  
  362.  
  363.                 for (i = 0; i < $scope.reportControls.length; i++) {
  364.                     for (x = 0; x < params.length; x++) {
  365.                         if ('#' + $scope.reportControls[i].ParameterName.toUpperCase() + '#' == params[x].toUpperCase()) {
  366.                             if ($scope.reportControls[i].FieldType == 'Text')     filter = filter.replace(params[x], "'TEST'")
  367.                             if ($scope.reportControls[i].FieldType == 'Number')   filter = filter.replace(params[x], 0)
  368.                             if ($scope.reportControls[i].FieldType == 'DateTime') filter = filter.replace(params[x], 'sysdate')
  369.                             if ($scope.reportControls[i].FieldType == 'Checkbox') filter = filter.replace(params[x], "'Y'")
  370.                             if ($scope.reportControls[i].FieldType == 'Lookup')   filter = filter.replace(params[x], 0)
  371.                         }
  372.  
  373.                     }
  374.                 }
  375.             }
  376.         }
  377.         if ($scope.refTables == null) var reftable = null
  378.         else reftable = $scope.refTables.TableName;
  379.         if (filter != undefined && filter != '') {
  380.             var check = filter.match(regExp);
  381.             if (check != null) {
  382.                 notificationService.displayError("The following parameters is not available in report template X", check);
  383.                 return;
  384.             }
  385.         }
  386.         var model = {
  387.             ParameterName: ParameterNameNoSpaces,
  388.             FieldType: $scope.FieldType,
  389.             DDLTableName: $scope.TableName,
  390.             DDLKey: $scope.TableKey,
  391.             DDLValue: $scope.TableValue,
  392.             DDLFilters: filter,
  393.             LanguageFilter : $scope.LanguageFilter,
  394.             DDLLanguageFilter : $scope.LanguageValue
  395.  
  396.  
  397.         };
  398.  
  399.         apiService.post(rootDir + 'Api/reportApi/VerifySelect/', model, verifySelectCompleted, verifySelectFailed);
  400.  
  401.     }
  402.  
  403.     function verifySelectCompleted(result) {
  404.         for (i = 0; i < $scope.reportControls.length; i++) {
  405.             if ($scope.reportControls[i].ParameterName == $scope.ParameterName) {
  406.  
  407.                 var filter = null;
  408.                 if ($scope.ControlType == 'Lookup') $scope.FieldType = 'Lookup';
  409.                 if ($scope.ControlType == 'DateTime') $scope.FieldType = 'DateTime';
  410.                 if ($scope.ControlType == 'Checkbox') $scope.FieldType = 'Checkbox';
  411.                 if ($scope.LookupSource != 'Static') staticListData = [];
  412.                
  413.                 if ($scope.ControlType == 'Radio') $scope.FieldType = 'Radio';
  414.                 if (!$scope.LanguageFilter) $scope.LanguageValue = null;
  415.                 var ParameterNameNoSpaces = $scope.ParameterName.replace(/ /g, "");
  416.                 if ($scope.TableFilters != '' && $scope.TableFilters != null) filter = $scope.TableFilters.replace(/(\r\n|\n|\r)/gm, "");
  417.  
  418.                 if ($scope.refTables == null) var reftable = null
  419.                 else reftable = $scope.refTables.TableName;
  420.                
  421.  
  422.                 $scope.reportControls[i].ParameterName = ParameterNameNoSpaces;
  423.                 $scope.reportControls[i].DefaultValue = $scope.DefaultValue;
  424.                 $scope.reportControls[i].Type = $scope.ControlType;
  425.                 $scope.reportControls[i].Caption = $scope.Caption;
  426.                 $scope.reportControls[i].Min = $scope.MinValue;
  427.                 $scope.reportControls[i].Max = $scope.MaxValue;
  428.                 $scope.reportControls[i].MaxLength = $scope.MaxLength;
  429.                 $scope.reportControls[i].FieldType = $scope.FieldType;
  430.                 $scope.reportControls[i].ReferentialCode = $scope.ReferentialCode;
  431.                 $scope.reportControls[i].Search = $scope.Search;
  432.                 $scope.reportControls[i].Required = $scope.Required;
  433.                 $scope.reportControls[i].DDLTableName = $scope.TableName;
  434.                 $scope.reportControls[i].DDLKey = $scope.TableKey;
  435.                 $scope.reportControls[i].DDLValue = $scope.TableValue;
  436.                 $scope.reportControls[i].DDLFilters = filter;// $scope.TableFilters;
  437.                 $scope.reportControls[i].LookupSource = $scope.LookupSource;
  438.                 $scope.reportControls[i].StaticList = staticListData;
  439.                 $scope.reportControls[i].updateMasterPara = $scope.updateMasterPara;
  440.                 $scope.reportControls[i].RefTableName = reftable;
  441.                 $scope.reportControls[i].LanguageFilter = $scope.LanguageFilter;
  442.                 $scope.reportControls[i].DDLLanguageFilter = $scope.LanguageValue;
  443.             }
  444.  
  445.  
  446.         }
  447.         notificationService.displaySuccess("Edited performed successfully.");
  448.     }
  449.  
  450.     function verifySelectFailed(result) {
  451.         notificationService.displayError(result.data.ExceptionMessage);
  452.     }
  453.  
  454.  
  455.     function Save() {
  456.  
  457.         if (saveflag) {
  458.             Add();
  459.         }
  460.         else {
  461.             if ($scope.myForm.$valid) {
  462.                 for (i = 0; i < $scope.reportControls.length; i++) {
  463.                     if ($scope.reportControls[i].ParameterName == $scope.ParameterName) {
  464.  
  465.                         var filter = null;
  466.                         if ($scope.ControlType == 'Lookup') {
  467.                             $scope.FieldType = 'Lookup';
  468.                             verifySelect();
  469.                         }
  470.                         if ($scope.ControlType == 'DateTime') $scope.FieldType = 'DateTime';
  471.                         if ($scope.ControlType == 'Checkbox') $scope.FieldType = 'Checkbox';
  472.                         if ($scope.ControlType == 'Radio') $scope.FieldType = 'Radio';
  473.                         if (!$scope.LanguageFilter) $scope.LanguageValue = null;
  474.                         var ParameterNameNoSpaces = $scope.ParameterName.replace(/ /g, "");
  475.                         if ($scope.TableFilters != '' && $scope.TableFilters != null) filter = $scope.TableFilters.replace(/(\r\n|\n|\r)/gm, "");
  476.  
  477.                         if ($scope.refTables == null) var reftable = null
  478.                         else reftable = $scope.refTables.TableName;
  479.  
  480.  
  481.                         $scope.reportControls[i].ParameterName = ParameterNameNoSpaces;
  482.                         $scope.reportControls[i].DefaultValue = $scope.DefaultValue;
  483.                         $scope.reportControls[i].Type = $scope.ControlType;
  484.                         $scope.reportControls[i].Caption = $scope.Caption;
  485.                         $scope.reportControls[i].Min = $scope.MinValue;
  486.                         $scope.reportControls[i].Max = $scope.MaxValue;
  487.                         $scope.reportControls[i].MaxLength = $scope.MaxLength;
  488.                         $scope.reportControls[i].FieldType = $scope.FieldType;
  489.                         $scope.reportControls[i].ReferentialCode = $scope.ReferentialCode;
  490.                         $scope.reportControls[i].Search = $scope.Search;
  491.                         $scope.reportControls[i].Required = $scope.Required;
  492.                         $scope.reportControls[i].DDLTableName = $scope.TableName;
  493.                         $scope.reportControls[i].DDLKey = $scope.TableKey;
  494.                         $scope.reportControls[i].DDLValue = $scope.TableValue;
  495.                         $scope.reportControls[i].DDLFilters = filter;// $scope.TableFilters;
  496.                         $scope.reportControls[i].LookupSource = $scope.LookupSource;
  497.                         $scope.reportControls[i].updateMasterPara = $scope.updateMasterPara;
  498.                         $scope.reportControls[i].RefTableName = reftable;
  499.                         $scope.reportControls[i].LanguageFilter = $scope.LanguageFilter;
  500.                         $scope.reportControls[i].DDLLanguageFilter = $scope.LanguageValue;
  501.                     }
  502.  
  503.  
  504.                 }
  505.                 if ($scope.ControlType != 'Lookup') notificationService.displaySuccess("Edit performed successfully.");
  506.  
  507.             }
  508.             else {
  509.                 notificationService.displayError("Failed to perform operation.");
  510.             }
  511.         }
  512.  
  513.     }
  514.  
  515.     function reset(input) {
  516.         if (input == 'MaxValue' && $scope.MaxValue == undefined) $scope.MaxValue = null;
  517.         if (input == 'MinValue' && $scope.MinValue == undefined) $scope.MinValue = null;
  518.         if (input == 'MaxLength' && $scope.MaxLength == undefined) $scope.MaxLength = null;
  519.         if (input == 'TableFilters' && $scope.TableFilters == undefined) $scope.TableFilters = null;
  520.         if (input == 'LanguageValues' && $scope.LanguageValues == undefined) $scope.LanguageValues = null;
  521.         if (input == 'Statickey' && $scope.Statickey == undefined) $scope.Statickey = null;
  522.         if (input == 'StaticValue' && $scope.StaticValue == undefined) $scope.StaticValue = null;
  523.        
  524.     }
  525.  
  526.  
  527.     function SaveJsonReport() {
  528.  
  529.         // fill PreFunction with pre/post trigger data and preCretria to check if any of the paramters is missing
  530.         var PRT_REF_NOInTrigger = false;
  531.         var PRT_REF_NO_SEQInTrigger = false;
  532.         let regExp = new RegExp(/(#[a-z0-9][a-z0-9\-_]*#)/ig);
  533.  
  534.         for (var x in PreFunction) {
  535.  
  536.             var PreFunctionArray = PreFunction[x].match(regExp);
  537.  
  538.             var params = [];
  539.             for (i in $scope.reportControls) {
  540.                 params.push('#' + $scope.reportControls[i].ParameterName + '#');
  541.  
  542.             }
  543.  
  544.             var difference = [];
  545.             if (PreFunctionArray != null) {
  546.                 jQuery.grep(PreFunctionArray, function (el) {
  547.                     if (jQuery.inArray(el, params) == -1) difference.push(el);
  548.                     if (el == '#PRT_REF_NO#')     PRT_REF_NOInTrigger = true;
  549.                     if (el == '#PRT_REF_NO_SEQ#') PRT_REF_NO_SEQInTrigger = true;
  550.                 });
  551.  
  552.                 for (diff in difference) {
  553.                     if (difference[diff] != '#PRT_REF_NO#' && difference[diff] != '#PRT_REF_NO_SEQ#' && difference[diff] != '#USER_ID#' && difference[diff] != '#LANG_CDE#' && difference[diff] != '#SYSDATE#') {
  554.                         notificationService.displayError("Missing Parameter X", difference[diff]);
  555.                         return;
  556.                     }
  557.  
  558.  
  559.                 }
  560.             }
  561.  
  562.             if (PRT_REF_NOInTrigger && $scope.PRT_REF_NO.length == 0) {
  563.                 notificationService.displayError("Missing Parameter PRT REF NO");
  564.                 return;
  565.             }
  566.  
  567.  
  568.             if (PRT_REF_NO_SEQInTrigger && $scope.PRT_REF_NO_SEQ.length == 0) {
  569.                 notificationService.displayError("Missing Parameter PRT REF NO SEQ");
  570.                 return;
  571.             }
  572.             PreFunctionArray = [];
  573.         }
  574.  
  575.  
  576.         // getting the list of update all json file allJsonList
  577.         var allJsonList = [];
  578.         for (var x in allJsonTemp) {
  579.             for (var i in $scope.reportControls) {
  580.                 if ($scope.reportControls[i].ParameterName == allJsonTemp[x].ParameterName) allJsonList.push($scope.reportControls[i])
  581.  
  582.             }
  583.         }
  584.  
  585.         if ($scope.reportControls.length == 0) {
  586.             notificationService.displayError("There is no Contorls defined");
  587.             return;
  588.         }
  589.         else if ($scope.reportKey == 0 || $scope.reportKey == null) {
  590.             notificationService.displayError("Invalid Report Selected");
  591.             return;
  592.         }
  593.  
  594.  
  595.         //  Saving the controls and prt ref no/seq data and and if there's any apply change to paramters
  596.         var JSONParameters =
  597.         {
  598.             ParameterList: $scope.reportControls,
  599.             PrtRefNo: $scope.PRT_REF_NO,
  600.             PrtRefNoSeq: $scope.PRT_REF_NO_SEQ
  601.  
  602.         };
  603.  
  604.         var model = {
  605.             reportKey: $scope.reportKey,
  606.             JSONParameters: JSONParameters,
  607.             UpdateAllJSON: allJsonList
  608.  
  609.  
  610.         };
  611.         apiService.post(rootDir + 'Api/reportApi/UpdateReportJson/', model, saveCompleted, saveFailed);
  612.     }
  613.     function masterJsonSaveCompleted(result) {
  614.         $scope.masterControls = result.data.jsonParameters;
  615.         notificationService.displaySuccess("Operation performed successfully.");
  616.         addFieldOnClick($scope.ParameterName);
  617.         NewField();
  618.         $scope.FieldType = 'Text';
  619.         allJsonTemp = [];
  620.         $scope.updateMasterPara = false;
  621.         $scope.paramProperties = false;
  622.  
  623.  
  624.     }
  625.     function masterJsonSaveFailed(result) {
  626.         notificationService.displayError(result.data);
  627.  
  628.     }
  629.  
  630.     function saveCompleted(result) {
  631.         allJsonTemp = [];
  632.         $scope.updateMasterPara = false;
  633.         $scope.masterControls = result.data.masterjson;
  634.         $scope.reportControls = result.data.jsonParameters.ParameterList;
  635.  
  636.         var data = result.data.DDLlist;
  637.         if (data.length > 0) {
  638.             for (i = 0; i < $scope.reportControls.length; i++) {
  639.                 var DDLdata = [];
  640.                 for (x = 0; x < data.length; x++) {
  641.                     if (data[x].ParameterName == $scope.reportControls[i].ParameterName) DDLdata.push(data[x]);
  642.                 }
  643.                 $scope.reportControls[i].DDL = DDLdata;
  644.             }
  645.         }
  646.  
  647.         NewField();
  648.         notificationService.displaySuccess("Operation performed successfully.");
  649.         $scope.myForm.$valid;
  650.         $scope.paramProperties = false;
  651.     }
  652.     function saveFailed(result) {
  653.         notificationService.displayError(result.data.ExceptionMessage);
  654.  
  655.     }
  656.  
  657.     $scope.resetDDLTables = function () {
  658.         $scope.TableName = null;
  659.         $scope.TableKey = null;
  660.         $scope.TableValue = null;
  661.         $scope.TableFilters = null;
  662.         $scope.StaticValue = null;
  663.         $scope.Statickey = null;
  664.         $scope.refTables = null;
  665.         $scope.LanguageValue = null;
  666.     }
  667.     ReadJSON();
  668.  
  669. }]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement