Reviewed-by: ShaoHe Feng <shaohef(a)linux.vnet.ibm.com>
Tested-by: ShaoHe Feng <shaohef(a)linux.vnet.ibm.com>
On 05/27/2014 03:41 PM, Hongliang Wang wrote:
This function was designed to substitute variables in HTML template
strings originally
so it was named as kimchi.template, and it can be used in other scenarios, e.g. we use
it when we load plugins we have a unified URL for plugin XML files:
/plugins/{plugin}/ui/config/tab-ext.xml
and after we have the plugins list, we can easily generate the corresponding URLs like
/plugins/pluginA/ui/config/tab-ext.xml,
/plugins/pluginB/ui/config/tab-ext.xml.
by list ['pluginA', 'pluginB'].
Though it is sometimes misunderstood to be related with VM templates.
Renamed it in this patch.
v1 -> v2:
2a) Configurated git to use "rename" instead of
"remove"&"create"
(Thanks to Sheldon & Zheng Sheng's help)
Signed-off-by: Hongliang Wang <hlwang(a)linux.vnet.ibm.com>
---
ui/js/src/kimchi.grid.js | 2 +-
ui/js/src/kimchi.guest_add_main.js | 2 +-
ui/js/src/kimchi.guest_edit_main.js | 4 ++--
ui/js/src/kimchi.guest_media_main.js | 2 +-
ui/js/src/kimchi.host.js | 2 +-
ui/js/src/kimchi.main.js | 2 +-
ui/js/src/kimchi.network.js | 2 +-
ui/js/src/kimchi.storage_main.js | 4 ++--
ui/js/src/kimchi.storagepool_add_main.js | 2 +-
ui/js/src/{kimchi.template.js => kimchi.substitute.js} | 2 +-
ui/js/src/kimchi.template_add_main.js | 4 ++--
ui/js/src/kimchi.template_edit_main.js | 2 +-
ui/js/src/kimchi.template_main.js | 2 +-
13 files changed, 16 insertions(+), 16 deletions(-)
rename ui/js/src/{kimchi.template.js => kimchi.substitute.js} (96%)
diff --git a/ui/js/src/kimchi.grid.js b/ui/js/src/kimchi.grid.js
index 055f487..2c70969 100644
--- a/ui/js/src/kimchi.grid.js
+++ b/ui/js/src/kimchi.grid.js
@@ -375,7 +375,7 @@ kimchi.widget.Grid.prototype = (function() {
var container = $('#' + containerID);
var gridID = this['opts']['id'];
var rowSelection = this['opts']['rowSelection'] ||
'single';
- var domNode = $(kimchi.template(htmlStr, {
+ var domNode = $(kimchi.substitute(htmlStr, {
id: gridID,
loading: i18n['KCHGRD6001M'],
message: i18n['KCHGRD6002M'],
diff --git a/ui/js/src/kimchi.guest_add_main.js b/ui/js/src/kimchi.guest_add_main.js
index 2113099..eefd59a 100644
--- a/ui/js/src/kimchi.guest_add_main.js
+++ b/ui/js/src/kimchi.guest_add_main.js
@@ -25,7 +25,7 @@ kimchi.guest_add_main = function() {
var html = '';
var tmpl = $('#tmpl-template').html();
$.each(result, function(index, value) {
- html += kimchi.template(tmpl, value);
+ html += kimchi.substitute(tmpl, value);
});
$('#templateTile').html(html);
return;
diff --git a/ui/js/src/kimchi.guest_edit_main.js b/ui/js/src/kimchi.guest_edit_main.js
index 0236e2d..90dcb32 100644
--- a/ui/js/src/kimchi.guest_edit_main.js
+++ b/ui/js/src/kimchi.guest_edit_main.js
@@ -42,7 +42,7 @@ kimchi.guest_edit_main = function() {
$.each(storages, function(index, storage) {
storage['vm'] = kimchi.selectedGuest;
rowHTML = $('#' + storage['type'] +
'-row-tmpl').html();
- var templated = kimchi.template(rowHTML, storage);
+ var templated = kimchi.substitute(rowHTML, storage);
container.append(templated);
});
@@ -96,7 +96,7 @@ kimchi.guest_edit_main = function() {
$(".action-area", item).toggleClass("hide");
};
var addItem = function(data) {
- var itemNode =
$.parseHTML(kimchi.template($('#interface-tmpl').html(),data));
+ var itemNode =
$.parseHTML(kimchi.substitute($('#interface-tmpl').html(),data));
$(".body",
"#form-guest-edit-interface").append(itemNode);
$("select", itemNode).append(networkOptions);
if(data.network!==""){
diff --git a/ui/js/src/kimchi.guest_media_main.js b/ui/js/src/kimchi.guest_media_main.js
index 02009ec..d6dee2e 100644
--- a/ui/js/src/kimchi.guest_media_main.js
+++ b/ui/js/src/kimchi.guest_media_main.js
@@ -28,7 +28,7 @@ kimchi.guest_media_main = function() {
$.each(storages, function(index, storage) {
storage['vm'] = kimchi.selectedGuest;
- var templated = kimchi.template(rowHTML, storage);
+ var templated = kimchi.substitute(rowHTML, storage);
container.append(templated);
});
diff --git a/ui/js/src/kimchi.host.js b/ui/js/src/kimchi.host.js
index 4c94fc1..ee59a7e 100644
--- a/ui/js/src/kimchi.host.js
+++ b/ui/js/src/kimchi.host.js
@@ -485,7 +485,7 @@ kimchi.host_main = function() {
data['memory'] = kimchi.formatMeasurement(data['memory'], {
fixed: 2
});
- var templated = kimchi.template(htmlTmpl, data);
+ var templated = kimchi.substitute(htmlTmpl, data);
$('#host-content-container').html(templated);
initPage();
diff --git a/ui/js/src/kimchi.main.js b/ui/js/src/kimchi.main.js
index 86fed5b..184029d 100644
--- a/ui/js/src/kimchi.main.js
+++ b/ui/js/src/kimchi.main.js
@@ -69,7 +69,7 @@ kimchi.main = function() {
var tabs = retrieveTabs(tabConfigUrl);
kimchi.listPlugins(function(plugins) {
$(plugins).each(function(i, p) {
- var url = kimchi.template(pluginConfigUrl, {
+ var url = kimchi.substitute(pluginConfigUrl, {
plugin: p
});
tabs.push.apply(tabs, retrieveTabs(url));
diff --git a/ui/js/src/kimchi.network.js b/ui/js/src/kimchi.network.js
index ca6d29b..875bc08 100644
--- a/ui/js/src/kimchi.network.js
+++ b/ui/js/src/kimchi.network.js
@@ -63,7 +63,7 @@ kimchi.getNetworkItemHtml = function(network) {
}
var disable_in_use = network.in_use ? "ui-state-disabled" :
"";
- var networkItem = kimchi.template($('#networkItem').html(), {
+ var networkItem = kimchi.substitute($('#networkItem').html(), {
name : network.name,
state : network.state,
type : network.type,
diff --git a/ui/js/src/kimchi.storage_main.js b/ui/js/src/kimchi.storage_main.js
index 6052510..1493124 100644
--- a/ui/js/src/kimchi.storage_main.js
+++ b/ui/js/src/kimchi.storage_main.js
@@ -25,7 +25,7 @@ kimchi.doListStoragePools = function() {
value.capacity = kimchi.changetoProperUnit(value.capacity,1);
value.allocated = kimchi.changetoProperUnit(value.allocated,1);
if ('kimchi-iso' !== value.type) {
- listHtml += kimchi.template(storageHtml, value);
+ listHtml += kimchi.substitute(storageHtml, value);
}
});
$('#storagepoolsList').html(listHtml);
@@ -172,7 +172,7 @@ kimchi.doListVolumes = function(poolObj) {
value.poolname = poolObj.data('name');
value.capacity = kimchi.changetoProperUnit(value.capacity,1);
value.allocation = kimchi.changetoProperUnit(value.allocation,1);
- listHtml += kimchi.template(volumeHtml, value);
+ listHtml += kimchi.substitute(volumeHtml, value);
});
volumeDiv.html(listHtml);
} else {
diff --git a/ui/js/src/kimchi.storagepool_add_main.js
b/ui/js/src/kimchi.storagepool_add_main.js
index 86dbe7f..050aa90 100644
--- a/ui/js/src/kimchi.storagepool_add_main.js
+++ b/ui/js/src/kimchi.storagepool_add_main.js
@@ -30,7 +30,7 @@ kimchi.initStorageAddPage = function() {
valid_types = ['part', 'disk', 'mpath'];
$.each(data, function(index, value) {
if (valid_types.indexOf(value.type) != -1) {
- listHtml += kimchi.template(deviceHtml, value);
+ listHtml += kimchi.substitute(deviceHtml, value);
}
});
$('.host-partition').html(listHtml);
diff --git a/ui/js/src/kimchi.template.js b/ui/js/src/kimchi.substitute.js
similarity index 96%
rename from ui/js/src/kimchi.template.js
rename to ui/js/src/kimchi.substitute.js
index 082269f..9d4dff6 100644
--- a/ui/js/src/kimchi.template.js
+++ b/ui/js/src/kimchi.substitute.js
@@ -15,7 +15,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-kimchi.template = function(templateStr, data, tag) {
+kimchi.substitute = function(templateStr, data, tag) {
tag = tag || /\{([^\}]+)\}/g;
var escapeHtml = function(html) {
diff --git a/ui/js/src/kimchi.template_add_main.js
b/ui/js/src/kimchi.template_add_main.js
index dbb3952..e9adbac 100644
--- a/ui/js/src/kimchi.template_add_main.js
+++ b/ui/js/src/kimchi.template_add_main.js
@@ -152,7 +152,7 @@ kimchi.template_add_main = function() {
volume.isoId = isoId;
volume.capacity = kimchi.changetoProperUnit(volume.capacity, 1);
kimchi.isoInfo[isoId] = volume;
- html += kimchi.template(template, volume);
+ html += kimchi.substitute(template, volume);
}
});
$('#list-local-iso').append(html);
@@ -266,7 +266,7 @@ kimchi.template_add_main = function() {
if (!kimchi.isoInfo[isoId]) {
volume.isoId = isoId;
kimchi.isoInfo[isoId] = volume;
- html += kimchi.template(template, volume);
+ html += kimchi.substitute(template, volume);
}
});
$('#list-remote-iso').html(html);
diff --git a/ui/js/src/kimchi.template_edit_main.js
b/ui/js/src/kimchi.template_edit_main.js
index 9ff8bcc..cffc685 100644
--- a/ui/js/src/kimchi.template_edit_main.js
+++ b/ui/js/src/kimchi.template_edit_main.js
@@ -87,7 +87,7 @@ kimchi.template_edit_main = function() {
var html = '';
var tmpl = $('#tmpl-network').html();
$.each(result, function(index, network) {
- html += kimchi.template(tmpl, network);
+ html += kimchi.substitute(tmpl, network);
});
$('#template-edit-network-list').html(html).show();
if(template.networks && template.networks.length > 0) {
diff --git a/ui/js/src/kimchi.template_main.js b/ui/js/src/kimchi.template_main.js
index 160ecc8..b90e3f3 100644
--- a/ui/js/src/kimchi.template_main.js
+++ b/ui/js/src/kimchi.template_main.js
@@ -22,7 +22,7 @@ kimchi.doListTemplates = function() {
var listHtml = '';
var templateHtml = $('#templateTmpl').html();
$.each(result, function(index, value) {
- listHtml += kimchi.template(templateHtml, value);
+ listHtml += kimchi.substitute(templateHtml, value);
});
$('#templateList').html(listHtml);
kimchi.templateBindClick();
--
Thanks and best regards!
Sheldon Feng(冯少合)<shaohef(a)linux.vnet.ibm.com>
IBM Linux Technology Center