Restore version to SNAPSHOT
[clamp.git] / src / main / resources / META-INF / resources / designer / partials / portfolios / stringMatch_properties.html
1 <!--
2   ============LICENSE_START=======================================================
3   ONAP CLAMP
4   ================================================================================
5   Copyright (C) 2017 AT&T Intellectual Property. All rights
6                               reserved.
7   ================================================================================
8   Licensed under the Apache License, Version 2.0 (the "License"); 
9   you may not use this file except in compliance with the License. 
10   You may obtain a copy of the License at
11   
12   http://www.apache.org/licenses/LICENSE-2.0
13   
14   Unless required by applicable law or agreed to in writing, software 
15   distributed under the License is distributed on an "AS IS" BASIS, 
16   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
17   See the License for the specific language governing permissions and 
18   limitations under the License.
19   ============LICENSE_END============================================
20   ===================================================================
21   ECOMP is a trademark and service mark of AT&T Intellectual Property.
22   -->
23 <style>
24 #deleteStringMatch{
25         height:34px;
26         background-color:#dddd;
27 }
28
29 .disabled{
30         background-color: #dddd;
31 }
32 .fileUpload {
33         position: relative;
34         overflow: hidden;
35         margin: 10px;
36 }
37
38 .fileUpload input.upload {
39         position: absolute;
40         top: 0;
41         right: 0;
42         margin: 0;
43         padding: 0;
44         font-size: 20px;
45         cursor: pointer;
46         opacity: 0;
47         filter: alpha(opacity = 0);
48         float: left;
49 }
50
51 .fileDisplay {
52         display: inline-block;
53         overflow: hidden;
54         float: right;
55         margin-left: 0px;
56         z-index: initial;
57         text-align: center;
58         margin-top: 17px;
59 }
60
61 .form-group {
62 /*      height:24px; */
63 /*      box-sizing:border-box; */
64         margin-bottom:20px;
65 }
66
67 .modelSearchBox{
68         position:absolute; 
69         padding: 25px 12px;
70 }
71
72 label{
73         text-align:right;
74         vertical-align:middle;
75 }
76
77 .leftStringMatchPanel{
78         padding: 0 10px 0 0;
79 }
80
81 #createNewStringMatch{
82         height:34px;
83         width:120px; /*84*/
84         background-color:#f2bfab;
85 }
86
87 .idError{
88         color:red; 
89         padding:50px 0px; 
90         text-align:center; 
91         display:none;
92 }
93
94 #rgname{
95         height:28px; 
96         margin-left:-5px;
97 }
98
99 .stringMatchPanel{
100         background-color: #f5f5f5;
101         padding: 10px 5px;
102 }
103
104 #stringMatchSearch{
105         height: 33px;
106         font-size: 12px;
107         padding: 2px 2px 2px 30px;
108         margin-bottom: 5px;
109         width:100%;
110 }
111 #stringMatchTable{
112         cursor: pointer;
113         width:100%;
114 }
115
116 #stringMatchTable tr{
117         border-bottom: 1px solid #ddd;
118         border-collapse: collapse;
119         text-align: left;
120         font-size: 12px;
121         font-weight: normal;
122 }
123
124 #stringMatchTable td{
125         padding: 8px 10px;
126 }
127
128 #stringMatchTable tr.highlight{
129         background-color: #f5f5f5;
130         font-weight: bold;
131         font-size: 13px;
132 }
133
134 #stringMatchTableHolder{
135         height:200px; 
136         width: 100%; 
137         overflow:auto;
138 }
139
140 #timeout{
141         height:28px; 
142         margin-left:10px;
143 }
144
145 </style>
146
147 <script type="text/javascript">
148         function disablefile() {
149
150                 document.getElementById("fileUpload").disabled = true;
151
152         }
153
154         function disableSVN() {
155                 var selectLength = document.querySelectorAll(".disabled-block-container .tab-close-popup");
156                 if(selectLength && selectLength.length>0){
157                         for(var i = 0; i< selectLength.length ; i++){
158                                 selectLength[i].disabled = true;
159                         }       
160                 }
161
162                 document.getElementById("schemaLocation").disabled = true;
163                 document.getElementById("userID").disabled = true;
164                 document.getElementById("password").disabled = true;
165
166         }
167 </script>
168
169
170 <div attribute-test="stringMatchwindowproperties" id="configure-widgets" class="disabled-block-container">
171         <div attribute-test="stringMatchwindowpropertiesh" class="modal-header">
172                 <button type="button" class="close" ng-click="close(false)"
173                         aria-hidden="true" style="margin-top: -3px">&times;</button>
174                 <h4>String Matching Micro Service</h4>
175         </div>
176
177
178         <div class="modal-body">
179                 <div attribute-test="stringMatchwindowpropertiesb" class="modal-body row">
180
181                         <div class="leftStringMatchPanel">
182                                 <div class="panel panel-default">
183                                         <i class="modelSearchBox"></i> <input type="text"
184                                                 id="stringMatchSearch" onkeyup="searchStringMatchList()"
185                                                 placeholder="Search ...">
186                                         <div id="stringMatchTableHolder">
187                                                 <table id="stringMatchTable"></table>
188                                         </div>
189                                 </div>
190                                 <div style="float: left">
191                                         <button type="button" id="createNewStringMatch" class="btn btn-sm">New Group</button>
192                                         </span>
193                                 </div>
194                                 <div style="float: right">
195                                         <button type="button" id="deleteStringMatch" class="btn btn-sm glyphicon glyphicon-trash" disabled></button>
196                                         </span>
197                                 </div>
198                                 <div id="repeatIdError" class="idError">Error: This Group name is already taken.</div>
199                                 <div id="newIdError" class="idError">Error: Please rename your new Group.</div>
200                         </div>
201
202                         <div class="panel panel-default col-sm-9 stringMatchPanel"
203                                 style="display: none;">
204                                 <form id="topicPublish" class="form-horizontal">
205                                         <div>
206 <!--                                            As per the last minute new requirements for 1707 the ID needs to be hidden and we need to have a friendly name instead -->
207                                                         <div style="display: none;">
208                                                                 <div class="form-group clearfix">
209                                                                         <label class="col-sm-4 control-label">Resource Group Id</label>
210                                                                         <div class="col-sm-8">
211                                                                                 <input class="form-control" id="rgname" name="rgname" readOnly> </input>
212                                                                         </div>
213                                                                 </div>
214                                                         </div>
215                                                         
216                                                         <div>
217                                                                 <div class="form-group clearfix">
218                                                                         <label class="col-sm-4 control-label">Resource Group</label>
219                                                                         <div class="col-sm-8">
220                                                                                 <input class="form-control" maxlength="48" placeholder="Enter Unique Name" id="rgfriendlyname" name="rgfriendlyname"> </input>
221                                                                         </div>
222                                                                 </div>
223                                                         </div>                                                  
224                                                         
225                                                         <!--Policy's drop down box -->
226                                                         <div class="form-group clearfix">
227                                                                 <label class="col-sm-4 control-label">Ops Policy:</label>
228                                                                 <div class="col-sm-8">
229                                                                         <select class="form-control" id="policyName" name="policyName"
230                                                                                 autofocus="autofocus" required ng-trim="true" enableFilter="true">
231                                                                                 <option ng-repeat="x in policyNames" value="{{x}}">{{x}}</option>
232                                                                         </select>
233                                                                 </div>
234                                                         </div>
235                                                         
236                                         </div>
237                                 </form>
238                                 
239                                 <div class="panel-heading" style="background-color: white;">
240                                         <ul id="nav_Tabs" class="nav nav-tabs">
241                                                 <li class><a id="add_one_more" href="#desc_tab"><span
242                                                                 class="glyphicon glyphicon-plus" aria-hidden="true"></span></a></li>
243                                         </ul>
244                                 </div>
245                                 <div class="panel-body">
246                                         <div class="tab-content">
247                                                 <div id="properties_tab" class="tab-pane fade in active"></div>
248                                         </div>
249                                 </div>
250                         </div>
251
252                         <span id="formSpan" style="display: none">
253                                 <form class="saveProps" class="form-horizontal">
254
255                                         <div>
256                                                 <div class="form-group clearfix">
257                                                         <label for="aaiMatchingFields" class="col-sm-4 control-label">AAI Fields Matching </label>
258                                                         <div class="col-sm-8">
259                                                                 <select class="form-control" name="aaiMatchingFields" id="aaiMatchingFields" multiple size=2></select>
260                                                         </div>
261                                                                                                         
262                                                 </div>
263                                                 <div class="form-group clearfix">
264                                                         <label for="aaiSendFields" class="col-sm-4 control-label">AAI Fields Send (Select Multiple)</label>
265
266                                                         <div class="col-sm-8 ">
267                                                                 <select class="form-control" id="aaiSendFields"
268                                                                         name="aaiSendFields" multiple size=2>
269                                                                 </select>
270
271                                                         </div>
272                                                 </div>
273 <!--                                            <div class="form-group clearfix"> -->
274 <!--                                                    <label for="groupNumber" class="col-sm-4 control-label"> -->
275 <!--                                                            Resource-Group</label> -->
276
277 <!--                                                    <div class="col-sm-8"> -->
278 <!--                                                            <input type="number" class="form-control" id="groupNumber" -->
279 <!--                                                                    name="groupNumber" min="0"> </input> -->
280
281 <!--                                                    </div> -->
282 <!--                                            </div> -->
283                                                 <div class="form-group clearfix">
284                                                         <label for="vfc" class="col-sm-4 control-label">Resource-VFC</label>
285                                                         <div class="col-sm-8">
286                                                                 <select class="form-control" id="vfc" name="vfc" enableFilter="true">
287
288                                                                 </select>
289
290                                                         </div>
291                                                 </div>
292                                                 <div class="form-group clearfix">
293                                                         <label for="alarmCondition" class="col-sm-4 control-label">Alarm Condition</label>
294                                                         <div class="col-sm-8">
295                                                                 <select class="form-control" id="alarmCondition" name="alarmCondition" enableFilter="true">
296                                                                 
297                                                                 </select>
298                                                         </div>
299                                                 </div>
300                                                 <div class="form-group clearfix">
301                                                         <label for="eventSeverity" class="col-sm-4 control-label">Event Severity</label>
302                                                         <div class="col-sm-8">
303                                                                 <select class="form-control" id="eventSeverity"
304                                                                         name="eventSeverity" enableFilter="false"></select>
305                                                         </div>
306                                                 </div>
307                                                 <div class="form-group clearfix">
308                                                         <label for="eventSourceType" class="col-sm-4 control-label">
309                                                                 Event Source Type</label>
310                                                         <div class="col-sm-8">
311                                                                 <input type="text" class="form-control" id="eventSourceType"
312                                                                         name="eventSourceType" readOnly></input>
313                                                         </div>
314                                                 </div>
315
316                                                 <div class="form-group clearfix">
317                                                         <label for="timeWindow" class="col-sm-4 control-label">
318                                                                 Time Window</label>
319
320                                                         <div class="col-sm-8">
321                                                                 <input type="text" maxlength="5" class="form-control"
322                                                                         onkeypress="return isNumberKey(event)"
323                                                                         id="timeWindow" name="timeWindow" />
324                                                         </div>
325                                                 </div>
326                                                 <div class="form-group clearfix">
327                                                         <label for="ageLimit" class="col-sm-4 control-label"> Age
328                                                                 Limit</label>
329
330                                                         <div class="col-sm-8">
331                                                                 <input type="text" maxlength="5" class="form-control" id="ageLimit"
332                                                                         onkeypress="return isNumberKey(event)"
333                                                                         name="ageLimit" />
334                                                         </div>
335                                                 </div>
336                                                 <div class="form-group clearfix">
337                                                         <label for="createClosedLoopEventId"
338                                                                 class="col-sm-4 control-label"> Create CL Event ID</label>
339                                                         <div class="col-sm-8">
340                                                                 <select class="form-control" id="createClosedLoopEventId"
341                                                                         name="createClosedLoopEventId" enableFilter="false">
342                                                                 </select>
343
344                                                         </div>
345                                                 </div>
346
347                                                 <div class="form-group clearfix">
348                                                         <label for="outputEventName" class="col-sm-4 control-label">
349                                                                 Output Event Name</label>
350
351                                                         <div class="col-sm-8">
352                                                                 <select class="form-control" id="outputEventName"
353                                                                         name="outputEventName" enableFilter="true"></select>
354
355                                                         </div>
356                                                 </div>
357                                         </div>
358
359
360
361                                 </form>
362                         </span>
363                 </div>
364         </div>
365
366         <div attribute-test="stringMatchwindowpropertiesf" class="modal-footer">
367                 <!--<button ng-click="reset()" class="btn btn-primary" style="float:left">Reset</button>-->
368                 <button id="savePropsBtn" class="btn btn-primary">Close</button>
369                 <button ng-click="close(true)" id="close_button"
370                         class="btn btn-primary">Cancel</button>
371         </div>
372
373         <script>
374
375                 //Basically this method will add a new form. All forms share the same class. When you want one form to show(active form) the other forms get the 
376                 // css attribute display:none
377                 $("#add_one_more").click(function(event) {
378                         event.preventDefault();
379                         num = add_one_more();
380                         setMultiSelect();
381                         addSelectListen(num);
382                 });
383                 
384                 
385                 //This method will load the existing Strin Match onto the screen
386                 loadPropertyWindow("string_match");
387                 setASDCFields();
388
389                 // By default, parentStringMatchConditions is disabled
390                 $("#parentStringMatchConditions").prop('disabled', 'disabled');
391                 
392                 
393                 var parent_stringMatch = {}
394                 var stringMatch_ids = {}
395                 var loadingId = false;
396                 var allSMatch = {};
397                 var vfc_temp=""
398                 var alarm_conditions_temp=""
399                 var event_severity_temp=""
400                 var event_type_source_temp=""           
401
402                 //Grab saved values for dropdowns
403                 var obj = elementMap[lastElementSelected];
404
405                 if (!($.isEmptyObject(obj))) {
406                         allSMatch = jQuery.extend({}, obj);
407                         for ( var x in allSMatch) {
408                                 $("#stringMatchTable").prepend(
409                                                 "<tr><td>" + x + "</td></tr>");
410                         }
411                 }
412
413                 
414                 //Load properties_tab for a chosen String Match
415                 function disperseConfig(stringMatchObj, id) {                   
416                         //remove old gui forms
417                         for (var i = 1; i < ($(".formId").length + 1); i++) {
418                                 $("#go_properties_tab" + i).parent().remove();
419                         }
420                         $(".formId").remove();
421
422                         if (stringMatchObj !== undefined) {
423                                 var el = stringMatchObj[id][4]['serviceConfigurations']
424                                 for (var i = 0; i < el.length; i++) {
425                                         loadingId = true;
426                                         var num = add_one_more();
427                                         loadingId = false;
428                                         for (var j = 0; j < el[i].length; j++) {
429                                                 if (el[i][j]["stringSet"] !== undefined) {
430                                                         var ss = el[i][j]["stringSet"]
431                                                         for (var o = 0; o < ss.length; o++) {
432                                                                 if(ss[o].hasOwnProperty("name")){
433                                                                         if(ss[o].name==="alarmCondition"){
434                                                                                 alarm_conditions_temp=ss[o].value
435                                                                         }else if(ss[o].name==="eventSeverity"){
436                                                                                 event_severity_temp=ss[o].value;
437                                                                         }else if(ss[o].name==="eventSourceType"){
438                                                                                 event_type_source_temp=ss[o].value;
439                                                                         }
440                                                                         else 
441                                                                         $("#formId" + num + " #" + ss[o].name).val(ss[o].value);        
442                                                                 }
443                                                                 
444                                                         }
445                                                 }else if(el[i][j].hasOwnProperty("name") && el[i][j].name==="vfc"){
446                                                         vfc_temp=el[i][j].value
447                                                 }
448                                                 else if (el[i][j].name === 'outputEventName' && el[i][j].value.toString() !== '') {
449                                                         $("#go_properties_tab" + num).text(el[i][j].value);
450                                                         $("#formId" + num + " #" + el[i][j].name).val(el[i][j].value);
451                                                 }
452                                                 else {
453                                                         if(el[i][j].hasOwnProperty("name")){
454                                                                 $("#formId" + num + " #" + el[i][j].name).val(
455                                                                                 el[i][j].value);
456                                                         }
457                                                 }
458                                         }
459                                         set_vfc_alarm_event(num);
460                                         vfc_temp="";
461                                         alarm_conditions_temp="";
462                                         event_severity_temp="";
463                                         event_type_source_temp="";
464
465                                         addSelectListen(num);
466                                 }
467
468                                 //Adding all the ids for parent String options
469                                 for (var i = 1; i <= $(".formId").length; i++) {
470                                         for (k in stringMatch_ids) {
471                                                 if ($("#formId" + i + " #_id").val() !== stringMatch_ids[k].toString() && $(k + " #recipe").val() !== undefined && $(k + " #recipe").val() !== "") {
472                                                         $("#formId" + i + " #parentStringMatch").append("<option value=\""+stringMatch_ids[k]+"\">"+ $(k + " #recipe").val()+ "</option>");
473                                                 }
474                                         }
475                                 }
476
477                                 for (k in parent_stringMatch) {
478                                         $("#formId" + k + " #parentStringMatch").val(parent_stringMatch[k]);
479                                         // force the change event
480                                         $("#formId" + k + " #parentStringMatch").change();
481                                 }
482
483                                 if (stringMatchObj[id][0]) {
484                                         $("#" + stringMatchObj[id][0].name).val(stringMatchObj[id][0].value);
485                                 }
486                                 
487                                 if (stringMatchObj[id][1]) {
488                                         $("#" + stringMatchObj[id][1].name).val(stringMatchObj[id][1].value);
489                                 }               
490                                 
491                                 if (stringMatchObj[id][2]) {
492                                         $("#" + stringMatchObj[id][2].name).val(stringMatchObj[id][2].value);
493                                 }
494                         }
495
496                         setMultiSelect();
497                         
498                         if (readOnly||readMOnly){
499                                 $('select[multiple] option').each(function() {
500                           var input = $('input[value="' + $(this).val() + '"]');
501                           input.prop('disabled', true);
502                           input.parent('li').addClass('disabled');
503                         });
504                                 $('input[value="multiselect-all"]').prop('disabled', true).parent('li').addClass('disabled');
505                         }
506                 }
507
508
509                 //This is ensure there are no repeated keys in the map
510                 function noRepeats(form) {
511                         //triggered per String.
512                         var select = {};
513                         for (var i = 0; i < form.length; i++) {
514                                 if (select[form[i].name] === undefined)
515                                         select[form[i].name] = []
516                                 select[form[i].name].push(form[i].value);
517                         }
518                         var arr = []
519                         for (s in select) {
520                                 var f = {}
521                                 f.name = s
522                                 f.value = select[s]
523                                 arr.push(f)
524                         }
525                         return arr
526                 }
527
528                 $("#savePropsBtn").click(function(event) {
529                         $(".idError").hide();
530                         if ($("#stringMatchTable .highlight td").html() !== $("#rgfriendlyname").val()){
531                                 //repeated name
532                                 if ($.inArray($("#rgfriendlyname").val(), Object.keys(allSMatch)) > -1){
533                                         $("#repeatIdError").show();
534                                         return;
535                                 } else { //not repeated
536                                         delete allSMatch[$("#stringMatchTable .highlight td").html()];
537                                 }
538                         }
539                         /* //Saves edits
540                         if ($("#stringMatchTable .highlight").length > 0) {
541                                 saveLastStringMatchLocally($("#stringMatchTable .highlight td").html());
542                         } */
543                         if ($("#rgfriendlyname").val().trim() == "New_Group"){
544                                 $("#newIdError").show();
545                                 return;
546                         }
547                         startNextItem();
548                         //Removes outdated (deleted) resource Groups by checking against left menu
549                         var finalSaveList = {};
550                         $("#stringMatchTable td").each(function() {
551                                 var tableVal = $(this).text();
552                                 if (tableVal in allSMatch) {
553                                         finalSaveList[tableVal] = allSMatch[tableVal];
554                                 }
555                         });
556
557                         saveProperties(finalSaveList);
558                         $("#close_button").click();
559                 })
560
561                 function add_one_more() {
562                         $("#nav_Tabs li").removeClass("active");
563
564                         //FormSpan contains a block of the form that is not being displayed. We will create clones of that and add them to tabs
565                         var form = $($("#formSpan").children()[0]).clone()
566                         var count = 0;
567                         //Each new tab will have the formId class attached to it. This way we can track how many forms we currently have out there and assign listeners to them
568                         if ($(".formId").length > 0) {
569                                 var greatest = 0;
570                                 var s = $(".formId");
571                                 for (var i = 0; i < s.length; i++) {
572                                         if (parseInt($(s[i]).attr("id").substring(6)) > greatest) {
573                                                 greatest = parseInt($(s[i]).attr("id").substring(6))
574                                         }
575                                 }
576                                 count = greatest + 1;
577                                 $("#properties_tab").append(
578                                                 ('<span class="formId" id="formId'+count+'"></span>'));
579                         } else {
580                                 count++;
581                                 $("#properties_tab").append(
582                                                 '<span class="formId" id="formId1"></span>');
583                         }
584
585                         //$(form).find("#stringMatchName").val("Recipe "+makid(2))
586                         //TODO change up how we auto assign stringMatchName. There could be the case where we do this and it will have repeats
587                         //alert($(form).find("#_id").val())
588                         //stringMatchNameChangeListener(form)
589                         
590                         $("#add_one_more")
591                                         .parent()
592                                         .before(
593                                                         ' <li class="active"><a id="go_properties_tab'+count+'">Condition</a><button id="tab_close'+count+'" type="button" class="close tab-close-popup" aria-hidden="true" style="margin-top: -30px;margin-right: 5px">&times;</button></li>');
594                         $("#formId" + count).append(form);
595                         $(".formId").not($("#formId" + count)).css("display", "none")
596                         addCustListen(count)
597                         addTabListen(count)
598                         
599                         // This is for when the process is not loading from map but being created
600                         if (!loadingId) {
601                                 var l = makeid()
602                                 $(form).find("#_id").val(l)
603                                 stringMatch_ids["#formId" + count] = l
604                                 var answers = {}
605
606                                 for (k in answers) {
607                                         $(k).val(answers[k])
608                                 }
609                         }
610                         return count;
611                 }
612
613                 function add_new_stringMatch(issueNewNames) {
614                         //remove old gui forms
615                         for (var i = 1; i < ($(".formId").length + 1); i++) {
616                                 $("#go_properties_tab" + i).parent().remove();
617                         }
618                         $(".formId").remove();
619
620                         //Reset header
621                         var ms = new Date().getTime();
622                         var defSMatch = ms;
623                         $("#rgname").val(defSMatch);
624                         
625                         $("#rgfriendlyname").val("New_Group");
626
627                         $("#add_one_more").click();
628                         return defSMatch;
629                 }
630
631                 //listener will change the tab name to the recipe
632                 function addTabListen(count) {
633                         $("#formId" + count + " #recipe").on("change",function() {
634                                 if ($("#formId" + count + " #recipe").val().toString() !== "") {
635                                         $('#go_properties_tab' + count).text($("#formId" + count + " #recipe").val())
636                                 } else
637                                         $('#go_properties_tab' + count).text("String");
638
639                                 var answers = {}
640
641                                 for (var i = 1; i <= greatestIdNum(); i++) {
642                                         if ($("#formId" + i).length > 0) {
643
644                                                 answers["#formId" + i + " #parentStringMatch"] = $("#formId" + i + " #parentStringMatch").val()
645                                                 $("#formId" + i + " #parentStringMatch").empty();
646
647                                                 for (k in stringMatch_ids) {
648                                                         if ($("#formId" + i + " #_id").val().toString() !== stringMatch_ids[k] && $(k + " #recipe").val() !== 'undefined' && $(k + " #recipe").val() !== "") {
649                                                                 $("#formId" + i + " #parentStringMatch").append("<option value='"+stringMatch_ids[k]+"''> "+ $(k+ " #recipe").val()+ "</option>")
650                                                         }
651                                                 }
652                                                 $("#formId" + i + " #parentStringMatch").prepend("<option value=''></option>")
653                                         }
654                                 }
655                                 for (k in answers) {
656                                         $(k).val(answers[k])
657                                 }
658                         })
659
660                         // disable parentStringMatchConditions when a parentStringMatch is not selected
661                         $("#formId" + count + " #parentStringMatch").on("change",function() {
662                                 if ($("#formId" + count + " #parentStringMatch").val().toString() == "") {
663                                         // deselect all options
664                                         $("#formId"+ count+ " #parentStringMatchConditions option:selected").prop("selected", false);
665                                         // disable the select box
666                                         $("#formId"+ count+ " #parentStringMatchConditions").prop('disabled', 'disabled');
667                                 } else {
668                                         $("#formId"+ count+ " #parentStringMatchConditions").prop('disabled', false);
669                                 }
670                         })
671                 }
672
673                         function addSelectListen(count) {
674                                 var onSelectChange = function() {
675                                         var opselected = this.selectedOptions[0].text;
676
677                                         if (this.id=="outputEventName"){
678                                                 if(opselected!==""){
679                                                         var stringMatchCount = $(this).closest("[id^='formId']").attr("id").substring(6);
680                                                         $(this).closest(".stringMatchPanel").find("#go_properties_tab"+stringMatchCount).text(opselected);
681                                                 } else {
682                                                         $(this).closest("[id^='go_properties_tab']").text("Condition");
683                                                 }
684                                         }
685
686                                         if (this.id=="vfc"){
687                                                 var vfcCount = $(this).closest("[id^='formId']").attr("id").substring(6);
688                                                 if(opselected!==""){
689                                                         setAlarmConditions(opselected, vfcCount);
690                                                         setAlertDescription(opselected, vfcCount);
691                                                 } else {
692                                                         $(this).closest(".formId").find("#eventSourceType").val("");
693                                                         $(this).closest(".formId").find("#eventSeverity").val("");
694                                                 }
695                                         }
696
697                                         if (this.id=="alarmCondition"){
698                                                 var alarmCount = $(this).closest("[id^='formId']").attr("id").substring(6);
699                                                 if(opselected!==""){
700                                                         setEventSourceType(opselected.toString(), alarmCount, "alarm");
701                                                 } else {
702                                                         $(this).closest(".formId").find("#eventSourceType").val("");
703                                                         $(this).closest(".formId").find("#eventSeverity").val("");
704                                                 }
705                                         }
706
707                                 };
708
709                                 $("#formId"+count+" select").each( function () {
710                                         this.change = onSelectChange;
711                                 });
712                         }
713
714                 function addCustListen(count) {                 
715                         $('#go_properties_tab' + count).click(function(event) {
716                                 $("#nav_Tabs li").removeClass("active");
717                                 $(this).parent().addClass("active");
718                                 $("#formId" + count).css("display", "")
719                                 $(".formId").not($("#formId" + count)).css("display", "none")
720
721                         })
722                         $('#tab_close' + count).click(function(event) {
723
724                                 $(this).parent().remove();
725                                 delete stringMatch_ids["#formId" + count + " #_id"]
726                                 $("#formId" + count).remove();
727                         })
728                 }
729                 
730                 function setStringSet(form) {
731                         var arr = []
732                         var alarmCondition = {}
733                         var eventSeverity = {}
734                         var eventSourceType = {}
735                         for (var i = 0; i < form.length; i++) {
736                                 if (form[i].name === "alarmCondition") {
737                                         alarmCondition = form[i]
738                                 } else if (form[i].name === "eventSeverity") {
739                                         eventSeverity = form[i];
740                                 } else if (form[i].name === "eventSourceType") {
741                                         eventSourceType = form[i];
742                                 } else {
743
744                                         arr.push(form[i])
745                                 }
746
747                         }
748                         var stringSet = {};
749                         stringSet['stringSet'] = []
750                         stringSet['stringSet'].push(alarmCondition);
751                         stringSet['stringSet'].push(eventSeverity);
752                         stringSet['stringSet'].push(eventSourceType);
753                         arr.push(stringSet)
754
755                         return arr;
756                 }
757                 
758                 //this will populate alarmcondition,vfc,eventtypesource if they are saved in elementmap
759                 function set_vfc_alarm_event (count){
760                         if(vfc_temp!=="" && vfc_temp!==undefined){
761                                 $("#formId"+count+" #vfc").val(vfc_temp)
762                                 
763                                 if(alarm_conditions_temp!=="" && alarm_conditions_temp!==undefined){
764                                         setAlarmConditions(vfc_temp,count)
765                                         $("#formId"+count+" #alarmCondition").val(alarm_conditions_temp);
766                                         
767                                         if(event_severity_temp!=="" && event_severity_temp!==undefined){
768                                                 setEventSourceType(alarm_conditions_temp,count)
769                                                 $("#formId"+count+" #eventSeverity").val(event_severity_temp)
770                                                 if(event_type_source_temp!=="" && event_type_source_temp!==undefined){
771                                                         $("#formId"+count+" #eventSourceType").val(event_type_source_temp)
772                                                 }
773                                         }
774                                         if(event_type_source_temp!=="" && event_type_source_temp!==undefined){
775                                                 setEventSourceType(alarm_conditions_temp,count)
776                                                 $("#formId"+count+" #eventSourceType").val(event_type_source_temp)
777                                                 if(event_severity_temp!=="" && event_severity_temp!==undefined){
778                                                         $("#formId"+count+" #eventSeverity").val(event_severity_temp)
779                                                 }
780                                         }
781                                 }
782                         }
783                 }
784
785                 function setAlarmConditions(vfcID, count){
786                         var alarmCondition={}
787                         
788                         if($("#formId"+count+" #vfc").val()!==""){
789                                 if(vf_Services['shared'] && vf_Services['shared']['byVfc'] && vf_Services['shared']['byVfc'][vfcID]){
790                                         alarmCondition=vf_Services['shared']['byVfc'][vfcID]['alarmCondition']  
791                                 }
792                         }
793                         
794                         $("#formId"+count+" #alarmCondition").empty();
795                         $("#formId"+count+" #alarmCondition").append("<option value=\"\"></opton>");
796                          if(alarmCondition && _.keys(alarmCondition).length>0){
797                                 for(key in alarmCondition){
798                                         var safestring = $('<div>').text(key).html();
799                                         $("#formId"+count+" #alarmCondition").append("<option value='"+safestring+"'>"+alarmCondition[key]+"</opton>"); 
800                                 }
801                                 $("#formId"+count+" #alarmCondition").multiselect("rebuild");
802                         }
803                 }
804
805                 function setEventSourceType(alarm, count){
806                         var eventSourceTypSeverity={}
807                         if($("#formId"+count+" #alarmCondition").val()!==""){
808                                 if(vf_Services && vf_Services['shared'] && vf_Services['shared']['byAlarmCondition'] && vf_Services['shared']['byAlarmCondition'][alarm]){
809                                         eventSourceTypSeverity=vf_Services['shared']['byAlarmCondition'][alarm] 
810                                 }
811                                 
812                         }
813                         
814                         $("#formId"+count+" #eventSourceType").val(eventSourceTypSeverity.eventSourceType);
815                         $("#formId"+count+" #eventSeverity").val(eventSourceTypSeverity.eventSeverity);
816                         $("#formId"+count+" #eventSeverity").multiselect("rebuild");
817                 }               
818
819                 function greatestIdNum() {
820                         var greatest = 0;
821                         var s = $(".formId");
822                         for (var i = 0; i < s.length; i++) {
823                                 if (parseInt($(s[i]).attr("id").substring(6)) > greatest) {
824                                         greatest = parseInt($(s[i]).attr("id").substring(6))
825                                 }
826                         }
827                         return greatest;
828                 }
829
830                 //Generate random id for each String
831                 //Also made sure ids couldnt be repeated
832                 function makeid(num) {
833
834                         var text = "";
835                         var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
836                         if (num == null)
837                                 num = 7;
838                         for (var i = 0; i < 7; i++)
839                                 text += possible.charAt(Math.floor(Math.random()
840                                                 * possible.length));
841                         var hasValue = false;
842                         for (k in stringMatch_ids) {
843                                 if (text === stringMatch_ids[k])
844                                         hasValue = true
845                         }
846                         if (hasValue)
847                                 return makeid(num);
848                         else
849                                 return text
850                 }
851
852                 var ParentStringMatch = function(id, name) {
853                         this.id = id
854                         this.name = name
855                 }
856
857                 //String table search filter
858                 function searchStringMatchList() {
859                         var search = document.getElementById("stringMatchSearch");
860                         var row = document.getElementsByTagName("td");
861                         for (var i = 0; i < row.length; i++) {
862                                 if (row[i].innerHTML.toUpperCase().indexOf(
863                                                 search.value.toUpperCase()) > -1) {
864                                         row[i].style.display = "";
865                                 } else {
866                                         row[i].style.display = "none";
867                                 }
868                         }
869                 }
870
871                 function saveLastStringMatchLocally(lastStringMatchId) {
872                         var polForm = []
873
874                         var properties = $(".saveProps").not("#formSpan .saveProps")
875                         
876                         var topicPublish = $("#topicPublish").serializeArray();
877                         
878                         for (var i = 0; i < topicPublish.length; i++) {
879                                 polForm.push(topicPublish[i]);
880                         }
881                         
882                         //The below three lines are added to make sure resource group can be save correctly even if the policy is not present 
883                         if (topicPublish.length == 2){
884                                 var pname = {name:"policyName", value:""};
885                                 polForm.push(pname);
886                                 var pid = {name:"policyId", value:""};
887                                 polForm.push(pid);
888                         }else{
889                                 var selectedPName = topicPublish[2]["value"];
890                                 var pid = {name:"policyId", value:allPolicies[selectedPName][1]["value"]};
891                                 polForm.push(pid);
892                         }
893
894                         var d = {}
895                         d["serviceConfigurations"] = [];
896                         for (var i = 0; i < properties.length; i++) {
897                                 var ser = $(properties[i]).serializeArray();
898                                 var s = noRepeats(ser)
899                                 var newSer = setStringSet(s);
900                                 d["serviceConfigurations"].push(newSer);
901                         }
902                         polForm.push(d);
903                         allSMatch[lastStringMatchId] = polForm;
904                 }
905
906                 $("#deleteStringMatch").on('click', function() {
907                         $(".idError").hide();
908                         var deleteId = $("#stringMatchTable .highlight td").html();
909                         delete allSMatch.deleteId;
910                         $("#stringMatchTable .highlight").remove();
911                         $("#rgfriendlyname").val('');
912                         expandTable();
913                 });
914
915                 $('#stringMatchTable').on('click', 'tr', function(event) {
916                         $(".idError").hide();
917                         //edited name
918                         if ($("#stringMatchTable .highlight td").html() !== $("#rgfriendlyname").val()){
919                                 //repeated name
920                                 if ($.inArray($("#rgfriendlyname").val(), Object.keys(allSMatch)) > -1){
921                                         $("#repeatIdError").show();
922                                         return;
923                                 } else { //not repeated
924                                         $("#repeatIdError").hide();
925                                         delete allSMatch[$("#stringMatchTable .highlight td").html()];
926                                 }
927                         }
928                         if ($("#rgfriendlyname").val().trim() == "New_Group"){
929                                 $("#newIdError").show();
930                                 return;
931                         }
932                         if (!(readOnly||readMOnly)){
933                                 startNextItem();
934                         } else {
935                                 if ($("#stringMatchTable .highlight").length == 0){
936                                         collapseTable();                
937                                 }
938                         }
939
940                         $(this).addClass('highlight').siblings().removeClass('highlight');
941                         disperseConfig(allSMatch, $(this).find("td").html());
942                 });
943
944                 
945                 $('#createNewStringMatch').on('click',  function() {
946                         $(".idError").hide();
947                         //edited name
948                         if ($("#stringMatchTable .highlight td").html() !== $("#rgfriendlyname").val()){
949                                 //repeated name
950                                 if ($.inArray($("#rgfriendlyname").val(), Object.keys(allSMatch)) > -1){
951                                         $("#repeatIdError").show();
952                                         return;
953                                 } else { //not repeated
954                                         $("#repeatIdError").hide();
955                                         delete allSMatch[$("#stringMatchTable .highlight td").html()];
956                                 }
957                         }
958                         if ($("#rgfriendlyname").val().trim() == "New_Group"){
959                                 $("#newIdError").show();
960                                 return;
961                         }
962                         startNextItem();
963                         var defSMatch = add_new_stringMatch();
964
965                         if (("#stringMatchTable .highlight").length > 0) {
966                                 $('#stringMatchTable tr.highlight').removeClass('highlight');
967                         }
968                         //$("#stringMatchTable").prepend("<tr class='highlight' id='" +defSMatch+ "''><td>"+ defSMatch + "</td></tr>");
969                         $("#stringMatchTable").prepend("<tr class='highlight'><td>New_Group</td></tr>");
970                         
971                 });
972
973                 function isNumberKey(event){
974                         var charCode = (event.which) ? event.which : event.keyCode
975                         if (charCode > 31 && (charCode < 48 || charCode > 57)){
976                                 return false;
977                         }
978                         return true;
979                 };
980                 
981                 function startNextItem() {
982                         //save last item before transitioning
983                         var lastItem = $("#stringMatchTable .highlight");
984                         
985                         
986                         if (lastItem.length > 0) {
987                                 saveLastStringMatchLocally($("#rgfriendlyname").val());
988                                 //lastItem.attr("id", $("#rgfriendlyname").val());
989                                 if($("#rgfriendlyname").val() != ''){
990                                         lastItem.find("td").html($("#rgfriendlyname").val());
991                                 }
992                         } else {
993                                 collapseTable();
994                         }
995
996                         //allow deleting
997                         if ($("#deleteStringMatch").prop("disabled")) {
998                                 $("#deleteStringMatch").prop("disabled", false);
999                         }
1000                 }
1001
1002                 //Show table panel only
1003                 function expandTable() {
1004                         $(".stringMatchPanel").css("display", "none");
1005                         $(".leftStringMatchPanel").removeClass("col-sm-3");
1006                         $(".modelSearchBox").css("padding", "25px 12px");
1007                         if (!($("#deleteStringMatch").prop("disabled"))) {
1008                                 $("#deleteStringMatch").prop("disabled", true);
1009                         }
1010                 }
1011
1012                 //Show both menus
1013                 function collapseTable() {
1014                         $(".leftStringMatchPanel").addClass("col-sm-3");
1015                         $(".glyphicon-search").css("padding", "10px 12px");
1016                         $(".stringMatchPanel").css("display", "unset");
1017                 }
1018         </script>
1019 </div>