Skip to content
This repository has been archived by the owner on May 23, 2019. It is now read-only.

Commit

Permalink
fix(Things): Fixed freeform combobox editor
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Jackson <chris@cd-jackson.com>
  • Loading branch information
cdjackson committed May 22, 2016
1 parent e20c646 commit cc1f65b
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 19 deletions.
24 changes: 9 additions & 15 deletions src/app/configuration/eshConfigParam.tpl.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
search-enabled="false"
multiple
limit="config.multipleLimit"
ng-disabled="config.readOnly"
>
ng-disabled="config.readOnly">
<ui-select-match>
{{$item.label}}
</ui-select-match>
Expand Down Expand Up @@ -46,25 +45,20 @@

<div ng-if="config.options!=null && config.options.length!=0 && config.multiple!=true && config.limitToOptions==false">
<!-- Single select dropdown, but allowing other entries -->

<!-- since this doesn't work - use an input box -->
<bootstrap-combo
name="{{config.name}}"
ng-dirty ng-required="{{config.required}}"
id="CONFIGLABEL-{{cfgType}}-{{config.name}}"
ng-model="cfgModel"
data-dropdown-data="config.options"
>
<bootstrap-combo id="CONFIGLABEL-{{cfgType}}-{{config.name}}"
name="{{config.name}}"
ng-dirty ng-required="{{config.required}}"
ng-model="cfgModel"
data-dropdown-data="config.options">
</div>

<div ng-if="config.options==null || config.options.length==0">
<input config-parameter="{{config}}"
<input id="CONFIGLABEL-{{cfgType}}-{{config.name}}"
config-parameter="{{config}}"
class="form-control"
name="{{config.name}}"
ng-dirty ng-required="{{config.required}}"
id="CONFIGLABEL-{{cfgType}}-{{config.name}}"
ng-model="cfgModel"
>
ng-model="cfgModel">
</div>

<p class="help-block single-line" ng-hide="config.description==null || config.description.length==0">
Expand Down
2 changes: 1 addition & 1 deletion src/app/configuration/thingConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@ angular.module('Config.Things', [
$scope.thingSave = function () {
var promises = [];

// Check if anything at thing level needs updating
// Check if anything at thing level needs updating (ie Channel Configuration)
var thingUpdated = false;
var updatedThing = {};
if ($scope.thingConfigForm.modifiedChildFormsCount !== 0) {
Expand Down
36 changes: 33 additions & 3 deletions src/common/combobox.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,51 @@ angular.module('bootstrapCombo', [
.directive('bootstrapCombo', function ($compile) {
return {
restrict: 'E',
require: "ngModel",
scope: {
items: '=dropdownData',
selectedItem: '=preselectedItem',
ngModel: '=',
placeholder: '@'
},
link: function (scope, element, attrs) {
link: function (scope, element, attrs,ngModel) {
scope.value = scope.ngModel;
for(var item in scope.items) {
if(scope.items[item].value == parseInt(scope.ngModel)) {
scope.value = scope.items[item].label;
break;
}
}

scope.selectVal = function (item) {
scope.ngModel = item.value;
scope.value = item.label;
ngModel.$setViewValue(item.value);
};

ngModel.$render = function() {
var value = ngModel.$viewValue;
for(var item in scope.items) {
if(scope.items[item].value == parseInt(ngModel.$viewValue)) {
value = scope.items[item].label;
break;
}
}
scope.value = value;
};

scope.$watch("value", function() {
for(var item in scope.items) {
if(scope.items[item].label == scope.value) {
ngModel.$setViewValue(scope.items[item].value);
return;
}
}
ngModel.$setViewValue(scope.value);
});

var html = '';
html += ' <div class="input-group">';
html += ' <input class="form-control" type="text" data-ng-model ="ngModel" data-ng-attr-placeholder="{{placeholder}}" />';
html += ' <input class="form-control" type="text" ng-model="value" ng-attr-placeholder="{{placeholder}}" />';
html += ' <div class="input-group-btn" data-ng-if="items.length">';
html += ' <div class="btn-group ">';
html += ' <button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown" >';
Expand Down

0 comments on commit cc1f65b

Please sign in to comment.