GUAC-1160: Create "guacForm" directive which allows the editing of an arbitrary set of fields.

This commit is contained in:
Michael Jumper
2015-04-15 16:05:20 -07:00
parent d29ab56d44
commit 32019e7cdf
5 changed files with 170 additions and 38 deletions

View File

@@ -0,0 +1,82 @@
/*
* Copyright (C) 2015 Glyptodon LLC
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
/**
* A directive that allows editing of a collection of fields.
*/
angular.module('form').directive('guacForm', [function form() {
return {
// Element only
restrict: 'E',
replace: true,
scope: {
/**
* The fields to display.
*
* @type Field[]
*/
fields : '=',
/**
* The object which will receive all field values. Each field value
* will be assigned to the property of this object having the same
* name.
*
* @type Object.<String, String>
*/
model : '='
},
templateUrl: 'app/form/templates/form.html',
controller: ['$scope', function formController($scope) {
/**
* The object which will receive all field values. Normally, this
* will be the object provided within the "model" attribute. If
* no such object has been provided, a blank model will be used
* instead as a placeholder, such that the fields of this form
* will have something to bind to.
*
* @type Object.<String, String>
*/
$scope.values = {};
// Update string value and re-assign to model when field is changed
$scope.$watch('model', function setModel(model) {
// Assign new model only if provided
if (model)
$scope.values = model;
// Otherwise, use blank model
else
$scope.values = {};
});
}] // end controller
};
}]);

View File

@@ -0,0 +1,50 @@
/*
* Copyright (C) 2015 Glyptodon LLC
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
/* Keep toggle-password icon on same line */
.form-field .password-field {
white-space: nowrap;
}
/* Generic 1x1em icon/button */
.form-field .password-field .icon.toggle-password {
display: inline-block;
opacity: 0.5;
cursor: default;
background-repeat: no-repeat;
background-size: 1em;
width: 1em;
height: 1em;
}
/* Icon for unmasking passwords */
.form-field .password-field input[type=password] ~ .icon.toggle-password {
background-image: url('images/action-icons/guac-show-pass.png');
}
/* Icon for masking passwords */
.form-field .password-field input[type=text] ~ .icon.toggle-password {
background-image: url('images/action-icons/guac-hide-pass.png');
}

View File

@@ -20,31 +20,8 @@
* THE SOFTWARE.
*/
/* Keep toggle-password icon on same line */
.form-field .password-field {
white-space: nowrap;
}
/* Generic 1x1em icon/button */
.form-field .password-field .icon.toggle-password {
display: inline-block;
opacity: 0.5;
cursor: default;
background-repeat: no-repeat;
background-size: 1em;
width: 1em;
height: 1em;
}
/* Icon for unmasking passwords */
.form-field .password-field input[type=password] ~ .icon.toggle-password {
background-image: url('images/action-icons/guac-show-pass.png');
}
/* Icon for masking passwords */
.form-field .password-field input[type=text] ~ .icon.toggle-password {
background-image: url('images/action-icons/guac-hide-pass.png');
table.form th {
text-align: left;
font-weight: normal;
padding-right: 1em;
}

View File

@@ -0,0 +1,32 @@
<table class="form">
<!--
Copyright 2015 Glyptodon LLC.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-->
<!-- All fields in form -->
<tr ng-repeat="field in fields">
<th>{{field.title | translate}}</th>
<td>
<guac-form-field field="field" model="values[field.name]"></guac-form-field>
</td>
</tr>
</table>

View File

@@ -59,17 +59,8 @@ THE SOFTWARE.
<!-- Connection parameters -->
<h2 class="header">{{'MANAGE_CONNECTION.SECTION_HEADER_PARAMETERS' | translate}}</h2>
<div class="section" ng-class="{loading: !parameters}">
<table class="properties connection-parameters">
<!-- All the different possible editable field types -->
<tr ng-repeat="parameter in protocols[connection.protocol].parameters">
<th>{{parameter.title | translate}}</th>
<td>
<guac-form-field field="parameter" model="parameters[parameter.name]"></guac-form-field>
</td>
</tr>
</table>
<div class="section connection-parameters" ng-class="{loading: !parameters}">
<guac-form fields="protocols[connection.protocol].parameters" model="parameters"></guac-form>
</div>
<!-- Form action buttons -->