1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-29 18:50:08 +03:00

Bug #3993: Allow vector attributes in custom-tags table

Vector attributes only work if they come in an update.
There isn't a button to add new vector attributes, but
it could be easily added if it's needed
This commit is contained in:
Carlos Martín 2015-09-21 17:06:54 +02:00
parent 0c5db8ec8e
commit 408881e791
6 changed files with 101 additions and 18 deletions

View File

@ -3,6 +3,8 @@ define(function(require) {
var Locale = require('utils/locale');
var TemplateHTML = require('hbs!./custom-tags-table/html');
var RowTemplateHTML = require('hbs!./custom-tags-table/row');
var VectorRowTemplateHTML = require('hbs!./custom-tags-table/vector-row');
var VectorAttributeRowTemplateHTML = require('hbs!./custom-tags-table/vector-attribute-row');
var TemplateUtils = require('utils/template-utils');
function _html(){
@ -12,12 +14,18 @@ define(function(require) {
function _setup(context){
context.off("click", ".add_custom_tag");
context.on("click", ".add_custom_tag", function(){
$(".custom_tags tbody", context).append(RowTemplateHTML());
$("tbody.custom_tags", context).append(RowTemplateHTML());
});
context.off("click", ".add_vector_attribute");
context.on("click", ".add_vector_attribute", function(){
var tbody = $("tbody.custom_vector_attributes", $(this).closest('table'));
tbody.append(VectorAttributeRowTemplateHTML());
});
$(".add_custom_tag", context).trigger("click");
context.on("click", ".custom_tags i.remove-tab", function(){
context.on("click", "tbody.custom_tags i.remove-tab", function(){
var tr = $(this).closest('tr');
tr.remove();
});
@ -27,10 +35,25 @@ define(function(require) {
function _retrieveCustomTags(context){
var template_json = {};
$('.custom_tags tr', context).each(function(){
$('tbody.custom_tags tr', context).each(function(){
if ($('.custom_tag_key', $(this)).val()) {
template_json[$('.custom_tag_key', $(this)).val()] = $('.custom_tag_value', $(this)).val();
}
if ($('.custom_vector_key', $(this)).val()) {
var vectorAttributes = {};
$('tbody.custom_vector_attributes tr', $(this)).each(function(){
var key = $('.custom_vector_attribute_key', $(this)).val();
if (key) {
vectorAttributes[key] = $('.custom_vector_attribute_value', $(this)).val();
}
});
if (!$.isEmptyObject(vectorAttributes)){
template_json[$('.custom_vector_key', $(this)).val()] = vectorAttributes;
}
}
});
return template_json;
@ -39,11 +62,16 @@ define(function(require) {
// context is the container div of customTagsHtml()
// template_json are the key:values that will be put into the table
function _fillCustomTags(context, template_json){
$(".custom_tags i.remove-tab", context).trigger("click");
$("tbody.custom_tags i.remove-tab", context).trigger("click");
$.each(template_json, function(key, value){
$(".custom_tags tbody", context).append(
RowTemplateHTML({key: key, value: value}));
if (typeof value == 'object') {
$("tbody.custom_tags", context).append(
VectorRowTemplateHTML({key: key, value: value}));
} else {
$("tbody.custom_tags", context).append(
RowTemplateHTML({key: key, value: value}));
}
});
}

View File

@ -1,6 +1,6 @@
<div class="row">
<div class="large-12 columns">
<table class="custom_tags dataTable policies_table">
<table class="dataTable policies_table">
<thead>
<tr>
<th>{{tr "KEY"}}</th>
@ -8,7 +8,7 @@
<th></th>
</tr>
</thead>
<tbody>
<tbody class="custom_tags">
</tbody>
<tfoot>
<tr>

View File

@ -1,13 +1,13 @@
<tr>
<td>
<input class="custom_tag_key" type="text" name="key" value="{{key}}">
</td>
<td>
<textarea class="custom_tag_value" name="value">
{{~value~}}
</textarea>
</td>
<td>
<a href="#"><i class="fa fa-times-circle remove-tab"></i></a>
</td>
</td>
<td>
<textarea class="custom_tag_value" name="value">
{{~value~}}
</textarea>
</td>
<td>
<a href="#"><i class="fa fa-times-circle remove-tab"></i></a>
</td>
</tr>

View File

@ -0,0 +1,13 @@
<tr>
<td>
<input class="custom_vector_attribute_key" type="text" name="key" value="{{key}}">
</td>
<td>
<textarea class="custom_vector_attribute_value" name="value">
{{~value~}}
</textarea>
</td>
<td>
<a href="#"><i class="fa fa-times-circle remove-tab"></i></a>
</td>
</tr>

View File

@ -0,0 +1,38 @@
<tr>
<td>
<input class="custom_vector_key" type="text" name="key" value="{{key}}">
</td>
<td>
<table>
<tbody class="custom_vector_attributes">
{{#each value}}
<tr>
<td>
<input class="custom_vector_attribute_key" type="text" name="key" value="{{@key}}">
</td>
<td>
<textarea class="custom_vector_attribute_value" name="value">
{{~this~}}
</textarea>
</td>
<td>
<a href="#"><i class="fa fa-times-circle remove-tab"></i></a>
</td>
</tr>
{{/each}}
</tbody>
<tfoot>
<tr>
<td colspan="3">
<a type="button" class="add_vector_attribute button small small-12 secondary radius">
<i class="fa fa-plus"></i>
</a>
</td>
</tr>
</tfoot>
</table>
</td>
<td>
<a href="#"><i class="fa fa-times-circle remove-tab"></i></a>
</td>
</tr>

View File

@ -1318,4 +1318,8 @@ hr {
#menu-toggle {
padding: 0px
}
}
.custom_tags td {
vertical-align: top;
}