· 5 years ago · Mar 10, 2020, 11:14 AM
1jQuery.sap.require("sap.m.MessageBox");
2jQuery.sap.require("sap.m.MessageToast");
3
4jQuery.sap.require('com.tutorial.service.measureobject.MeasurementObjectTypesFactory' + m_urlVersion);
5jQuery.sap.require('com.tutorial.service.measureobject.MeasurementObjectTypesService' + m_urlVersion);
6jQuery.sap.require('com.tutorial.service.measureobject.MeasurementObjectSusageStatusFactory' + m_urlVersion);
7jQuery.sap.require('com.tutorial.service.measureobject.MeasurementObjectFrequencyFactory' + m_urlVersion);
8jQuery.sap.require('com.tutorial.service.measureobject.MeasurementObjectFactory' + m_urlVersion);
9jQuery.sap.require('com.tutorial.service.measureobject.MeasurementObjectUOMFactory' + m_urlVersion);
10jQuery.sap.require('com.tutorial.service.measureobject.MeasurementObjectAGGREGATIONFactory' + m_urlVersion);
11jQuery.sap.require('com.tutorial.service.measureobject.MeasurementObjectPMOFactory' + m_urlVersion);
12jQuery.sap.require('com.tutorial.service.measureobject.MeasurementObjectPKPrimaryInfoFactory' + m_urlVersion);
13jQuery.sap.require('com.tutorial.service.measureobject.MeasurementObjectLegFactory' + m_urlVersion);
14jQuery.sap.require('com.tutorial.service.measureobject.MeasurementObjectGetChildFactory' + m_urlVersion);
15jQuery.sap.require('com.tutorial.service.measureobject.MeasurementObjectSolutionFactory' + m_urlVersion);
16jQuery.sap.require('com.tutorial.service.measureobject.MeasurementObjectFeatureFactory' + m_urlVersion);
17jQuery.sap.require("com.tutorial.util.Formatter" + m_urlVersion);
18jQuery.sap.require("com.tutorial.util.Utils" + m_urlVersion);
19
20
21var varPath;
22var packNameForMO;
23var contextID;
24var that;
25var that2;
26var extendedAttributesTableData;
27var userDefinedAttributes;
28var stereotypeAttributes;
29var username;
30var valueListArray;
31
32jQuery.ajax({
33 url: userUrl,
34 method: 'GET',
35 dataType: 'json',
36
37 success: function(user)
38 {
39 username = user.USER;
40 },
41 error: function(XHR, Status, Error)
42 {
43 var error = Error;
44 console.log(XHR.responseText);
45 username = "default";
46 }
47});
48
49sap.ui.controller("ui5_routing.AddMo2", {
50 // the method handleNavBack is triggered when the back button is pressed
51 handleNavBack : function(oEvent) {
52 this.resetField();
53 var router = sap.ui.core.UIComponent.getRouterFor(this);
54 if (varPath != undefined)
55 router.navTo("Detail", {
56 contextPath : varPath,
57 contextID : contextID
58 });
59 else
60 if (sap.ui.getCore().byId("iconTabBar1") == undefined)
61 router.navTo("main");
62 else {
63 router.navTo("main", {
64 query : {
65 tab : sap.ui.getCore().byId("iconTabBar1").getSelectedKey()
66 }
67 }, true);
68 }
69 var that = this;
70 var moprodService = com.tutorial.service.measureobject.MeasurementObjectPMOFactory.getInstance();
71 moprodService.loadModel({
72 endpointParam : varPath,
73 successFunc : function(moData, response) {
74 var oModelMo = new sap.ui.model.json.JSONModel();
75 oModelMo.setData(moData.results[0]);
76 that.getView().setModel(oModelMo);
77 oModelMo.updateBindings(true);
78
79 },
80 errorFunc : function() {
81 var msg = 'Unsuccessfully added';
82 sap.m.MessageToast.show(msg);
83 }
84 })
85 },
86
87 onInit : function() {
88
89 that2 = this;
90 this.router = sap.ui.core.UIComponent.getRouterFor(this);
91 console.log("Hi in add for MO --" + this._oRouter);
92 this.router.attachRoutePatternMatched(this._handleRouteMatched, this);
93 var model = new sap.ui.model.odata.v2.ODataModel(m_xsodata);
94 this.getView().setModel(model, "techs");
95 },
96 // the method _handleRouteMatched is triggered after navigation to this page
97 // (this is necessary for routing)
98 // _handleRouteMatched is a hook method for the router and will be called
99 // automatically by the framework, after the view is rendered
100 // in this method are binded the necessary models on the AddMo2 view
101 _handleRouteMatched : function(oEvent) {
102
103 var table = this.byId("addMoTable");
104 jQuery.ajax({
105 url : "https://ifd.wdf.sap.corp/usag/morepository/MOREPOSITORY/Usage.xsodata/ATTRIBUTE_VALUES",
106 method : 'GET',
107 dataType : 'xml',
108 success : function(data) {
109
110 valueListArray = []; //destroy all elements to prevent duplication
111 var tempArray = data.getElementsByTagName("m:properties");
112 for(var x = 0;x < tempArray.length;x++){
113 var attribute_ID = tempArray[x].childNodes[1].innerHTML;
114 var value_ID = tempArray[x].childNodes[2].innerHTML;
115 var value_text = tempArray[x].childNodes[3].innerHTML;
116 var description = tempArray[x].childNodes[4].innerHTML;
117
118 valueListArray.push({ATTRIBUTE_ID: attribute_ID, //Creates objects based on number of entries in EXTDEF_LIST_VALUES HANA table
119 VALUE_ID: value_ID,
120 VALUE_TEXT: value_text,
121 DESCRIPTION: description});
122 }
123
124 },
125 error : function(XHR, Status, Error) {
126 alert(Error);
127 }
128 });
129
130 jQuery.ajax({
131 url : userUrl,
132 method : 'GET',
133 dataType : 'json',
134 success : function(user) {
135 username = user.USER;
136 console.log("owneeeeeeeeeer1" + username)
137 },
138 error : function(XHR, Status, Error) {
139 var error = Error;
140 console.log(XHR.responseText);
141 username = "default";
142 }
143 });
144
145 var oParam = oEvent.getParameter("name");
146 if (oParam !== "AddMo2") {
147 return;
148 }
149 var that = this;
150 varPath = oEvent.getParameter("arguments").contextPath;
151 contextID = oEvent.getParameter("arguments").contextID;
152
153 var oModel = new sap.ui.model.json.JSONModel();
154 oModel.setData({
155 enabledName : false,
156 enabledTech : false,
157 enabledDescription : false,
158 enabledLogic : false,
159 enabledFrequency : false,
160 enabledStereotype: false,
161 enabledMethod : false,
162 enabledUOM : false,
163 enabledAggregation : false,
164
165 });
166 this.getView().setModel(oModel, "typeMO");
167
168 console.log("Inside the Line Item " + varPath);
169 userDefinedAttributes = [];
170 if (varPath != undefined) {
171 var packageService = com.tutorial.service.measureobject.MeasurementObjectPKPrimaryInfoFactory.getInstance();
172
173 packageService.loadModel({
174 endpointParam : varPath,
175 successFunc : function(moData, response) {
176 packNameForMO = moData.results[0].NAME;
177 var productName = moData.results[0].PRODUCT_NAME;
178
179 sap.ui.getCore().byId("labelGlobalMO").setText("Measurement Object will be added to " + packNameForMO);
180 sap.ui.getCore().byId("productTextForSearchView").setText(productName);
181
182 },
183 errorFunc : function() {
184 console.log('error');
185 }
186 });
187
188 }
189
190 this.MOAssigments = {};
191
192 var oModelMoType = new sap.ui.model.json.JSONModel();
193 oModelMoType.setData({
194 MoTypes : [],
195 Uoms : [],
196 Aggregations : [],
197 Frequencies : [],
198 SusageStatuses : []
199 });
200
201 sap.ui.getCore().setModel(oModelMoType, 'model');
202
203 var motypesService = com.tutorial.service.measureobject.MeasurementObjectTypesFactory.getInstance();
204 var uomService = com.tutorial.service.measureobject.MeasurementObjectUOMFactory.getInstance();
205 var aggregationService = com.tutorial.service.measureobject.MeasurementObjectAGGREGATIONFactory.getInstance();
206 var frequency = com.tutorial.service.measureobject.MeasurementObjectFrequencyFactory.getInstance();
207 var susageStatus = com.tutorial.service.measureobject.MeasurementObjectSusageStatusFactory.getInstance();
208
209 frequency.loadModel({
210 successFunc : function(moData, response) {
211 sap.ui.getCore().getModel('model').getData().Frequencies = moData.results;
212 that.byId("listFrequency").setModel(sap.ui.getCore().getModel('model'));
213 sap.ui.getCore().getModel('model').updateBindings(true);
214 },
215 errorFunc : function() {
216
217 }
218 });
219 susageStatus.loadModel({
220 successFunc : function(moData, response) {
221 sap.ui.getCore().getModel('model').getData().SusageStatuses = moData.results;
222 that.byId("listStatus").setModel(sap.ui.getCore().getModel('model'));
223 sap.ui.getCore().getModel('model').updateBindings(true);
224 },
225 errorFunc : function() {
226
227 }
228 });
229 var oModel = new sap.ui.model.odata.ODataModel(m_xsodata, true);
230 var filters = [];
231 filters.push(new sap.ui.model.Filter("ID", sap.ui.model.FilterOperator.Contains, 'NEMO'));
232 var that = this;
233 oModel.read("/OBJTYPES", {
234 filters : filters,
235 success : function(oData, oResponse) {
236
237 sap.ui.getCore().getModel('model').getData().MoTypes = oData.results;
238 that.getView().byId('listMOType').setModel(sap.ui.getCore().getModel('model'));
239 that.getView().byId('listMOType').setSelectedItem(that.getView().byId('listMOType').getItems()[0]);
240 that.handleMotypeSelected();
241 }
242 });
243 // UOM
244 uomService.loadModel({
245 successFunc : function(moData, response) {
246 sap.ui.getCore().getModel('model').getData().Uoms = moData.results;
247 that.byId("listUOM").setModel(sap.ui.getCore().getModel('model'));
248 sap.ui.getCore().getModel('model').updateBindings(true);
249 },
250 errorFunc : function() {
251
252 }
253 });
254
255 aggregationService.loadModel({
256 successFunc : function(moData, response) {
257 sap.ui.getCore().getModel('model').getData().Aggregations = moData.results;
258 that.byId("listAGGREGATION").setModel(sap.ui.getCore().getModel('model'));
259 sap.ui.getCore().getModel('model').updateBindings(true);
260 },
261 errorFunc : function() {
262 }
263 });
264
265 this.MOAssigments2 = {
266 Product : null,
267 ProductID : '',
268 FeatureID : '',
269 Feature : null,
270 Solution : null,
271 SolutionID : ''
272 };
273
274 var oModelMo = new sap.ui.model.json.JSONModel();
275 oModelMo.setData({
276 Products : [],
277 Solutions : [],
278 Features : [],
279 });
280 sap.ui.getCore().setModel(oModelMo, 'pageModel');
281
282 var solutionService = com.tutorial.service.measureobject.MeasurementObjectSolutionFactory.getInstance();
283 var featureService = com.tutorial.service.measureobject.MeasurementObjectFeatureFactory.getInstance();
284
285
286 var oDataMOdel = new sap.ui.model.odata.ODataModel(m_xsodata);
287 oDataMOdel.read("/CV_NODE_PARENTSParameters(P_NODEID=\'" + varPath + "\')/Results/?$orderby=LEVEL", null, null, true, fSuccess, fError);
288 function fSuccess(oEvent) {
289
290 var parents = [];
291 parents = oEvent.results;
292 sap.ui.getCore().byId("PanelIdNavAdd").removeAllContentMiddle();
293 for ( var i in parents) {
294 if (i != 0) {
295 var breadcrumb = sap.ui.getCore().byId("PanelIdNavAdd").addContentMiddle(new sap.m.Text({
296 text : ">"
297
298 }).addStyleClass("textForArrow"))
299 }
300
301 var oLink = new sap.m.Button({
302 text : parents[i].NAME,
303 enabled : false
304
305 });
306 oLink.nodeid = parents[i].RESULT_NODE;
307 if (i == parents.length - 1)
308 oLink.addStyleClass("lastBreadcrumb");
309 var breadcrumb = sap.ui.getCore().byId("PanelIdNavAdd").addContentMiddle(oLink);
310 }
311 }
312 ;
313 function fError(oEvent) {
314 console.log("An error occured while reading Parents Data!")
315 }
316 ;
317
318 var oDataModelStereotypes = new sap.ui.model.odata.ODataModel(m_xsodata);
319 oDataModelStereotypes.read("/CL_STEREOTYPE_HIER_DETAILParameters" + "(IP_TYPE='" + 'MO' + "')/Results", null, null, true, fSuccessStereotypes, fErrorStereotypes);
320
321
322 function fSuccessStereotypes(oEvent) {
323
324 data = oEvent.results;
325 var listPopulator = that.byId("listStereotype");
326 listPopulator.destroyItems();
327 var listItem = new sap.m.StandardListItem({
328 title: "",
329 customData:[
330 new sap.ui.core.CustomData({
331 key:"KEY",
332 value: "valueeee"
333 }),
334 ]
335 })
336 listPopulator.addItem(listItem);
337
338 for(var item of data){
339
340 if(item.DESCRIPTION == null || item.DESCRIPTION == undefined || item.DESCRIPTION =='')
341 {
342 item.DESCRIPTION = item.NAME;
343 }
344 var listItem = that.quickhelp(
345 new sap.m.ObjectListItem({
346 title: item.PATH,
347 customData:[
348 new sap.ui.core.CustomData({
349 key:"KEY",
350 value: "valueeee"
351 }),
352 ]
353// press: that.onListItemPress
354
355 }),
356 item.DESCRIPTION
357 )
358
359 listPopulator.addItem(listItem);
360 }
361 that.MOAssigments.Stereotype = "";
362
363 };
364
365 function fErrorStereotypes(oEvent) {
366 console.log("An error occured while reading the data!")
367 };
368
369
370 },
371
372 handleStereotypeSelected : function(evt) {
373
374 var selectedItem = this.byId("listStereotype").getSelectedItem().getProperty("title");
375 var selectedID = this.byId("listStereotype").getSelectedItem().getTitle();
376 var moService = com.tutorial.service.measureobject.MeasurementObjectFactory.getInstance();
377
378 this.byId("inputStereotype").setValue(selectedItem);
379 this.byId("popoverStereotype").close();
380 sap.ui.getCore().byId("butonelSt").setIcon("sap-icon://cancel");
381 this.MOAssigments.Stereotype = selectedID;
382
383 var table = this.byId("addMoTable");
384 table.setVisible(true);
385
386 var stereoTypeList = evt.getParameters().listItem.mProperties.title;
387 var stereoTypeArray = stereoTypeList.split('/');
388 var stereoType = stereoTypeArray[stereoTypeArray.length - 1];
389
390 this.loadTableData(stereoType);
391 this.CalculateExtendedAttributes()
392
393 },
394
395 AddRecord: function(oEvent){
396
397 var that = this;
398
399 var oDialogAddRow = sap.ui.getCore().byId(this.createId('Dialog'));
400 var oDialogSaveButton = sap.ui.getCore().byId(this.createId('oDialogSaveButton'));
401 oDialogAddRow.setTitle("ADD A NEW RECORD");
402 var oLayout = new sap.ui.commons.layout.MatrixLayout({
403 columns: 2,
404 width: "100%"
405 });
406
407 var oFirstLabel= sap.ui.getCore().byId(this.createId('oFirstLabel'));
408 var oFirstTF = sap.ui.getCore().byId(this.createId('attrid'));
409 oFirstTF.setValue('');
410 oLayout.createRow(oFirstLabel, oFirstTF);
411
412 var oSecondLabel = sap.ui.getCore().byId(this.createId('oSecondLabel'));
413 var oSecondTF = sap.ui.getCore().byId(this.createId('valueid'));
414 oSecondTF.setValue('');
415 oLayout.createRow(oSecondLabel, oSecondTF);
416
417 oDialogAddRow.addContent(oLayout);
418 oDialogAddRow.open();
419
420 },
421
422 saveRecord: function(oEvent){
423
424 var that = this;
425 var attrTable = sap.ui.getCore().byId(this.createId('addMoTable'));
426 var oFirstTF = sap.ui.getCore().byId(this.createId('attrid'));
427 var oSecondTF = sap.ui.getCore().byId(this.createId('valueid'));
428 var attribute = oFirstTF.getValue();
429 var value = oSecondTF.getValue();
430 var existing = false;
431 attrTable.getItems().forEach(function(collListItem){
432 if(collListItem.getCells()[0].getText() == attribute){
433 existing = true;
434 }
435 })
436 if(attribute == "" || value == ""){
437 sap.m.MessageToast.show('Both values are mandatory!');
438 }
439 else if(attribute.indexOf(' ') > -1){
440 sap.m.MessageToast.show('Attribute name can not contain spaces');
441 }
442 else if(existing){
443 sap.m.MessageToast.show('Attribute allready exists');
444 }
445 else{
446 var columnListItem = new sap.m.ColumnListItem({
447
448 cells: [
449 new sap.m.Text({
450
451 text : attribute
452 }),
453 new sap.m.Input({
454
455 value : value,
456 width: "80%"
457 }),
458 new sap.m.Text({
459 text: username
460 })
461
462 ],
463
464 type: 'Active'
465 })
466
467 attrTable.addItem(columnListItem);
468 userDefinedAttributes.push({ DATATYPE: "String",
469 MANAGED_BY: username,
470 NAME: attribute,
471 VALUE: value});
472 sap.ui.getCore().byId(this.createId('Dialog')).close();
473 }
474 },
475
476 DeleteRecord: function(){
477 var that = this;
478 var attrTable = sap.ui.getCore().byId(this.createId('addMoTable'));
479 var toBeDeleted = attrTable.getSelectedItems();
480 toBeDeleted.forEach(function(attr){
481 if(attr.getCells()[2].getText() != "Stereotype" || attr.getText() == "Stereotype_Calculated"){
482 userDefinedAttributes = userDefinedAttributes.filter(toDelete => toDelete.NAME != attr.getCells()[0].getText() );
483
484 attrTable.removeItem(attr);
485 attr.destroy();
486 }
487 else{
488 sap.m.MessageToast.show('One or more attributes can not be deleted because they are managed by the stereotype');;
489 }
490 })
491 },
492
493 loadTableData: function (stereoType) {
494
495 var usageServicePath = com.tutorial.util.Utils.getUsageURL();
496 var model = "/CL_ALL_ATTRIBUTES_FOR_STEREOTYPEParameters";
497 var viewPath = model + "(IP_STEREOTYPE_ID='" + stereoType + "')/Results";
498 var that = this;
499
500 $.ajax({
501 async: true,
502 url: usageServicePath + viewPath,
503 type: 'GET',
504 cache: false,
505 dataType: 'JSON',
506 success: function (data) {
507 var results = data.d.results;
508 if (results.length > 0) {
509 that.bindTable(results);
510
511 } else {
512 that.bindTable([]);
513 }
514 },
515 error : function(XHR, Status, Error) {
516 alert(Error);
517 }
518 });
519
520 },
521 bindTable: function (results) {
522
523
524 var table = this.getView().byId(this.createId("addMoTable"));
525 table.destroyItems();
526 that = this;
527 that.extendedAttributes = [];
528 for (var i = 0; i < results.length; i++) {
529 // to do -> put the correct fields
530 var attributeListValues = valueListArray.filter(x => x.ATTRIBUTE_ID === results[i].NAME); //Filters on entries in EXTDEF_LIST_VALUES to get specific attribute entries as objects for loop instance
531 var mandatory = false;
532 var attribute = results[i].NAME;
533 var description = results[i].DESCRIPTION;
534 var placeholder = results[i].DEFAULTVALUE;
535 var displaytext = results[i].NAME;
536 var calculatedExpression = results[i].CALCULATED_EXPRESSION;
537 if(calculatedExpression != null && calculatedExpression != 'null' && calculatedExpression != ''){
538 calculatedExpression = calculatedExpression.replace('{', '()()').replace('}', '<><>')
539 }
540
541 if(results[i].MANDATORY =='Y'){
542 mandatory = true;
543 displaytext = displaytext + '*';
544 }
545
546 var managedBy = calculatedExpression == null || calculatedExpression == 'null' || calculatedExpression == '' ? "Stereotype" : "Stereotype_Calculated" ;
547 var type = managedBy == "SYSTEM" || managedBy =="Stereotype_Calculated" ? 'Inactive' :'Active';
548
549 that.extendedAttributes.push(results[i].NAME);
550 if(attributeListValues.length == 0){
551 var columnListItem = new sap.m.ColumnListItem({
552 cells: [
553 new sap.m.Label({
554 id: "Text" + attribute,
555 text: displaytext
556 }),
557 this.quickhelp(new sap.m.Input({
558 // todo --> map the input fields to the attribute or
559 // counter etc..
560 id: "Value" + attribute,
561 value: placeholder,
562 required: mandatory,
563 width: "80%",
564 editable: type=='Active' ? true : false,
565 change : function(){that.CalculateExtendedAttributes()}
566 }),description),
567 new sap.m.Text({
568 id: "Managed" + attribute,
569 text: managedBy
570 }),
571 new sap.m.Label({
572 id: "Stereotype_Calculated" + attribute,
573 text: calculatedExpression,
574 customData : [new sap.ui.core.CustomData({'key' : 'calculatedAtr','value' : calculatedExpression})],
575 visible : false
576 })
577 ]
578 })
579 }else{
580
581
582 var arraySpecificValues = new Array(); //create array to store current loop attribute values as ListItems
583
584 for(var x = 0; x < attributeListValues.length;x++){
585 var oItem = new sap.ui.core.ListItem(); //create ListItem for each value of current loop attribute to be used by ComboBox
586 oItem.setText(attributeListValues[x].VALUE_TEXT);
587 oItem.setAdditionalText(attributeListValues[x].DESCRIPTION);
588 arraySpecificValues.push(oItem);
589 }
590
591 var columnListItem = new sap.m.ColumnListItem({
592
593 cells: [
594 this.quickhelp( new sap.m.ComboBox({
595 id: "Value" + attribute,
596 value: results[i].VALUE,
597 items: arraySpecificValues,
598 showSecondaryValues: true
599 }),description),
600
601 new sap.m.Text({
602 id: "Managed" + attribute,
603 text: managedBy
604 }),
605 new sap.m.Label({
606 id: "Stereotype_Calculated" + attribute,
607 text: calculatedExpression,
608 customData : [new sap.ui.core.CustomData({'key' : 'calculatedAtr','value' : calculatedExpression})],
609 visible : false
610 })
611
612 ],
613 type:type
614 })
615 }
616
617
618 table.addItem(columnListItem);
619 }
620
621 for (var i = 0; i < userDefinedAttributes.length; i++) {
622 // to do -> put the correct fields
623 var attribute = userDefinedAttributes[i].NAME;
624 var value = userDefinedAttributes[i].VALUE;
625
626 var columnListItem = new sap.m.ColumnListItem({
627 cells: [
628 new sap.m.Label({
629 id: "Text" + attribute,
630 text: attribute
631 }),
632 new sap.m.Input({
633 // todo --> map the input fields to the attribute or
634 // counter etc..
635 id: "Value" + attribute,
636 value: value,
637 width: "80%"
638 }),
639 new sap.m.Text({
640 id: "Managed" + attribute,
641 text: username
642 })
643 ]
644 })
645
646 table.addItem(columnListItem);
647 }
648
649 that.CalculateExtendedAttributes();
650 },
651
652 CalculateExtendedAttributes: function(){
653 var existingAttributes = {};
654
655 var attrTable = sap.ui.getCore().byId(this.createId('addMoTable'));
656 var tableItems= attrTable.getItems();
657
658 for(var i=0;i< tableItems.length;i++){
659 var currentListItem = tableItems[i].getCells();
660 if(currentListItem[2].getText()=="Stereotype"){
661 var attrName ="";
662 var attrValue = "";
663 try{
664 attrName = currentListItem[0].getId().split("Text")[1];
665 attrValue = currentListItem[1].getValue();
666 }
667 catch(error){
668 console.log(error.toString());
669 }
670 existingAttributes[attrName] = attrValue;
671 }
672 }
673
674 var oTable = sap.ui.getCore().byId("addMoTable");
675 var that = this;
676 var oBus = sap.ui.getCore().getEventBus();
677 var moService = com.tutorial.service.measureobject.MeasurementObjectFactory.getInstance();
678 var moprodService = com.tutorial.service.measureobject.MeasurementObjectPMOFactory.getInstance();
679 var moKey = this.generateKey();
680 var router = sap.ui.core.UIComponent.getRouterFor(this);
681 var listMOTYPE;
682 that = this;
683
684 if (this.byId("listMOType").getSelectedItem() == null)
685 listMOTYPE = null;
686 else
687 listMOTYPE = this.byId("listMOType").getSelectedItem().getCustomData()[0].getValue();
688
689 var currentObject = {
690 "TECHNICAL_NAME" : sap.ui.getCore().byId('technicalNameFieldIdMO').getValue(),
691 "DESCRIPTION" : this.byId('descriptionFieldId').getValue(),
692 "KEY" : sap.ui.getCore().byId('technicalNameFieldIdMO').getValue(),
693 "NAME" : sap.ui.getCore().byId('keyTextFieldId').getValue(),
694 "DATE_OF_ENTER" : this.byId('dateFieldID').getValue(),
695 "FEATUREID" : null,
696 "PRODUCTID" : null,
697 "SOLUTIONID" : null,
698 "FEATURE" : null,
699 "PRODUCT" : null,
700 "SOLUTION" : null,
701 "MO_TYPE" : listMOTYPE,
702 "UNIT_OF_MEASURE" : this.MOAssigments.UOM,
703 "AGGREGATION" : this.MOAssigments.AGGREGATION,
704 "MO_LOGIC" : this.byId('moLogicFieldId').getValue(),
705 "MEASUREMENT_FREQUENCY" : this.MOAssigments.Frequency,
706 "MEASUREMENT_METHOD" : this.MOAssigments.Status,
707 "STEREOTYPE": this.MOAssigments.Stereotype.split('/').pop(),
708 "ACTIVE": 'yes',
709 "OWNER" : username
710 };
711
712 for(var i=0;i< tableItems.length;i++){
713 var currentListItem = tableItems[i].getCells();
714 if(currentListItem[2].getText()=="Stereotype_Calculated"){
715 var calculatedExpression = currentListItem[3].getCustomData()[0].getValue();
716 calculatedExpression = calculatedExpression.replace( '()()', '{').replace( '<><>', '}');
717
718 var attributeValue = "";
719
720 try{
721 eval(calculatedExpression);
722 }
723 catch (error){
724 console.log(error.toString());
725 }
726
727 currentListItem[1].setValue(attributeValue);
728 }
729 }
730
731
732
733 },
734
735
736// the method filterFrequency is called when the mouse is put on the input(id
737// "inputFrequency") of Measurement Frequency. At the mouse press the pop-up
738// with possible entries appear (id "listFrequency").
739 filterFrequency : function() {
740
741 var searchValue = jQuery.trim(this.byId("inputFrequency").getValue());
742 var showSearch = (searchValue.length !== 0);
743
744 var binding = this.byId("listFrequency").getBinding("items");
745 if (showSearch && binding !== undefined) {
746 var filters = [];
747 filters.push(new sap.ui.model.Filter("NAME", sap.ui.model.FilterOperator.Contains, searchValue));
748 binding.filter(filters);
749 } else {
750 binding.filter(false);
751 }
752 },
753 // the method handleFrequencySelected is called when a value from the list
754 // displayed (id: "listFrequency") is selected
755 handleFrequencySelected : function(evt) {
756 var selectedItem = this.byId("listFrequency").getSelectedItem().getProperty("title");
757 var selectedID = this.byId("listFrequency").getSelectedItem().getTitle();
758 var moService = com.tutorial.service.measureobject.MeasurementObjectFactory.getInstance();
759 var selectedResult;
760
761 switch(selectedID) {
762 case "Day":
763 selectedResult = "DA";
764 break;
765 case "Event":
766 selectedResult = "EV";
767 break;
768 case "Hour":
769 selectedResult = "HO";
770 break;
771 case "Minute":
772 selectedResult = "MI";
773 break;
774 case "Month":
775 selectedResult = "MO";
776 break;
777 case "Quarter":
778 selectedResult = "QA";
779 break;
780 case "Second":
781 selectedResult = "SE";
782 break;
783 case "Week":
784 selectedResult = "WE";
785 break;
786 case "Year":
787 selectedResult = "YE";
788 break;
789 }
790
791 this.byId("inputFrequency").setValue(selectedItem);
792 this.byId("popoverFrequency").close();
793 sap.ui.getCore().byId("butonelSys").setIcon("sap-icon://cancel");
794 this.MOAssigments.Frequency = selectedResult;
795
796 },
797
798 // the method handleStereotypeSelected is called when a value from the list
799 // displayed (id: "listStereotype") is selected
800 filterStereotype : function() {
801
802 var searchValue = jQuery.trim(this.byId("inputStereotype").getValue());
803 var showSearch = (searchValue.length !== 0);
804
805 var binding = this.byId("listStereotype").getBinding("items");
806 if (showSearch && binding !== undefined) {
807 var filters = [];
808 filters.push(new sap.ui.model.Filter("NAME", sap.ui.model.FilterOperator.Contains, searchValue));
809 binding.filter(filters);
810 } else {
811 binding.filter(false);
812 }
813 },
814
815
816 // the method filterStatus is called when the mouse is put on the input(id
817 // "inputStatus") of Measurement method. At the mouse press the pop-up with
818 // possible entries appear (id "listStatus").
819 filterStatus : function() {
820
821 var searchValue = jQuery.trim(this.byId("inputStatus").getValue());
822 var showSearch = (searchValue.length !== 0);
823
824 var binding = this.byId("listStatus").getBinding("items");
825 if (showSearch && binding !== undefined) {
826 var filters = [];
827 filters.push(new sap.ui.model.Filter("NAME", sap.ui.model.FilterOperator.Contains, searchValue)); // name
828
829 binding.filter(filters);
830 } else {
831 binding.filter(false);
832 }
833 },
834 // the method handleStatusSelected is called when a value from the list
835 // displayed (id: "listStatus") is selected
836 handleStatusSelected : function(evt) {
837 var selectedItem = this.byId("listStatus").getSelectedItem().getProperty("title");
838
839 var selectedID = this.byId("listStatus").getSelectedItem().getTitle();
840 var moService = com.tutorial.service.measureobject.MeasurementObjectFactory.getInstance();
841
842 this.byId("inputStatus").setValue(selectedItem);
843
844 this.byId("popoverStatus").close();
845 sap.ui.getCore().byId("butonelSysSusage").setIcon("sap-icon://cancel");
846 this.MOAssigments.Status = selectedID;
847
848 },
849 // the method filterMotype is called when the mouse is put on the input(id
850 // "inputMOType") of Measurement Object Type. At the mouse press the pop-up
851 // with possible entries appear (id "listMOType").
852 filterMotype : function() {
853
854 var searchValue = jQuery.trim(sap.ui.getCore().byId('inputMOType').getValue());
855 var showSearch = (searchValue.length !== 0);
856
857 var binding = this.byId("listMOType").getBinding("items");
858 if (showSearch && binding !== undefined) {
859 var filters = [];
860 filters.push(new sap.ui.model.Filter("NAME", sap.ui.model.FilterOperator.Contains, searchValue));
861 binding.filter(filters);
862 } else {
863 binding.filter(false);
864 }
865 },
866
867 // the method handleMotypeSelected is called when a value from the list
868 // displayed (id: "listMOType") is selected
869 handleMotypeSelected : function(evt) {
870 this.resetField();
871 var selectedItem = this.byId("listMOType").getSelectedItem().getProperty("title");
872 var selectedID = this.byId("listMOType").getSelectedItem().getTitle();
873 var moService = com.tutorial.service.measureobject.MeasurementObjectFactory.getInstance();
874 var that = this;
875 sap.ui.getCore().byId('inputMOType').setValue(selectedItem);
876 this.byId("popoverMOType").close();
877
878 this.MOAssigments.MotypeID = selectedID;
879 if (sap.ui.getCore().byId('inputMOType').getValue() == 'NEMO') {
880 sap.ui.getCore().byId('butonelSys').setIcon("sap-icon://arrow-down");
881 sap.ui.getCore().byId('butonelSt').setIcon("sap-icon://arrow-down");
882 sap.ui.getCore().byId('butonelSysSusage').setIcon("sap-icon://arrow-down");
883 sap.ui.getCore().byId('butonelSysUOM').setIcon("sap-icon://arrow-down");
884 sap.ui.getCore().byId('butonelSysAggregation').setIcon("sap-icon://arrow-down");
885 sap.ui.getCore().byId('technicalNameFieldIdMO').setShowValueHelp(false);
886 sap.ui.getCore().byId('butonelSys').setVisible(true);
887 sap.ui.getCore().byId('butonelSt').setVisible(true);
888 sap.ui.getCore().byId('butonelSysSusage').setVisible(true);
889 sap.ui.getCore().byId('butonelSysUOM').setVisible(true);
890 sap.ui.getCore().byId('butonelSysAggregation').setVisible(true);
891
892 var oModel = new sap.ui.model.json.JSONModel();
893 oModel.setData({
894 enabledName : true,
895 enabledTech : true,
896 enabledDescription : true,
897 enabledLogic : true,
898 enabledFrequency : true,
899 enabledStereotype: true,
900 enabledMethod : true,
901 enabledUOM : true,
902 enabledAggregation : true,
903 });
904 this.getView().setModel(oModel, "typeMO");
905 } else {
906 sap.ui.getCore().byId('butonelSys').setVisible(false);
907 sap.ui.getCore().byId('butonelSt').setVisible(false);
908 sap.ui.getCore().byId('butonelSysSusage').setVisible(false);
909 sap.ui.getCore().byId('butonelSysUOM').setVisible(false);
910 sap.ui.getCore().byId('butonelSysAggregation').setVisible(false);
911
912 sap.ui.getCore().byId('technicalNameFieldIdMO').setShowValueHelp(true)
913 var oModel = new sap.ui.model.json.JSONModel();
914 oModel.setData({
915 enabledName : false,
916 enabledTech : true,
917 enabledDescription : true,
918 enabledLogic : false,
919 enabledFrequency : false,
920 enabledStereotype : false,
921 enabledMethod : false,
922 enabledUOM : false,
923 enabledAggregation : false,
924 AGG : 'SUM',
925 FREQ : 'Monthly',
926 Stereotype: '',
927 UOM : 'Traffic'
928 });
929 this.MOAssigments.Frequency = 'Monthly';
930 this.MOAssigments.Stereotype = 'Custom';
931 this.MOAssigments.UOM = 'Traffic';
932 this.MOAssigments.AGGREGATION = 'SUM';
933 this.getView().setModel(oModel, "typeMO");
934 }
935
936 },
937
938 // the method filterUOM is called when the mouse is put on the input(id
939 // "inputUOM") of Unit of Measure. At the mouse press the pop-up with
940 // possible entries appear (id "listUOM").
941 filterUOM : function() {
942
943 var searchValue = jQuery.trim(this.byId("inputUOM").getValue());
944 var showSearch = (searchValue.length !== 0);
945
946 var binding = this.byId("listUOM").getBinding("items");
947 if (showSearch && binding !== undefined) {
948 var filters = [];
949 filters.push(new sap.ui.model.Filter("NAME", sap.ui.model.FilterOperator.Contains, searchValue));
950 binding.filter(filters);
951 } else {
952 binding.filter(false);
953 }
954 },
955 // the method handleUOMSelected is called when a value from the list
956 // displayed (id: "listUOM") is selected
957 handleUOMSelected : function(evt) {
958 var selectedItem = this.byId("listUOM").getSelectedItem().getProperty("title");
959 var selectedID = this.byId("listUOM").getSelectedItem().getTitle();
960 var moService = com.tutorial.service.measureobject.MeasurementObjectFactory.getInstance();
961 this.byId("inputUOM").setValue(selectedItem);
962 this.byId("popoverUOM").close();
963 sap.ui.getCore().byId("butonelSysUOM").setIcon("sap-icon://cancel");
964 this.MOAssigments.UOM = selectedItem;
965 },
966
967 // the method filterAGGREGATION is called when the mouse is put on the
968 // input(id "inputAGGREGATION") of Aggregation. At the mouse press the
969 // pop-up with possible entries appear (id "listAGGREGATION").
970 filterAGGREGATION : function() {
971
972 var searchValue = jQuery.trim(this.byId("inputAGGREGATION").getValue());
973 var showSearch = (searchValue.length !== 0);
974
975 var binding = this.byId("listAGGREGATION").getBinding("items");
976 if (showSearch && binding !== undefined) {
977 var filters = [];
978 filters.push(new sap.ui.model.Filter("NAME", sap.ui.model.FilterOperator.Contains, searchValue));
979 binding.filter(filters);
980 } else {
981 binding.filter(false);
982 }
983 },
984 // the method handleAGGREGATIONSelected is called when a value from the list
985 // displayed (id: "listAGGREGATION") is selected
986 handleAGGREGATIONSelected : function(evt) {
987 var selectedItem = this.byId("listAGGREGATION").getSelectedItem().getProperty("title");
988 var selectedID = this.byId("listAGGREGATION").getSelectedItem().getTitle();
989 var moService = com.tutorial.service.measureobject.MeasurementObjectFactory.getInstance();
990 this.byId("inputAGGREGATION").setValue(selectedItem);
991 this.byId("popoverAGGREGATION").close();
992 sap.ui.getCore().byId("butonelSysAggregation").setIcon("sap-icon://cancel");
993 this.MOAssigments.AGGREGATION = selectedItem;
994 },
995
996 // the method generateKey is triggered from addMo method to generate a new
997 // key for the new package that will be added
998 generateKey : function() {
999 var key = Math.floor((Math.random() * 10000) + 1);
1000
1001 return key.toString();
1002 },
1003 checkEmptyFields : function() {
1004 if (sap.ui.getCore().byId('inputMOType').getValue() == "NEMO") {
1005 if ((!sap.ui.getCore().byId('technicalNameFieldIdMO').getValue()) || (!sap.ui.getCore().byId('keyTextFieldId').getValue()) || (!sap.ui.getCore().byId('inputMOType').getValue())) {
1006 // check that inputs are not empty
1007 if (!sap.ui.getCore().byId('technicalNameFieldIdMO').getValue())
1008 sap.ui.getCore().byId('technicalNameFieldIdMO').setValueState("Error");
1009 if (!sap.ui.getCore().byId('keyTextFieldId').getValue())
1010 sap.ui.getCore().byId('keyTextFieldId').setValueState("Error");
1011 if (!sap.ui.getCore().byId('inputMOType').getValue())
1012 sap.ui.getCore().byId('inputMOType').setValueState("Error");
1013 var msg = 'Please fill the mandatory fields!';
1014 sap.m.MessageToast.show(msg);
1015 return false;
1016 }
1017 return true;
1018 } else {
1019 if ((!sap.ui.getCore().byId('technicalNameFieldIdMO').getValue()) || (!sap.ui.getCore().byId('keyTextFieldId').getValue()) || (!sap.ui.getCore().byId('inputMOType').getValue())) {
1020 // check that inputs are not empty
1021 if (!sap.ui.getCore().byId('technicalNameFieldIdMO').getValue())
1022 sap.ui.getCore().byId('technicalNameFieldIdMO').setValueState("Error");
1023 if (!sap.ui.getCore().byId('inputMOType').getValue())
1024 sap.ui.getCore().byId('inputMOType').setValueState("Error");
1025 var msg = 'Please fill the mandatory fields!';
1026 sap.m.MessageToast.show(msg);
1027 return false;
1028 }
1029 return true;
1030 }
1031 },
1032 checkDuplicates : function(oEvent) {
1033 var router = sap.ui.core.UIComponent.getRouterFor(this);
1034 var found = false;
1035 if (oEvent.results.length != 0) {
1036 console.log("Duplicate TECHNICAL NAME");
1037 var oMeasureOb = new sap.ui.model.json.JSONModel(oEvent.results);
1038 found = true;
1039 console.log(oEvent.results[0]);
1040 }
1041
1042 if (found) {
1043
1044
1045 jQuery.ajax({
1046 url: userUrl,
1047 method: 'GET',
1048 dataType: 'json',
1049
1050 success: function(user)
1051 {
1052 username = user.USER;
1053 },
1054 error: function(XHR, Status, Error)
1055 {
1056 var error = Error;
1057 console.log(XHR.responseText);
1058 username = "default";
1059 }
1060 });
1061
1062
1063
1064 if (varPath != undefined) {
1065 var that = this;
1066 sap.m.MessageBox.show("MO already exists, do you want to assign it to the current package?", {
1067 icon : sap.m.MessageBox.Icon.INFORMATION,
1068 title : "Info MessageBox",
1069 actions : [ sap.m.MessageBox.Action.YES, sap.m.MessageBox.Action.NO ],
1070 onClose : function(oAction) {
1071 if (oAction === sap.m.MessageBox.Action.YES) {
1072 keyPackage = varPath;
1073 var dateNew = com.tutorial.util.Formatter.GetUnformattedDate();
1074
1075 var moOb2 = {
1076 "KEY_MEASUREMENT_OBJECTS" : oEvent.results[0].KEY,// moKey,
1077 "KEY_PACKAGE" : keyPackage,
1078 "CHANGED_BY" : username,
1079 "CHANGED_AT" : dateNew
1080 };
1081 var keyMO = oEvent.results[0].KEY;
1082
1083 var oDataMOdel = new sap.ui.model.odata.ODataModel(m_xsodata);
1084 // oDataMOdel.read("/LEG?$filter=KEY_PACKAGE eq '" +
1085 // moOb2.KEY_PACKAGE + "' and
1086 // KEY_MEASUREMENT_OBJECTS eq '" +
1087 // moOb2.KEY_MEASUREMENT_OBJECTS + "'", null, null,
1088 // true, fSuccess, fError);
1089 oDataMOdel.read("/CL_PACK_MO_DETAILSParameters(IP_PACKAGE_KEY=\'" + moOb2.KEY_PACKAGE + "\')/Results/?$orderby=SORT_COL asc", null, null, true, fSuccess, fError);
1090
1091 function fSuccess(oEvent) {
1092 if (oEvent.results.length != 0) {
1093 sap.ui.getCore().byId('technicalNameFieldIdMO').setValueState("Error");
1094 console.log("Assignment already exists");
1095 var msg = 'This MO is already assigned to this package';
1096 sap.m.MessageToast.show(msg);
1097 } else {
1098
1099 // update the date of assignment of the MO
1100 // with key_MO
1101 var moService = com.tutorial.service.measureobject.MeasurementObjectFactory.getInstance();
1102
1103 var dateObj = new Date();
1104 var month = dateObj.getUTCMonth() + 1; // months
1105 // from
1106 // 1-12
1107
1108 if (month < 10) {
1109 month = 0 + month.toString()
1110 }
1111
1112 var day = dateObj.getUTCDate();
1113
1114 if (day < 10) {
1115 day = 0 + day.toString()
1116 }
1117
1118 var year = dateObj.getUTCFullYear();
1119
1120 var hour = dateObj.getHours();
1121
1122 if (hour < 10) {
1123 hour = 0 + hour.toString()
1124 }
1125
1126 var minutes = dateObj.getMinutes();
1127
1128 if (minutes < 10) {
1129 minutes = 0 + minutes.toString()
1130 }
1131
1132 var seconds = dateObj.getSeconds();
1133
1134 if (seconds < 10) {
1135 seconds = 0 + seconds.toString()
1136 }
1137
1138 var newdate = year.toString() + month.toString() + day.toString() + hour.toString() + minutes.toString() + seconds.toString();
1139
1140 var moObUpdate = {
1141 "DATE_OF_ASSIGNMENT" : newdate
1142 };
1143
1144 moService.updateModel({
1145 updatedData : moObUpdate,
1146 successFunc : function(moData) {
1147 keyPackage = keyPackage;
1148
1149 },
1150 errorFunc : function() {
1151 var msg = 'failed to update Measurement Object';
1152 sap.m.MessageToast.show(msg);
1153 },
1154 moKey : keyMO
1155 });
1156
1157 var moprodService = com.tutorial.service.measureobject.MeasurementObjectPMOFactory.getInstance();
1158 moprodService.createModel({
1159 moData : moOb2,
1160 successFunc : function(notesData) {
1161 var msg = 'Successfully added';
1162 sap.m.MessageToast.show(msg);
1163 that.resetField();
1164 sap.ui.getCore().byId('inputMOType').setValue("");
1165 sap.ui.getCore().byId('inputMOType').setValueState("None");
1166
1167 sap.ui.getCore().byId('technicalNameFieldIdMO').setValue("");
1168 sap.ui.getCore().byId('technicalNameFieldIdMO').setValueState("None");
1169
1170 sap.ui.getCore().byId('keyTextFieldId').setValue("");
1171 sap.ui.getCore().byId('keyTextFieldId').setValueState("None");
1172 router.navTo("Detail", {
1173 contextPath : varPath
1174 });
1175
1176 },
1177 errorFunc : function() {
1178 sap.ui.getCore().byId('inputMOType').setValue("");
1179 sap.ui.getCore().byId('inputMOType').setValueState("None");
1180
1181 sap.ui.getCore().byId('technicalNameFieldIdMO').setValue("");
1182 sap.ui.getCore().byId('technicalNameFieldIdMO').setValueState("None");
1183
1184 sap.ui.getCore().byId('keyTextFieldId').setValue("");
1185 sap.ui.getCore().byId('keyTextFieldId').setValueState("None");
1186 var msg = 'failed to add';
1187 sap.m.MessageToast.show(msg);
1188 }
1189 });
1190 }
1191 }
1192 function fError(oEvent) {
1193 var msg = 'Unsuccessfully read assignment data';
1194 sap.m.MessageToast.show(msg);
1195 }
1196 //
1197
1198 } else {
1199 sap.ui.getCore().byId('technicalNameFieldIdMO').setValueState("Error");
1200 var msg = 'Technical Name already exists. Please enter a different name';
1201 sap.m.MessageToast.show(msg);
1202 }
1203 }
1204
1205 });
1206 } else {
1207 sap.m.MessageBox.show("MO already exists, do you want to display it?", {
1208 icon : sap.m.MessageBox.Icon.INFORMATION,
1209 title : "Info MessageBox",
1210 actions : [ sap.m.MessageBox.Action.YES, sap.m.MessageBox.Action.NO ],
1211 linkTitle : "Link",
1212 onClose : function(oAction) {
1213 if (oAction === sap.m.MessageBox.Action.YES) {
1214 router.navTo("DetailMO", {
1215 lineItemId : oEvent.results[0].KEY
1216 });
1217
1218 } else {
1219 sap.ui.getCore().byId('technicalNameFieldIdMO').setValueState("Error");
1220 var msg = 'Technical Name already exists. Please enter a different name';
1221 sap.m.MessageToast.show(msg);
1222 }
1223 }
1224 });
1225 }
1226 }
1227 return !found;
1228 },
1229
1230 checkSameMoPackName: function(technicalName){
1231
1232 var url = com.tutorial.util.Utils.getServerBaseURL() +"/usag/morepository/MOREPOSITORY/WebContent/checkChildren.xsjs" + "?parent_key=" + technicalName; // +
1233 // "&child_key="
1234 // +
1235 // child_key
1236 // +
1237 // "&action_type="
1238 // +
1239 // action_type
1240 // +
1241 // "&changed_By="
1242 // +
1243 // changed_By
1244 // +
1245 // "&changed_at="
1246 // +
1247 // changed_at
1248 // +
1249 // "&pkgchanged_Date="
1250 // +
1251 // pkgchanged_Date;
1252 var result = [];
1253 jQuery.ajax({
1254 url: url,
1255 async: false,
1256 method: 'GET',
1257 dataType: 'json',
1258 success: function(response)
1259 {
1260 for(var i = 0 ; i < response.length; i++)
1261 result.push(response[i].TECHNICAL_NAME);
1262 },
1263 error: function(error){
1264 alert("error");
1265 }
1266
1267 });
1268 return result;
1269 },
1270
1271
1272
1273 // the method addMO is triggered when it's intended to add a mo (add button
1274 // is pressed)
1275 // before adding the new entry, the technical name is checked to see if it
1276 // already exists
1277 // a new entry is added in usag.morepository::Z_USAG_MO
1278 addMo : function(evt) {
1279 that2.CalculateExtendedAttributes();
1280
1281 var oTable = sap.ui.getCore().byId("addMoTable");
1282 var that = this;
1283 var oBus = sap.ui.getCore().getEventBus();
1284 var moService = com.tutorial.service.measureobject.MeasurementObjectFactory.getInstance();
1285 var moprodService = com.tutorial.service.measureobject.MeasurementObjectPMOFactory.getInstance();
1286 var moKey = this.generateKey();
1287 var router = sap.ui.core.UIComponent.getRouterFor(this);
1288 var listMOTYPE;
1289 that = this;
1290
1291 if (this.byId("listMOType").getSelectedItem() == null)
1292 listMOTYPE = null;
1293 else
1294 listMOTYPE = this.byId("listMOType").getSelectedItem().getCustomData()[0].getValue();
1295
1296
1297 if(!this.validateExtendedAttributeField()){
1298 sap.m.MessageToast.show("Please fill in all mandatory extended attributes");
1299 return;
1300 }
1301
1302 var moOb = {
1303 "TECHNICAL_NAME" : sap.ui.getCore().byId('technicalNameFieldIdMO').getValue(),
1304 "DESCRIPTION" : this.byId('descriptionFieldId').getValue(),
1305 "KEY" : sap.ui.getCore().byId('technicalNameFieldIdMO').getValue(),
1306 "NAME" : sap.ui.getCore().byId('keyTextFieldId').getValue(),
1307 "DATE_OF_ENTER" : this.byId('dateFieldID').getValue(),
1308 "FEATUREID" : null,
1309 "PRODUCTID" : null,
1310 "SOLUTIONID" : null,
1311 "FEATURE" : null,
1312 "PRODUCT" : null,
1313 "SOLUTION" : null,
1314 "MO_TYPE" : listMOTYPE,
1315 "UNIT_OF_MEASURE" : this.MOAssigments.UOM,
1316 "AGGREGATION" : this.MOAssigments.AGGREGATION,
1317 "MO_LOGIC" : this.byId('moLogicFieldId').getValue(),
1318 "MEASUREMENT_FREQUENCY" : this.MOAssigments.Frequency,
1319 "MEASUREMENT_METHOD" : this.MOAssigments.Status,
1320 "STEREOTYPE": this.MOAssigments.Stereotype.split('/').pop(),
1321 "ACTIVE": 'yes',
1322 "OWNER" : username
1323 };
1324 console.log("owneeeeeeeeeer2" + moOb.OWNER + username)
1325
1326
1327 // check there is no package with the same technicalName
1328 if(varPath != "" && varPath != undefined){
1329 var resultCheck = this.checkSameMoPackName(varPath);
1330 for(var packageTechnicalName of resultCheck){
1331 if(packageTechnicalName == moOb.TECHNICAL_NAME){
1332 sap.ui.getCore().byId('technicalNameFieldIdMO').setValueState("Error");
1333 var msg = "Due to technical restrictions in the processing systems it is not allowed to have MO's and Packages with the same technical name assigned" +
1334 " to the same parent package. Please use another technical name or change the assignment";
1335 sap.m.MessageToast.show(msg);
1336 return;
1337 }
1338
1339 }
1340
1341 }
1342
1343 if (this.checkEmptyFields())
1344
1345 {
1346
1347 var specialCharactersFlag=false;
1348 var specialCharacters = /[!@#$%^&*()+\-=\[\]{};':"\\|,<>\/?]/;
1349
1350 if (specialCharacters.test(moOb.TECHNICAL_NAME) == true) {
1351
1352 sap.ui.getCore().byId('technicalNameFieldIdMO').setValueState("Error");
1353 var msg = 'Special Characters are not allowed for Technical Name';
1354 sap.m.MessageToast.show(msg);
1355 specialCharactersFlag=true;
1356
1357 }
1358
1359 if (specialCharacters.test(moOb.NAME) == true) {
1360
1361 sap.ui.getCore().byId('keyTextFieldId').setValueState("Error");
1362 var msg = 'Special Characters are not allowed for Name';
1363 sap.m.MessageToast.show(msg);
1364 specialCharactersFlag=true;
1365
1366 }
1367
1368 if(specialCharactersFlag == true) {
1369 return;
1370 }
1371
1372
1373
1374 jQuery.ajax({
1375 url: userUrl,
1376 method: 'GET',
1377 dataType: 'json',
1378
1379 success: function(user)
1380 {
1381 username = user.USER;
1382 },
1383 error: function(XHR, Status, Error)
1384 {
1385 var error = Error;
1386 console.log(XHR.responseText);
1387 username = "default";
1388 }
1389 });
1390
1391 var oDataMOdel = new sap.ui.model.odata.ODataModel(m_xsodata);
1392 oDataMOdel.read("/MEASUREMENT_OBJECTS?$filter=TECHNICAL_NAME eq '" + moOb.TECHNICAL_NAME + "'", null, null, true, fSuccess, fError);
1393 function fSuccess(oEvent) {
1394 if (that.checkDuplicates(oEvent)) {
1395 moService.createModel({
1396 moData : moOb,
1397 successFunc : function(notesData) {
1398 that.addExtendedAttributes();
1399 that.bindTable([]);
1400 var oTable = sap.ui.getCore().byId("tableMoForPackageId");
1401 if (varPath != undefined) {
1402 keyPackage = varPath;
1403 var dateNew = com.tutorial.util.Formatter.GetUnformattedDate();
1404 var moOb2 = {
1405 "KEY_MEASUREMENT_OBJECTS" : sap.ui.getCore().byId('technicalNameFieldIdMO').getValue(),
1406 "KEY_PACKAGE" : keyPackage,
1407 "CHANGED_BY" : username,
1408 "CHANGED_AT" : dateNew
1409 };
1410 moprodService.createModel({
1411 moData : moOb2,
1412 successFunc : function(notesData) {
1413// that.validateExtendedAttributeField();
1414 var msg = 'Measurement Object successfully added';
1415 sap.m.MessageToast.show(msg);
1416 that.resetField();
1417 sap.ui.getCore().byId('inputMOType').setValue("");
1418 sap.ui.getCore().byId('inputMOType').setValueState("None");
1419
1420 sap.ui.getCore().byId('technicalNameFieldIdMO').setValue("");
1421 sap.ui.getCore().byId('technicalNameFieldIdMO').setValueState("None");
1422
1423 sap.ui.getCore().byId('keyTextFieldId').setValue("");
1424 sap.ui.getCore().byId('keyTextFieldId').setValueState("None");
1425
1426 router.navTo("Detail", {
1427 contextPath : varPath,
1428 contextID : "1"
1429 });
1430
1431 },
1432 errorFunc : function() {
1433 sap.ui.getCore().byId('inputMOType').setValue("");
1434 sap.ui.getCore().byId('inputMOType').setValueState("None");
1435
1436 sap.ui.getCore().byId('technicalNameFieldIdMO').setValue("");
1437 sap.ui.getCore().byId('technicalNameFieldIdMO').setValueState("None");
1438
1439 sap.ui.getCore().byId('keyTextFieldId').setValue("");
1440 sap.ui.getCore().byId('keyTextFieldId').setValueState("None");
1441 var msg = 'Unsuccessfully added';
1442 sap.m.MessageToast.show(msg);
1443 }
1444 });
1445 } else {
1446 that.resetField();
1447 if (sap.ui.getCore().byId("iconTabBar1") == undefined)
1448 router.navTo("main");
1449 else {
1450 router.navTo("main", {
1451 query : {
1452 tab : sap.ui.getCore().byId("iconTabBar1").getSelectedKey()
1453 }
1454 }, true);
1455 }
1456 sap.ui.getCore().byId('inputMOType').setValue("");
1457 sap.ui.getCore().byId('inputMOType').setValueState("None");
1458
1459 sap.ui.getCore().byId('technicalNameFieldIdMO').setValue("");
1460 sap.ui.getCore().byId('technicalNameFieldIdMO').setValueState("None");
1461
1462 sap.ui.getCore().byId('keyTextFieldId').setValue("");
1463 sap.ui.getCore().byId('keyTextFieldId').setValueState("None");
1464 }
1465 },
1466 errorFunc : function() {
1467
1468 sap.m.MessageToast.show('failed to add Measurement Object');
1469
1470 sap.ui.getCore().byId('inputMOType').setValue("");
1471 sap.ui.getCore().byId('inputMOType').setValueState("None");
1472
1473 sap.ui.getCore().byId('technicalNameFieldIdMO').setValue("");
1474 sap.ui.getCore().byId('technicalNameFieldIdMO').setValueState("None");
1475
1476 sap.ui.getCore().byId('keyTextFieldId').setValue("");
1477 sap.ui.getCore().byId('keyTextFieldId').setValueState("None");
1478 }
1479 });
1480
1481 }
1482 }
1483 ;
1484 function fError(oEvent) {
1485 console.log("An error occured while reading Measurement Object Data!")
1486 }
1487 ;
1488 }
1489
1490 },
1491
1492 // after the mo was successfully added, the method resetField is called to
1493 // reset all the fields to null value
1494 resetField : function() {
1495 sap.ui.getCore().byId('technicalNameFieldIdMO').setValue("");
1496 sap.ui.getCore().byId('technicalNameFieldIdMO').setValueState("None");
1497
1498 sap.ui.getCore().byId('keyTextFieldId').setValue("");
1499 sap.ui.getCore().byId('keyTextFieldId').setValueState("None");
1500
1501 this.byId('descriptionFieldId').setValue("");
1502
1503 // this.byId('inputField').setValue("");
1504 // this.byId('inputSolution').setValue("");
1505 sap.ui.getCore().byId('inputMOType').setValue("");
1506 this.byId('inputUOM').setValue("");
1507 this.byId('inputAGGREGATION').setValue("");
1508 this.byId('moLogicFieldId').setValue("");
1509 this.byId('inputFrequency').setValue("");
1510 this.byId('inputStereotype').setValue("");
1511 this.byId('inputStatus').setValue("");
1512 },
1513
1514 // quickhelp function
1515 quickhelp: function(oControl, sText, bCustomize){
1516 // create the RichTooltip control
1517 var oRichTooltip = new sap.ui.commons.RichTooltip({
1518 text: sText,
1519 title: "Quick Help",
1520 imageSrc: "images/Tip.gif"
1521 });
1522 // Change position and durations if required
1523 if (bCustomize) {
1524 oRichTooltip.setMyPosition("begin top");
1525 oRichTooltip.setAtPosition("end top");
1526 oRichTooltip.setOpenDuration(300);
1527 oRichTooltip.setCloseDuration(300);
1528 }
1529 // add it to the control
1530 oControl.setTooltip(oRichTooltip);
1531 // return the control itself (makes this function a
1532 // decorator function)
1533 return oControl;
1534 },
1535
1536 validateNames: function(){
1537 var name = sap.ui.getCore().byId('technicalNameFieldIdMO').getValue();
1538 var technicalName = sap.ui.getCore().byId('keyTextFieldId').getValue();
1539
1540 if(name == null || name == undefined || name == ""){
1541 sap.ui.getCore().byId('keyTextFieldId').setValue("");
1542 sap.ui.getCore().byId('keyTextFieldId').setValueState("Error");
1543 }
1544 if(technicalName == null || technicalName == undefined || technicalName == ""){
1545 sap.ui.getCore().byId('technicalNameFieldIdMO').setValue("");
1546 sap.ui.getCore().byId('technicalNameFieldIdMO').setValueState("Error");
1547 }
1548 },
1549
1550 validateExtendedAttributeField: function(){
1551
1552 var flag = 1;
1553 if(this.extendedAttributes != null && this. extendedAttributes!= undefined){
1554 for(var attribute of this.extendedAttributes){
1555 var name = attribute;
1556 var value = sap.ui.getCore().byId('Value' + attribute).getValue();
1557 var managedBy = sap.ui.getCore().byId('Managed' + attribute).getText();
1558 var required = sap.ui.getCore().byId('Value' + attribute).getRequired();
1559 if(value =='' || value == undefined){
1560 if(required == true){
1561 flag = 0;
1562 }
1563 }
1564 }
1565 }
1566
1567 if(flag == 0)
1568 return false;
1569
1570 return true;
1571 },
1572
1573 saveExtendedAttributes: function (moKey) {
1574 if(this.extendedAttributes != null && this.extendedAttributes != undefined){
1575 extendedAttributesTableData = {
1576 packId: moKey,
1577 extendedAttributesValues: []
1578 };
1579 this.extendedAttributes.forEach(attribute => {
1580 var name = attribute;
1581 var value = sap.ui.getCore().byId('Value' + attribute).getValue();
1582 var managedBy = sap.ui.getCore().byId('Managed' + attribute).getText();
1583 extendedAttributesTableData.extendedAttributesValues.push({name: name, value: value, managedBy: managedBy});
1584 });
1585 }
1586
1587 },
1588
1589 addExtendedAttributes: function(){
1590 var that=this;
1591 var table = this.getView().byId(this.createId("addMoTable"));
1592 table.getItems().forEach(function(ColListItem){
1593 var attribute={};
1594 attribute.name = ColListItem.getCells()[0].getText();
1595 if(attribute.name[attribute.name.length-1] == '*'){
1596 attribute.name = attribute.name.slice(0, -1);
1597 }
1598 attribute.value = ColListItem.getCells()[1].getValue();
1599 attribute.managedBy = ColListItem.getCells()[2].getText();
1600 that.saveAttribute(attribute);
1601 })
1602 },
1603
1604
1605 saveAttribute: function(attribute){
1606// debugger;
1607 var that = this;
1608 var obj_type = 'Z_USAG_MO';
1609 var action_type = 'insert';
1610 var datatype = 'String';
1611
1612 var url = UpdateExtendedAttributesDataURL + "?obj_type=" + obj_type + "&action_type=" + action_type + "&datatype=" + datatype + "&obj_id=" + sap.ui.getCore().byId('technicalNameFieldIdMO').getValue() + "&attribute=" + attribute.name + "&value=" + attribute.value + "&managed_by=" + attribute.managedBy;
1613 jQuery.ajax({
1614 url: url,
1615 method: 'GET',
1616 // dataType: 'json',
1617 success: function(XHR, Status, Error)
1618 {
1619 if(Error){console.log(Error)}
1620
1621 },
1622 error: function(XHR, Status, Error)
1623 {
1624 console.log(Error)
1625 }
1626 });
1627
1628 },
1629
1630});