2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
23 var parameterBlockDirective = function($log, PARAMETER, UtilityService) {
25 * If "IS_SINGLE_OPTION_AUTO_SELECTED" is set to "true" ...
27 * IF these 3 conditions all exist:
29 * 1) The parameter type is PARAMETER.SELECT
31 * 2) AND the "prompt" attribute is set to a string.
33 * 3) AND the optionList" only contains a single entry
35 * THEN the "prompt" will not be displayed as an initial select option.
38 var IS_SINGLE_OPTION_AUTO_SELECTED = true;
41 * Optionally remove "nameStyle" and "valueStyle" "width" entries to set
44 var tableStyle = "width: auto; margin: 0 auto; border-collapse: collapse; border: none;";
45 var nameStyle = "width: 220px; text-align: left; vertical-align: middle; font-weight: bold; padding: 3px 5px; border: none;";
46 var valueStyle = "width: 400px; text-align: left; vertical-align: middle; padding: 3px 5px; border: none;";
47 var checkboxValueStyle = "width: 400px; text-align: center; vertical-align: middle; padding: 3px 5px; border: none;"
48 var textInputStyle = "height: 25px; padding: 2px 5px;";
49 var checkboxInputStyle = "height: 18px; width: 18px; padding: 2px 5px;";
50 var selectStyle = "height: 25px; padding: 2px; text-align: center;";
51 var requiredLabelStyle = "width: 25px; padding: 5px 10px 10px 5px;";
54 var getParameterHtml = function(parameter, editable) {
55 var style = valueStyle;
56 var attributeString = "";
57 if (parameter.type === PARAMETER.BOOLEAN) {
58 style = checkboxValueStyle;
60 if (UtilityService.hasContents(parameter.description)) {
61 attributeString += " title=' " + parameter.description + " '";
64 if(parameter.type == 'file' && !parameter.isVisiblity){
65 rowstyle = ' style="display:none;"';
67 var html = "<tr"+rowstyle+"><td style='" + nameStyle + "'" + attributeString + ">"
68 + getNameHtml(parameter) + "</td>";
69 if (editable === undefined) {
70 if (UtilityService.hasContents(parameter.value)) {
71 html += "<td data-tests-id='" + getParameterName(parameter) + "' style='" + style + "'>" + parameter.value;
73 html += "<td data-tests-id='" + getParameterName(parameter) + "' style='" + style + "'>";
76 html += "<td style='" + style + "'>" + getValueHtml(parameter);
82 var updateParameter = function(parameter, element, editable) {
83 $(element).parent().parent().children("td").first().html(
84 getNameHtml(parameter));
85 if (editable === undefined) {
86 $(element).html(parameter.value);
88 $(element).parent().html(getValueHtml(parameter));
92 var getNameHtml = function(parameter) {
93 if (parameter.isVisible === false) {
96 var name = getParameterName(parameter);
98 var requiredLabel = "";
99 if (parameter.isRequired) {
100 requiredLabel = "<img src='app/vid/images/asterisk.png' style='"
101 + requiredLabelStyle + "'></img>";
103 return name + ":" + requiredLabel;
106 var getParameterName = function(parameter) {
108 if (UtilityService.hasContents(parameter.name)) {
109 name = parameter.name;
116 var getValueHtml = function(parameter) {
118 var textInputPrompt = "Enter data";
119 var attributeString = " data-tests-id='" + parameter.id +"' parameter-id='" + parameter.id + "'";
120 var additionalStyle = "";
121 if (parameter.isEnabled === false) {
122 attributeString += " disabled='disabled'";
124 if (parameter.isRequired) {
125 attributeString += " is-required='true'";
127 if (UtilityService.hasContents(parameter.description)) {
128 attributeString += " title=' " + parameter.description + " '";
130 if (UtilityService.hasContents(parameter.isReadOnly) && (parameter.isReadOnly === true)) {
131 attributeString += " readonly";
133 if ( (UtilityService.hasContents(parameter.maxLength)) && (UtilityService.hasContents(parameter.minLength)) ) {
134 attributeString += " pattern='.{" + parameter.minLength + "," + parameter.maxLength + "}' required";
136 else if (UtilityService.hasContents(parameter.maxLength)) {
137 attributeString += " maxlength='" + parameter.maxLength + "'";
139 else if (UtilityService.hasContents(parameter.minLength)) {
140 attributeString += " pattern='.{" + parameter.minLength + ",}'"
142 if (parameter.isVisible === false) {
143 additionalStyle = " visibility: hidden;";
147 if (UtilityService.hasContents(parameter.name)) {
148 name = parameter.name;
152 attributeString += " parameter-name='" + name + "'";
154 if ( parameter.type === PARAMETER.MAP ) {
155 textInputPrompt = "{<key1>: <value1>,\.\.\.,<keyN>: <valueN>}";
158 if ( parameter.type === PARAMETER.LIST ) {
159 textInputPrompt = "[<value1>,\.\.\.,<valueN>]";
162 switch (parameter.type) {
163 case PARAMETER.BOOLEAN:
164 if (parameter.value) {
165 return "<select" + attributeString + " style='" + selectStyle
166 + additionalStyle + "'>" + "<option value=true>true</option>"
167 + "<option value=false>false</option>";
170 return "<select" + attributeString + " style='" + selectStyle
171 + additionalStyle + "'>" + "<option value=false>false</option>"
172 + "<option value=true>true</option>"
176 case PARAMETER.CHECKBOX:
177 if (parameter.value) {
178 return "<input type='checkbox' "+attributeString+ " checked='checked' style='"+checkboxInputStyle+"'"
181 return "<input type='checkbox' "+attributeString+ "' style='"+checkboxInputStyle+"'"
182 + " value='false'/>";
186 return "<input type='file' "+attributeString+ " id='"+parameter.id+"' value='"+parameter.value+"'/>";
188 case PARAMETER.NUMBER:
189 var value=parameter.value;
190 var parameterSpec = "<input type='number'" + attributeString + " style='" + textInputStyle + additionalStyle + "'";
192 if ( UtilityService.hasContents(parameter.min) ) {
193 parameterSpec += " min='" + parameter.min + "'";
195 if ( UtilityService.hasContents(parameter.max) ) {
196 parameterSpec += " max='" + parameter.max + "'";
198 if (UtilityService.hasContents(value)) {
199 parameterSpec += " value='" + value + "'";
201 parameterSpec += ">";
203 /*if(!isNaN(value) && value.toString().index('.') != -1){
205 return "<input type='text'" + attributeString + " style='"
206 + textInputStyle + additionalStyle + "' only-integers" + value
210 return "<input type='text'" + attributeString + " style='"
211 + textInputStyle + additionalStyle + "' only-float" + value
214 return (parameterSpec);
216 case PARAMETER.SELECT:
217 if (UtilityService.hasContents(parameter.prompt)) {
218 attributeString += " prompt='" + parameter.prompt + "'";
220 return "<select" + attributeString + " style='" + selectStyle
221 + additionalStyle + "'>" + getOptionListHtml(parameter)
224 case PARAMETER.STRING:
227 if (UtilityService.hasContents(parameter.value)) {
228 value = " value='" + parameter.value + "'";
230 if (UtilityService.hasContents(parameter.prompt)) {
231 attributeString += " placeholder='" + parameter.prompt + "'";
232 } else if (textInputPrompt !== "") {
233 attributeString += " placeholder='" + textInputPrompt + "'";
235 var finalString = "<input type='text'" + attributeString + " style='"
236 + textInputStyle + additionalStyle + "'" + value
243 var getBooleanListHtml = function(parameter){
248 var getOptionListHtml = function(parameter) {
253 if (!angular.isArray(parameter.optionList)
254 || parameter.optionList.length === 0) {
258 if (UtilityService.hasContents(parameter.prompt)) {
259 if (!(IS_SINGLE_OPTION_AUTO_SELECTED && parameter.optionList.length === 1) || !(parameter.isSingleOptionAutoSelected && parameter.optionList.length === 1)) {
260 html += "<option value=''>" + parameter.prompt + "</option>";
264 for (var i = 0; i < parameter.optionList.length; i++) {
265 var option = parameter.optionList[i];
266 var name = option.name;
268 if (option.id === undefined) {
271 if (name === undefined) {
276 if (option.isDefault === undefined || option.isDefault === false ) {
277 html += "<option value='" + value + "'>" + name + "</option>";
280 html += "<option value='" + value + "' selected>" + name + "</option>";
287 if (!angular.isArray(parameter.optionList)
288 || parameter.optionList.length === 0) {
292 if (UtilityService.hasContents(parameter.prompt)) {
293 if (!(IS_SINGLE_OPTION_AUTO_SELECTED && parameter.optionList.length === 1)) {
294 html += "<option value=''>" + parameter.prompt + "</option>";
298 for (var i = 0; i < parameter.optionList.length; i++) {
299 var option = parameter.optionList[i];
300 var name = option.name;
302 if (option.id === undefined) {
305 if (name === undefined) {
310 html += getOptionHtml(option.isPermitted, option.isDataLoading, value, name, parameter);
313 >>>>>>> 7e45cad... merge
316 function getOptionHtml(isPermitted, isDefault, value, name, parameter) {
318 if (isDefault === undefined || isDefault === false ) {
320 html = "<option class='" + parameter.id + "Option' value='" + value + "'>" + name + "</option>";
322 html = "<option class='" + parameter.id + "Option' value='" + value + "' disabled>" + name + "</option>";
327 html = "<option class='" + parameter.id + "Option' value='" + value + "'>" + "' selected>" + name + "</option>";
329 html = "<option class='" + parameter.id + "Option' value='" + value + "' disabled>" + "' selected>" + name + "</option>";
335 var getParameter = function(element, expectedId) {
336 var id = $(element).attr("parameter-id");
337 if (expectedId !== undefined && expectedId !== id) {
343 if ($(element).prop("type") === "checkbox") {
344 parameter.value = $(element).prop("checked");
345 }else if ($(element).prop("type") === "file") {
346 parameter.value = $('#'+id).attr("value");
349 if ($(element).prop("type") === "text") {
350 $(element).val($(element).val().trim());
352 parameter.value = $(element).val();
354 if ($(element).prop("selectedIndex") === undefined) {
355 parameter.selectedIndex = -1;
357 parameter.selectedIndex = $(element).prop("selectedIndex");
358 if (UtilityService.hasContents($(element).attr("prompt"))) {
359 parameter.selectedIndex--;
365 var getRequiredField = function(element) {
366 if ($(element).prop("type") === "text") {
367 $(element).val($(element).val().trim());
369 if ($(element).val() === "" || $(element).val() === null) {
370 return '"' + $(element).attr("parameter-name") + '"';
376 var callback = function(element, scope) {
378 id : $(element).attr("parameter-id")
385 template : "<div><table style='" + tableStyle + "'></table></div>",
390 link : function(scope, element, attrs) {
392 var control = scope.control || {};
394 control.setList = function(parameterList) {
396 for (var i = 0; i < parameterList.length; i++) {
397 html += getParameterHtml(parameterList[i], attrs.editable);
400 element.find("input, select").bind("change", function() {
401 callback(this, scope);
405 control.updateList = function(parameterList) {
406 element.find("input, select").each(
408 for (var i = 0; i < parameterList.length; i++) {
409 if (parameterList[i].id === $(this).attr(
411 updateParameter(parameterList[i], this,
416 element.find("input, select").bind("change", function() {
417 callback(this, scope);
421 control.getList = function(expectedId) {
422 var parameterList = new Array();
423 element.find("input, select").each(function() {
424 var parameter = getParameter(this, expectedId);
425 if (parameter !== undefined) {
426 parameterList.push(parameter);
429 return parameterList;
432 control.getRequiredFields = function() {
433 var requiredFields = "";
435 element.find("input, select").each(function() {
436 if ($(this).attr("is-required") === "true") {
437 var requiredField = getRequiredField(this);
438 if (requiredField !== "") {
440 requiredFields = requiredField;
446 return requiredFields;
447 } else if (count == 1) {
448 return requiredFields + " and 1 other field";
450 return requiredFields + " and " + count + " other fields";
457 appDS2.directive('parameterBlock', [ "$log", "PARAMETER", "UtilityService",
458 parameterBlockDirective ]);
461 appDS2.directive('onlyIntegers', function () {
464 link: function (scope, elm, attrs, ctrl) {
465 elm.on('keydown', function (event) {
466 if(event.shiftKey){event.preventDefault(); return false;}
467 //console.log(event.which);
468 if ([8, 13, 27, 37, 38, 39, 40].indexOf(event.which) > -1) {
469 // backspace, enter, escape, arrows
471 } else if (event.which >= 49 && event.which <= 57) {
474 } else if (event.which >= 96 && event.which <= 105) {
478 // else if ([110, 190].indexOf(event.which) > -1) {
479 // // dot and numpad dot
483 event.preventDefault();
491 appDS2.directive('onlyFloat', function () {
494 link: function (scope, elm, attrs, ctrl) {
495 elm.on('keydown', function (event) {
496 if ([110, 190].indexOf(event.which) > -1) {
497 // dot and numpad dot
498 event.preventDefault();