[Kimchi-devel] [PATCH 7/8] refactor exception: Update UI references

Aline Manera alinefm at linux.vnet.ibm.com
Sun Feb 9 22:48:01 UTC 2014


From: Aline Manera <alinefm at br.ibm.com>

Instead of using UI message, we can display the messages from backend as
they are also translated to the current language

Also associate a code to the UI messages and display error messages
like: <code>: <msg>
For that, create a new function kimchi.message.error.code to display
those messages.
The function kimchi.message.error will be used to display error messages came
from backend (that are already in format <code>: <msg>)

Signed-off-by: Aline Manera <alinefm at br.ibm.com>
---
 ui/js/src/kimchi.api.js                  |    4 +-
 ui/js/src/kimchi.guest_add_main.js       |    7 +-
 ui/js/src/kimchi.guest_main.js           |   32 +++---
 ui/js/src/kimchi.host.js                 |   46 ++++----
 ui/js/src/kimchi.line-chart.js           |    2 +-
 ui/js/src/kimchi.login_window.js         |    8 +-
 ui/js/src/kimchi.main.js                 |    6 +-
 ui/js/src/kimchi.message.js              |    4 +
 ui/js/src/kimchi.network.js              |   22 ++--
 ui/js/src/kimchi.report_add_main.js      |    8 +-
 ui/js/src/kimchi.storage_main.js         |   18 ++--
 ui/js/src/kimchi.storagepool_add_main.js |   28 ++---
 ui/js/src/kimchi.template_add_main.js    |   18 ++--
 ui/js/src/kimchi.template_main.js        |   16 +--
 ui/js/widgets/filter-select.js           |    4 +-
 ui/js/widgets/select-menu.js             |    4 +-
 ui/pages/i18n.html.tmpl                  |  172 ++++++++++++++----------------
 17 files changed, 194 insertions(+), 205 deletions(-)

diff --git a/ui/js/src/kimchi.api.js b/ui/js/src/kimchi.api.js
index 63ddd88..6433fe0 100644
--- a/ui/js/src/kimchi.api.js
+++ b/ui/js/src/kimchi.api.js
@@ -307,7 +307,7 @@ var kimchi = {
                 window.open(url);
             });
         }).error(function() {
-            kimchi.message.error(i18n['msg.fail.get.config']);
+            kimchi.message.error.code('KCHAPI6002E');
         });
     },
 
@@ -330,7 +330,7 @@ var kimchi = {
                 window.open(url);
             });
         }).error(function() {
-            kimchi.message.error(i18n['msg.fail.get.config']);
+            kimchi.message.error.code('KCHAPI6002E');
         });
     },
 
diff --git a/ui/js/src/kimchi.guest_add_main.js b/ui/js/src/kimchi.guest_add_main.js
index 2085562..7ada1e3 100644
--- a/ui/js/src/kimchi.guest_add_main.js
+++ b/ui/js/src/kimchi.guest_add_main.js
@@ -44,8 +44,8 @@ kimchi.guest_add_main = function() {
 
             $('#prompt-choose-template').addClass('hidden');
             $('#prompt-create-template').removeClass('hidden');
-        }, function() {
-            kimchi.message.error(i18n['temp.msg.fail.list']);
+        }, function(err) {
+            kimchi.message.error(err.responseJSON.reason);
         });
     };
 
@@ -72,8 +72,7 @@ kimchi.guest_add_main = function() {
             var reason = jqXHR &&
                 jqXHR['responseJSON'] &&
                 jqXHR['responseJSON']['reason'];
-            reason = reason ? ': ' + reason : '';
-            kimchi.message.error(i18n['vm.msg.fail.create.vm'] + reason);
+            kimchi.message.error(reason);
         });
 
         return false;
diff --git a/ui/js/src/kimchi.guest_main.js b/ui/js/src/kimchi.guest_main.js
index 8467f3f..99cb84a 100644
--- a/ui/js/src/kimchi.guest_main.js
+++ b/ui/js/src/kimchi.guest_main.js
@@ -25,8 +25,8 @@ kimchi.initVmButtonsAction = function() {
             $(this).addClass('loading');
             kimchi.startVM($(this).data('vm'), function(result) {
                 kimchi.listVmsAuto();
-            }, function() {
-                kimchi.message.error(i18n['msg.fail.start']);
+            }, function(err) {
+                kimchi.message.error(err.responseJSON.reason);
             });
         } else {
             event.preventDefault();
@@ -40,8 +40,8 @@ kimchi.initVmButtonsAction = function() {
             $(this).addClass('loading');
             kimchi.stopVM($(this).data('vm'), function(result) {
                 kimchi.listVmsAuto();
-            }, function() {
-                kimchi.message.error(i18n['msg.fail.stop']);
+            }, function(err) {
+                kimchi.message.error(err.responseJSON.reason);
             });
         } else {
             event.preventDefault();
@@ -79,14 +79,14 @@ kimchi.initVmButtonsAction = function() {
         if ('running' === $(this).data('vmstate')) {
             kimchi.resetVM($(this).data('vm'), function(result) {
                 kimchi.listVmsAuto();
-            }, function() {
-                kimchi.message.error(i18n['msg.fail.reset']);
+            }, function(err) {
+                kimchi.message.error(err.responseJSON.reason);
             });
         } else {
             kimchi.startVM($(this).data('vm'), function(result) {
                 kimchi.listVmsAuto();
-            }, function() {
-                kimchi.message.error(i18n['msg.fail.start']);
+            }, function(err) {
+                kimchi.message.error(err.responseJSON.reason);
             });
         }
     });
@@ -94,16 +94,16 @@ kimchi.initVmButtonsAction = function() {
     $(".vm-delete").on("click", function(event) {
         var vm = $(this);
         var settings = {
-            title : i18n['msg.confirm.delete.title'],
-            content : i18n['msg.vm.confirm.delete'],
-            confirm : i18n['msg.confirm.delete.confirm'],
-            cancel : i18n['msg.confirm.delete.cancel']
+            title : i18n['KCHAPI6001M'],
+            content : i18n['KCHVM6001M'],
+            confirm : i18n['KCHAPI6002M'],
+            cancel : i18n['KCHAPI6003M']
         };
         kimchi.confirm(settings, function() {
             kimchi.deleteVM(vm.data('vm'), function(result) {
                 kimchi.listVmsAuto();
-            }, function() {
-                kimchi.message.error(i18n['msg.fail.delete']);
+            }, function(err) {
+                kimchi.message.error(err.responseJSON.reason);
             });
         }, function() {
         });
@@ -214,8 +214,8 @@ kimchi.listVmsAuto = function() {
         }
 
         kimchi.vmTimeout = window.setTimeout("kimchi.listVmsAuto();", 5000);
-    }, function() {
-        kimchi.message.error(i18n['msg.fail.list.guests']);
+    }, function(err) {
+        kimchi.message.error(err.responseJSON.reason);
         kimchi.vmTimeout = window.setTimeout("kimchi.listVmsAuto();", 5000);
     });
 };
diff --git a/ui/js/src/kimchi.host.js b/ui/js/src/kimchi.host.js
index e9279fb..a5c341b 100644
--- a/ui/js/src/kimchi.host.js
+++ b/ui/js/src/kimchi.host.js
@@ -31,10 +31,10 @@ kimchi.host_main = function() {
         reportGrid = new kimchi.widget.Grid({
             container: 'available-reports-grid-container',
             id: reportGridID,
-            title: i18n['msg.host.debugreport.title'],
+            title: i18n['KCHDR6002M'],
             toolbarButtons: [{
                 id: reportGridID + '-generate-button',
-                label: i18n['msg.host.debugreport.generate'],
+                label: i18n['KCHDR6006M'],
                 onClick: function(event) {
                     kimchi.window.open('report-add.html', {
                         close: function() {
@@ -44,13 +44,13 @@ kimchi.host_main = function() {
                 }
             }, {
                 id: reportGridID + '-rename-button',
-                label: i18n['msg.host.debugreport.rename'],
+                label: i18n['KCHDR6008M'],
                 disabled: true,
                 onClick: function(event) {
                 }
             }, {
                 id: reportGridID + '-remove-button',
-                label: i18n['msg.host.debugreport.remove'],
+                label: i18n['KCHDR6009M'],
                 disabled: true,
                 onClick: function(event) {
                     var report = reportGrid.getSelected();
@@ -59,10 +59,10 @@ kimchi.host_main = function() {
                     }
 
                     var settings = {
-                        title : i18n['msg.host.debugreport.confirm.title'],
-                        content : i18n['msg.host.debugreport.confirm.content'],
-                        confirm : i18n['msg.confirm'],
-                        cancel : i18n['msg.cancel']
+                        title : i18n['KCHAPI6004M'],
+                        content : i18n['KCHDR6001M'],
+                        confirm : i18n['KCHAPI6002M'],
+                        cancel : i18n['KCHAPI6003M']
                     };
 
                     kimchi.confirm(settings, function() {
@@ -76,7 +76,7 @@ kimchi.host_main = function() {
                 }
             }, {
                 id: reportGridID + '-download-button',
-                label: i18n['msg.host.debugreport.download'],
+                label: i18n['KCHDR6010M'],
                 disabled: true,
                 onClick: function(event) {
                     var report = reportGrid.getSelected();
@@ -102,15 +102,15 @@ kimchi.host_main = function() {
             }],
             fields: [{
                 name: 'name',
-                label: i18n['msg.host.debugreport.name'],
+                label: i18n['KCHDR6003M'],
                 'class': 'debug-report-name'
             }, {
                 name: 'file',
-                label: i18n['msg.host.debugreport.file'],
+                label: i18n['KCHDR6004M'],
                 'class': 'debug-report-file'
             }, {
                 name: 'time',
-                label: i18n['msg.host.debugreport.time'],
+                label: i18n['KCHDR6005M'],
                 'class': 'debug-report-time'
             }],
             data: reports
@@ -135,10 +135,10 @@ kimchi.host_main = function() {
     var restartButtonID = '#host-button-restart';
     var shutdownHost = function(params) {
         var settings = {
-            title : i18n['msg.host.shutdown.confirm.title'],
-            content : i18n['msg.host.shutdown.confirm.content'],
-            confirm : i18n['msg.confirm'],
-            cancel : i18n['msg.cancel']
+            title : i18n['KCHAPI6004M'],
+            content : i18n['KCHHOST6008M'],
+            confirm : i18n['KCHAPI6002M'],
+            cancel : i18n['KCHAPI6003M']
         };
 
         kimchi.confirm(settings, function() {
@@ -149,7 +149,7 @@ kimchi.host_main = function() {
             kimchi.listVMs(function(vms) {
                 for(var i = 0; i < vms.length; i++) {
                     if(vms[i]['state'] === 'running') {
-                        kimchi.message.warn(i18n['msg.host.shutdown.vmrunning']);
+                        kimchi.message.error.code('KCHHOST6001E');
                         $(shutdownButtonID).prop('disabled', false);
                         $(restartButtonID).prop('disabled', false);
                         return;
@@ -220,7 +220,7 @@ kimchi.host_main = function() {
             cpu: {
                 u: {
                     type: 'percent',
-                    legend: i18n['msg.host.chartlegend.cpu'],
+                    legend: i18n['KCHHOST6002M'],
                     points: []
                 }
             },
@@ -229,7 +229,7 @@ kimchi.host_main = function() {
                     type: 'value',
                     base: 2,
                     fixed: 2,
-                    legend: i18n['msg.host.chartlegend.memory.available'],
+                    legend: i18n['KCHHOST6003M'],
                     points: []
                 }
             },
@@ -239,7 +239,7 @@ kimchi.host_main = function() {
                     base: 2,
                     fixed: 2,
                     unit: 'B/s',
-                    legend: i18n['msg.host.chartlegend.disk.read'],
+                    legend: i18n['KCHHOST6004M'],
                     points: []
                 },
                 w: {
@@ -247,7 +247,7 @@ kimchi.host_main = function() {
                     base: 2,
                     fixed: 2,
                     unit: 'B/s',
-                    legend: i18n['msg.host.chartlegend.disk.write'],
+                    legend: i18n['KCHHOST6005M'],
                     'class': 'disk-write',
                     points: []
                 }
@@ -258,7 +258,7 @@ kimchi.host_main = function() {
                     base: 2,
                     fixed: 2,
                     unit: 'B/s',
-                    legend: i18n['msg.host.chartlegend.network.received'],
+                    legend: i18n['KCHHOST6006M'],
                     points: []
                 },
                 s: {
@@ -266,7 +266,7 @@ kimchi.host_main = function() {
                     base: 2,
                     fixed: 2,
                     unit: 'B/s',
-                    legend: i18n['msg.host.chartlegend.network.sent'],
+                    legend: i18n['KCHHOST6007M'],
                     'class': 'network-sent',
                     points: []
                 }
diff --git a/ui/js/src/kimchi.line-chart.js b/ui/js/src/kimchi.line-chart.js
index 3685677..4e59cb4 100644
--- a/ui/js/src/kimchi.line-chart.js
+++ b/ui/js/src/kimchi.line-chart.js
@@ -110,7 +110,7 @@ kimchi.widget.LineChart = function(params) {
             );
         }
 
-        var maxValueLabel = i18n['msg.host.chartaxis.max'] + ' ' +
+        var maxValueLabel = i18n['KCHHOST6001M'] + ' ' +
             (type === 'value'
                 ? kimchi.formatMeasurement(maxValue, formatSettings)
                 : '100%');
diff --git a/ui/js/src/kimchi.login_window.js b/ui/js/src/kimchi.login_window.js
index 6396a1e..59de389 100644
--- a/ui/js/src/kimchi.login_window.js
+++ b/ui/js/src/kimchi.login_window.js
@@ -42,7 +42,7 @@ kimchi.login_main = function() {
         for(var i = 0; i < idsArray.length; i++) {
             var id = idsArray[i];
             if (!$('#' + id).val()) {
-                $('#' + id + '-msg').text(i18n['msg.login.requiredfield']);
+                $('#' + id + '-msg').text(i18n['KCHAUTH6002E']);
                 placeCursor(id);
                 return false;
             }
@@ -75,7 +75,7 @@ kimchi.login_main = function() {
             return false;
         }
 
-        $('#btn-login').text(i18n['msg.login.loggingin']).prop('disabled', true);
+        $('#btn-login').text(i18n['KCHAUTH6002M']).prop('disabled', true);
 
         var userID = $('#user-id').val();
         userID && kimchi.user.setUserID(userID);
@@ -95,8 +95,8 @@ kimchi.login_main = function() {
             kimchi.user.showUser(true);
             kimchi.window.close();
         }, function() {
-            $('#message-container').text(i18n['msg.login.failed']);
-            $('#btn-login').prop('disabled', false).text(i18n['msg.login.login']);
+            $('#message-container').text(i18n['KCHAUTH6001E']);
+            $('#btn-login').prop('disabled', false).text(i18n['KCHAUTH6001M']);
             placeCursor('user-id');
         });
 
diff --git a/ui/js/src/kimchi.main.js b/ui/js/src/kimchi.main.js
index cc8afee..5387495 100644
--- a/ui/js/src/kimchi.main.js
+++ b/ui/js/src/kimchi.main.js
@@ -46,7 +46,7 @@ kimchi.main = function() {
          */
         var tab = $('#nav-menu a[href="' + url + '"]');
         if (tab.length === 0) {
-            kimchi.message.error(i18n['msg.err.uri.invalid']);
+            kimchi.message.error.code('KCHAPI6001E');
             location.hash = '';
             return;
         }
@@ -138,8 +138,8 @@ kimchi.main = function() {
         $('#btn-logout').on('click', function() {
             kimchi.logout(function() {
                 updatePage();
-            }, function() {
-                kimchi.message.error(i18n['msg.logout.failed']);
+            }, function(err) {
+                kimchi.message.error(err.responseJSON.reason);
             });
         });
     };
diff --git a/ui/js/src/kimchi.message.js b/ui/js/src/kimchi.message.js
index 770f999..844febc 100644
--- a/ui/js/src/kimchi.message.js
+++ b/ui/js/src/kimchi.message.js
@@ -107,6 +107,10 @@ kimchi.message.warn = function(msg) {
 kimchi.message.error = function(msg) {
     kimchi.message(msg, 'error');
 };
+kimchi.message.error.code = function(code) {
+    msg = code + ": " + i18n[code]
+    kimchi.message(msg, 'error');
+};
 kimchi.message.success = function(msg) {
     kimchi.message(msg, 'success');
 };
diff --git a/ui/js/src/kimchi.network.js b/ui/js/src/kimchi.network.js
index 0a3026f..c1f87ce 100644
--- a/ui/js/src/kimchi.network.js
+++ b/ui/js/src/kimchi.network.js
@@ -54,10 +54,10 @@ kimchi.addNetworkItem = function(network) {
 
 kimchi.getNetworkItemHtml = function(network) {
     if(!network.interface) {
-        network.interface = i18n["value_unavailable"];
+        network.interface = i18n["KCHNET6001M"];
     }
     if(!network.addrSpace) {
-        network.addrSpace = i18n["value_unavailable"];
+        network.addrSpace = i18n["KCHNET6001M"];
     }
     if(i18n["network_type_" + network.type]) {
         network.type = i18n["network_type_" + network.type];
@@ -104,10 +104,10 @@ kimchi.addNetworkActions = function(network) {
                 });
             } else if ($(evt.currentTarget).attr("nwAct") === "delete") {
                 kimchi.confirm({
-                    title : i18n['msg_warning'],
-                    content : i18n['network_action_confirm'],
-                    confirm : i18n['msg.confirm.delete.confirm'],
-                    cancel : i18n['msg.confirm.delete.cancel']
+                    title : i18n['KCHAPI6006M'],
+                    content : i18n['KCHNET6002M'],
+                    confirm : i18n['KCHAPI6002M'],
+                    cancel : i18n['KCHAPI6003M']
                 }, function() {
                     kimchi.deleteNetwork(network.name, function() {
                         $(evt.currentTarget).parents(".item").remove();
@@ -143,15 +143,15 @@ kimchi.initNetworkCreation = function() {
                 if ($("#enableVlan").prop("checked")) {
                     data.vlan_id = network.vlan_id;
                     if (!(data.vlan_id >=1 && data.vlan_id <= 4094)) {
-                        kimchi.message.error(i18n['msg.invalid.vlan_id']);
+                        kimchi.message.error.code('KCHNET6001E');
                         return;
                     }
                 }
             }
             kimchi.createNetwork(data, function(result) {
                 network.state = result.state === "active" ? "up" : "down";
-                network.interface = result.interface ? result.interface : i18n["value_unavailable"];
-                network.addrSpace = result.subnet ? result.subnet : i18n["value_unavailable"];
+                network.interface = result.interface ? result.interface : i18n["KCHNET6001M"];
+                network.addrSpace = result.subnet ? result.subnet : i18n["KCHNET6001M"];
                 kimchi.addNetworkItem(network);
                 $("#networkConfig").dialog("close");
             });
@@ -176,7 +176,7 @@ kimchi.initNetworkDialog = function() {
         },
         buttons : [ {
             id : "networkFormOk",
-            text : i18n.action_create,
+            text : i18n.KCHAPI6005M,
             class: "ui-button-primary",
             disabled: true,
             click : function() {
@@ -196,7 +196,7 @@ kimchi.openNetworkDialog = function(okCallback) {
         kimchi.setDefaultNetworkType(result.length!==0);
     });
     $("#networkConfig").dialog({
-        title : i18n.network_dialog_title_create
+        title : i18n.KCHNET6003M
     });
     $("#networkFormOk").on("click", function() {
         okCallback();
diff --git a/ui/js/src/kimchi.report_add_main.js b/ui/js/src/kimchi.report_add_main.js
index 9826c38..f893d85 100644
--- a/ui/js/src/kimchi.report_add_main.js
+++ b/ui/js/src/kimchi.report_add_main.js
@@ -16,7 +16,7 @@ kimchi.report_add_main = function() {
         var formData = addReportForm.serializeObject();
         errorMessage.text('');
         submitButton
-            .text(i18n['msg.host.debugreport.generating'])
+            .text(i18n['KCHDR6007M'])
             .prop('disabled', true);
         nameTextbox.prop('disabled', true);
         kimchi.createReport(formData, function(result) {
@@ -25,10 +25,10 @@ kimchi.report_add_main = function() {
                 result: result
             });
         }, function(result) {
-            result && result['message'] &&
-                $('#report-error-message').text(result['message']);
+            result && result['reason'] &&
+                $('#report-error-message').text(result['reason']);
             submitButton
-                .text(i18n['msg.host.debugreport.generate'])
+                .text(i18n['KCHDR6006M'])
                 .prop('disabled', false);
             nameTextbox.prop('disabled', false).focus();
         });
diff --git a/ui/js/src/kimchi.storage_main.js b/ui/js/src/kimchi.storage_main.js
index 5605f4b..d65da0b 100644
--- a/ui/js/src/kimchi.storage_main.js
+++ b/ui/js/src/kimchi.storage_main.js
@@ -36,8 +36,8 @@ kimchi.doListStoragePools = function() {
         } else {
             $('#storagepoolsList').html('');
         }
-    }, function() {
-        kimchi.message.error(i18n['kimchi.list.storage.fail.msg']);
+    }, function(err) {
+        kimchi.message.error(err.responseJSON.reason);
     });
 
 }
@@ -79,10 +79,10 @@ kimchi.storageBindClick = function() {
     $('.pool-delete').on('click', function(event) {
         var $pool = $(this);
         var settings = {
-            title : i18n['msg.confirm.delete.title'],
-            content : i18n['msg.storagepool.confirm.delete'],
-            confirm : i18n['msg.confirm.delete.confirm'],
-            cancel : i18n['msg.confirm.delete.cancel']
+            title : i18n['KCHAPI6001M'],
+            content : i18n['KCHPOOL6001M'],
+            confirm : i18n['KCHAPI6002M'],
+            cancel : i18n['KCHAPI6003M']
         };
         kimchi.confirm(settings, function() {
             var poolName = $pool.data('name');
@@ -159,14 +159,14 @@ kimchi.doListVolumes = function(poolObj) {
                 });
                 volumeDiv.html(listHtml);
             } else {
-                volumeDiv.html("<div class='pool-empty'>" + i18n['msg.kimchi.storage.pool.empty'] + "</div>");
+                volumeDiv.html("<div class='pool-empty'>" + i18n['KCHPOOL6002M'] + "</div>");
             }
             poolObj.removeClass('in');
             kimchi.changeArrow(handleArrow);
             slide.slideDown('slow');
         }
-    }, function() {
-        kimchi.message.error(i18n['msg.kimchi.list.volume.fail']);
+    }, function(err) {
+        kimchi.message.error(err.responseJSON.reason);
     });
 }
 
diff --git a/ui/js/src/kimchi.storagepool_add_main.js b/ui/js/src/kimchi.storagepool_add_main.js
index e5922b3..ac97e1a 100644
--- a/ui/js/src/kimchi.storagepool_add_main.js
+++ b/ui/js/src/kimchi.storagepool_add_main.js
@@ -141,11 +141,11 @@ kimchi.validateForm = function() {
     var name = $('#poolId').val();
     var poolType = $("#poolTypeInputId").val();
     if ('' === name) {
-        kimchi.message.error(i18n['msg.pool.edit.name.blank']);
+        kimchi.message.error.code('KCHPOOL6001E');
         return false;
     }
     if (!/^[\w-]+$/.test(name)) {
-        kimchi.message.error(i18n['msg.validate.pool.edit.name']);
+        kimchi.message.error.code('KCHPOOL6004E');
         return false;
     }
     if (poolType === "dir") {
@@ -164,11 +164,11 @@ kimchi.validateForm = function() {
 kimchi.validateDirForm = function () {
     var path = $('#pathId').val();
     if ('' === path) {
-        kimchi.message.error(i18n['msg.pool.edit.path.blank']);
+        kimchi.message.error.code('KCHPOOL6002E');
         return false;
     }
     if (!/((\/([0-9a-zA-Z-_\.]+)))$/.test(path)) {
-        kimchi.message.error(i18n['msg.validate.pool.edit.path']);
+        kimchi.message.error.code('KCHAPI6003E');
         return false;
     }
     return true;
@@ -181,11 +181,11 @@ kimchi.validateNfsForm = function () {
         return false;
     }
     if ('' === nfspath) {
-        kimchi.message.error(i18n['msg.pool.edit.nfspath.blank']);
+        kimchi.message.error.code('KCHPOOL6003E');
         return false;
     }
     if (!/((\/([0-9a-zA-Z-_\.]+)))$/.test(nfspath)) {
-        kimchi.message.error(i18n['msg.validate.pool.edit.nfspath']);
+        kimchi.message.error.code('KCHPOOL6005E');
         return false;
     }
     return true;
@@ -198,7 +198,7 @@ kimchi.validateIscsiForm = function() {
         return false;
     }
     if ('' === iscsiTarget) {
-        kimchi.message.error(i18n['msg.pool.edit.iscsitarget.blank']);
+        kimchi.message.error.code('KCHPOOL6007E');
         return false;
     }
     return true;
@@ -206,11 +206,11 @@ kimchi.validateIscsiForm = function() {
 
 kimchi.validateServer = function(serverField) {
     if ('' === serverField) {
-        kimchi.message.error(i18n['msg.pool.edit.server.blank']);
+        kimchi.message.error.code('KCHPOOL6008E');
         return false;
     }
     if(!kimchi.isServer(serverField)) {
-        kimchi.message.error(i18n['msg.validate.pool.edit.server']);
+        kimchi.message.error.code('KCHPOOL6009E');
         return false;
     }
     return true;
@@ -218,7 +218,7 @@ kimchi.validateServer = function(serverField) {
 
 kimchi.validateLogicalForm = function () {
     if ($("input[name=devices]:checked").length === 0) {
-        kimchi.message.error(i18n['msg.validate.pool.edit.logical.device']);
+        kimchi.message.error.code('KCHPOOL6006E');
         return false;
     } else {
         return true;
@@ -263,10 +263,10 @@ kimchi.addPool = function(event) {
         }
         if (poolType === 'logical') {
             var settings = {
-                title : i18n['msg.confirm.delete.title'],
-                content : i18n['msg.logicalpool.confirm.delete'],
-                confirm : i18n['msg.confirm.delete.confirm'],
-                cancel : i18n['msg.confirm.delete.cancel']
+                title : i18n['KCHAPI6001M'],
+                content : i18n['KCHPOOL6003M'],
+                confirm : i18n['KCHAPI6002M'],
+                cancel : i18n['KCHAPI6003M']
             };
             kimchi.confirm(settings, function() {
                 kimchi.createStoragePool(formData, function() {
diff --git a/ui/js/src/kimchi.template_add_main.js b/ui/js/src/kimchi.template_add_main.js
index 85e73a2..1b1f413 100644
--- a/ui/js/src/kimchi.template_add_main.js
+++ b/ui/js/src/kimchi.template_add_main.js
@@ -72,7 +72,7 @@ kimchi.template_add_main = function() {
 
     $('#iso-search').click(function() {
         var settings = {
-            content : i18n['msg.template.iso.search.confirm']
+            content : i18n['KCHTMPL6002M']
         };
         kimchi.confirm(settings, function() {
             $('#iso-search').hide();
@@ -83,7 +83,7 @@ kimchi.template_add_main = function() {
 
     $('#iso-more').click(function() {
         var settings = {
-            content : i18n['msg.template.iso.search.confirm']
+            content : i18n['KCHTMPL6002M']
         };
         kimchi.confirm(settings, function() {
             $('#iso-more').hide();
@@ -119,7 +119,7 @@ kimchi.template_add_main = function() {
                 showLocalIsoField(isos);
             } else {
                 if (isFinished) {
-                    kimchi.message.warn(i18n['msg.fail.template.no.iso']);
+                    kimchi.message.warn(i18n['KCHTMPL6001W']);
                 }
             }
             if (isFinished) {
@@ -214,11 +214,11 @@ kimchi.template_add_main = function() {
     $('#btn-template-file-create').click(function() {
         var isoFile = $('#iso-file').val();
         if (!kimchi.is_iso_file(isoFile)) {
-            kimchi.message.error(i18n['msg.invalid.iso']);
+            kimchi.message.error.code('KCHTMPL6002E');
             return;
         }        
         if (!kimchi.template_check_path(isoFile)) {
-            kimchi.message.error(i18n['msg.invalid.path']);
+            kimchi.message.error.code('KCHAPI6003E');
             return;
         }
         var data = {
@@ -274,7 +274,7 @@ kimchi.template_add_main = function() {
             $('#list-remote-iso').html(html);
             $('#remote-iso-field').show();
         } else {
-            kimchi.message.warn(i18n['msg.fail.template.no.iso']);
+            kimchi.message.warn(i18n['KCHTMPL6001W']);
         }
     };
 
@@ -330,7 +330,7 @@ kimchi.template_add_main = function() {
     $('#btn-template-url-create').click(function() {
         var isoUrl = $('#iso-url').val();
         if (!kimchi.template_check_url(isoUrl)) {
-            kimchi.message.error(i18n['msg.invalid.url']);
+            kimchi.message.error.code('KCHAPI6004E');
             return;
         }
         var data = {
@@ -365,7 +365,7 @@ kimchi.template_add_main = function() {
                 };
                 kimchi.createTemplate(data, function() {
                     successNum++;
-                    kimchi.message.success(i18n['msg.success.create.template'] + ': ' + isoInfo.name);
+                    kimchi.message.success(i18n['KCHTMPL6001M'] + ': ' + isoInfo.name);
                     $('input[value="' + isoInfo.isoId + '"]').prop('checked', false);
                     $('.check-all>input').prop('checked', false);
                     kimchi.doListTemplates();
@@ -374,7 +374,7 @@ kimchi.template_add_main = function() {
                         kimchi.window.close();
                     }
                 }, function(err) {
-                    kimchi.message.error(i18n['msg.fail.create.template'] + ': ' + isoInfo.name + '<br>' + err.responseJSON.reason);
+                    kimchi.message.error(err.responseJSON.reason);
                 });
             };
             if (formData.iso instanceof Array) {
diff --git a/ui/js/src/kimchi.template_main.js b/ui/js/src/kimchi.template_main.js
index ffc7306..0904e71 100644
--- a/ui/js/src/kimchi.template_main.js
+++ b/ui/js/src/kimchi.template_main.js
@@ -33,8 +33,8 @@ kimchi.doListTemplates = function() {
             $('#templateList').html('');
             $('#noTemplates').show();
         }
-    }, function() {
-        kimchi.message.error(i18n['kimchi.list.template.fail.msg']);
+    }, function(err) {
+        kimchi.message.error(err.responseJSON.reason);
     });
 };
 
@@ -47,17 +47,17 @@ kimchi.bindClick = function() {
     $('.template-delete').on('click', function(event) {
         var $template = $(this);
         var settings = {
-            title : i18n['msg.confirm.delete.title'],
-            content : i18n['msg.template.confirm.delete'],
-            confirm : i18n['msg.confirm.delete.confirm'],
-            cancel : i18n['msg.confirm.delete.cancel']
+            title : i18n['KCHAPI6001M'],
+            content : i18n['KCHTMPL6001M'],
+            confirm : i18n['KCHAPI6002M'],
+            cancel : i18n['KCHAPI6003M']
         };
         kimchi.confirm(settings, function() {
             var templateName = $template.data('template');
             kimchi.deleteTemplate(templateName, function() {
                 kimchi.doListTemplates();
-            }, function() {
-                kimchi.message.error(i18n['fail.delete.template']);
+            }, function(err) {
+                kimchi.message.error(err.responseJSON.reason);
             });
         }, function() {
         });
diff --git a/ui/js/widgets/filter-select.js b/ui/js/widgets/filter-select.js
index 44030a1..9e024cf 100644
--- a/ui/js/widgets/filter-select.js
+++ b/ui/js/widgets/filter-select.js
@@ -55,7 +55,7 @@
                     that.listControl.html('');
                     var items = that._dataList(options);
                     if (items.length === 0) {
-                        that.listControl.html(i18n['msg.no.mapping.result']);
+                        that.listControl.html(i18n['KCHAPI6005E']);
                     } else {
                         $.each(items, function(index, item) {
                             that.listControl.append(item);
@@ -75,7 +75,7 @@
                     });
                     if (that.listControl.html() === '') {
                         that.target.addClass("invalid-field");
-                        that.listControl.html(i18n['msg.no.mapping.result']);
+                        that.listControl.html(i18n['KCHAPI6005E']);
                     } else {
                         that.target.removeClass("invalid-field");
                     }
diff --git a/ui/js/widgets/select-menu.js b/ui/js/widgets/select-menu.js
index c9a1b87..c213f3c 100644
--- a/ui/js/widgets/select-menu.js
+++ b/ui/js/widgets/select-menu.js
@@ -62,7 +62,7 @@
                     }
                 });
             } else {
-                kimchi.message.error(i18n['selectmenu.data.error']);
+                kimchi.message.code.error('KCHAPI6006E');
             }
         },
 
@@ -83,4 +83,4 @@
             $.Widget.prototype.destroy.call(this);
         }
     });
-}(jQuery));
\ No newline at end of file
+}(jQuery));
diff --git a/ui/pages/i18n.html.tmpl b/ui/pages/i18n.html.tmpl
index d63d4e9..540c07c 100644
--- a/ui/pages/i18n.html.tmpl
+++ b/ui/pages/i18n.html.tmpl
@@ -36,99 +36,85 @@
 <body>
 <script>
 var i18n = {
-    'temp.msg.fail.list': "$_("Failed to list the template")",
-    'temp.msg.choose.temp': "$_("Please choose a template")",
-    'vm.msg.fail.create.vm': "$_("Failed to create vm")",
-    'msg.login.failed': "$_("The username or password you entered is incorrect. Please try again.")",
-    'msg.login.requiredfield': "$_("This field is required.")",
-    'msg.login.login': "$_("Log in")",
-    'msg.login.loggingin': "$_("Logging in...")",
-    'msg.err.uri.invalid': "$_("Invalid URL. Redireced to home page.")",
-    'msg.404.gotohomepage': "$_("Go to Homepage")",
-    'msg.fail.start': "$_("Failed to start")",
-    'msg.fail.stop': "$_("Failed to stop")",
-    'msg.fail.reset': "$_("Failed to reset")",
-    'msg.fail.delete': "$_("Failed to delete")",
-    'msg.fail.list.guests': "$_("Failed to list guests")",
-    'msg.fail.create.template': "$_("Failed to create template")",
-    'msg.success.create.template': "$_("Create template successfully")",
-    'msg.fail.template.no.iso': "$_("No iso found")",
-    'msg.fail.template.scan': "$_("Failed to scan")",
-    'msg.fail.template.distr': "$_("Failed to list iso distributions")",
-    'msg.confirm.delete.title': "$_("Delete Confirmation")",
-    'msg.confirm': "$_("OK")",
-    'msg.cancel': "$_("Cancel")",
-    'msg.confirm.delete.confirm': "$_("OK")",
-    'msg.confirm.delete.cancel': "$_("Cancel")",
-    'msg.host.chartaxis.max': "$_("Max:")",
-    'msg.host.chartlegend.cpu': "$_("Utilization")",
-    'msg.host.chartlegend.memory.available': "$_("Available")",
-    'msg.host.chartlegend.disk.read': "$_("Read Rate")",
-    'msg.host.chartlegend.disk.write': "$_("Write Rate")",
-    'msg.host.chartlegend.network.received': "$_("Received")",
-    'msg.host.chartlegend.network.sent': "$_("Sent")",
-    'msg.host.debugreport.confirm.title': "$_("Confirm")",
-    'msg.host.debugreport.confirm.content': "$_("Debug report will be removed permanently and can't be recovered. Do you want to continue?")",
-    'msg.host.debugreport.title': "$_("Debug Reports")",
-    'msg.host.debugreport.name': "$_("Name")",
-    'msg.host.debugreport.file': "$_("File Path")",
-    'msg.host.debugreport.time': "$_("Generated Time")",
-    'msg.host.debugreport.generate': "$_("Generate")",
-    'msg.host.debugreport.generating': "$_("Generating...")",
-    'msg.host.debugreport.rename': "$_("Rename")",
-    'msg.host.debugreport.remove': "$_("Remove")",
-    'msg.host.debugreport.download': "$_("Download")",
-    'msg.host.shutdown.vmrunning': "$_("Some VM(s) are running!")",
-    'msg.host.shutdown.confirm.title': "$_("Confirm")",
-    'msg.host.shutdown.confirm.content': "$_("Shutting down or restarting host will cause unsaved work lost. Continue to shut down/restarting?")",
-    'msg.vm.confirm.delete': "$_("This will delete the VM and its virtual disks. "
-                                 "This operation cannot be undone. "
-                                 "Would you like to continue?")",
-    'msg.template.confirm.delete': "$_("This will permanently delete the Template. "
-                                       "Would you like to continue?")",
-    'msg.template.iso.search.confirm': "It will take long time. Do you want to continue?",
-    'msg.fail.get.config': "$_("Failed to get application configuration")",
-    'msg.invalid.path': "$_("This is not a valid linux path")",
-    'msg.invalid.url': "$_("This is not a valid url.")",
-    'msg.invalid.vlan_id': "$_("The VLAN id must be between 1 and 4094.")",
-    'msg.invalid.iso': "$_("This is not a valid ISO file.")",
-    'msg.storagepool.confirm.delete':"$_("This will permanently delete the Storage Pool. Would you like to continue?")",
-    'msg.pool.edit.name.blank':"$_("The storage pool name can not be blank.")",
-    'msg.pool.edit.path.blank':"$_("The storage pool path can not be blank.")",
-    'msg.pool.edit.nfspath.blank':"$_("NFS server mount path can not be blank.")",
-    'msg.validate.pool.edit.name':"$_("Invalid Storage Pool name.  It may only contain letters, numbers, underscores, and hyphens.")",
-    'msg.validate.pool.edit.path':"$_("This is not a real linux path.")",
-    'msg.validate.pool.edit.nfspath':"$_("Invalid nfs mount path.")",
-    'msg.validate.pool.edit.logical.device':"$_("No logical device selected.")",
-    'msg.kimchi.storage.pool.empty':"$_("This storage pool is empty.")",
-    'msg.kimchi.list.volume.fail':"$_("Failed to list the storage pool.")",
-    'msg.kimchi.storage.pool.not.active':"$_("The storage pool is not active now.")",
-    'fail.delete.template': "$_("Failed to delete template.")",
-    'Guests':"$_("Guests")",
-    'Host':"$_("Host")",
-    'Templates':"$_("Templates")",
-    'Storage':"$_("Storage")",
-    'value_unavailable': "$_("unavailable")",
-    'Network':"$_("Network")",
-    'network_type_isolated': "$_("isolated")",
-    'network_type_nat': "$_("NAT")",
-    'network_type_bridged': "$_("bridged")",
-    'network_bridged_space': "$_("connected to")",
-    'network_action_confirm': "$_("This action will interrupt network connectivity for any virtual machine that depend on this network.")",
-    'network_dialog_title_create': "$_("Create a network")",
-    'network_dialog_ok': "$_("OK")",
-    'network_dialog_cancel': "$_("Cancel")",
-    'action_create': "$_("Create")",
-    'msg_warning': "$_("Warning")",
-    'msg.logicalpool.confirm.delete': "$_("It will format your disk and you will loose any data in"
-                                      " there, are you sure to continue? ")",
-    'msg.pool.edit.iscsitarget.blank': "$_("The iSCSI target can not be blank.")",
-    'msg.pool.edit.server.blank':"$_("Server name can not be blank.")",
-    'msg.validate.pool.edit.server':"$_("This is not a valid Server Name or IP. please, modify it.")",
-    'select_default': "$_("Please choose")",
-    'msg.no.mapping.result': "$_("No such data exsit.")",
-    'msg.no.result' : "$_("No valid result")",
-    'selectmenu.data.error' : "$_("options needed.")"
+    'KCHAUTH6001E': "$_("The username or password you entered is incorrect. Please try again.")",
+    'KCHAUTH6002E': "$_("This field is required.")",
+
+    'KCHAUTH6001M': "$_("Log in")",
+    'KCHAUTH6002M': "$_("Logging in...")",
+
+    'Host': "$_("Host")",
+    'Guests': "$_("Guests")",
+    'Templates': "$_("Templates")",
+    'Storage': "$_("Storage")",
+    'Network': "$_("Network")",
+
+    'KCHAPI6001E': "$_("Invalid URL. Redireced to home page.")",
+    'KCHAPI6002E': "$_("Failed to get application configuration")",
+    'KCHAPI6003E': "$_("This is not a valid linux path")",
+    'KCHAPI6004E': "$_("This is not a valid url.")",
+    'KCHAPI6005E': "$_("No such data exsit.")",
+    'KCHAPI6006E': "$_("options needed.")",
+
+    'KCHAPI6001M': "$_("Delete Confirmation")",
+    'KCHAPI6002M': "$_("OK")",
+    'KCHAPI6003M': "$_("Cancel")",
+    'KCHAPI6004M': "$_("Confirm")",
+    'KCHAPI6005M': "$_("Create")",
+    'KCHAPI6006M': "$_("Warning")",
+
+    'KCHTMPL6001M': "$_("Create template successfully")",
+
+    'KCHTMPL6001W': "$_("No iso found")",
+
+    'KCHTMPL6002E': "$_("This is not a valid ISO file.")",
+
+    'KCHTMPL6001M': "$_("This will permanently delete the Template. Would you like to continue?")",
+    'KCHTMPL6002M': "$_("It will take long time. Do you want to continue?")",
+
+    'KCHHOST6001E': "$_("Unable to shut down system as there are some VM(s) running!")",
+
+    'KCHHOST6001M': "$_("Max:")",
+    'KCHHOST6002M': "$_("Utilization")",
+    'KCHHOST6003M': "$_("Available")",
+    'KCHHOST6004M': "$_("Read Rate")",
+    'KCHHOST6005M': "$_("Write Rate")",
+    'KCHHOST6006M': "$_("Received")",
+    'KCHHOST6007M': "$_("Sent")",
+    'KCHHOST6008M': "$_("Shutting down or restarting host will cause unsaved work lost. Continue to shut down/restarting?")",
+
+    'KCHDR6001M': "$_("Debug report will be removed permanently and can't be recovered. Do you want to continue?")",
+    'KCHDR6002M': "$_("Debug Reports")",
+    'KCHDR6003M': "$_("Name")",
+    'KCHDR6004M': "$_("File Path")",
+    'KCHDR6005M': "$_("Generated Time")",
+    'KCHDR6006M': "$_("Generate")",
+    'KCHDR6007M': "$_("Generating...")",
+    'KCHDR6008M': "$_("Rename")",
+    'KCHDR6009M': "$_("Remove")",
+    'KCHDR6010M': "$_("Download")",
+
+
+    'KCHVM6001M': "$_("This will delete the VM and its virtual disks. This operation cannot be undone. Would you like to continue?")",
+
+    'KCHNET6001E': "$_("The VLAN id must be between 1 and 4094.")",
+
+    'KCHNET6001M': "$_("unavailable")",
+    'KCHNET6002M': "$_("This action will interrupt network connectivity for any virtual machine that depend on this network.")",
+    'KCHNET6003M': "$_("Create a network")",
+
+    'KCHPOOL6001M': "$_("This will permanently delete the Storage Pool. Would you like to continue?")",
+    'KCHPOOL6002M': "$_("This storage pool is empty.")",
+    'KCHPOOL6003M': "$_("It will format your disk and you will loose any data in there, are you sure to continue? ")",
+
+    'KCHPOOL6001E': "$_("The Storage Pool name can not be blank.")",
+    'KCHPOOL6002E': "$_("The Storage Pool path can not be blank.")",
+    'KCHPOOL6003E': "$_("NFS server mount path can not be blank.")",
+    'KCHPOOL6004E': "$_("Invalid Storage Pool name. It may only contain letters, numbers, underscores, and hyphens.")",
+    'KCHPOOL6005E': "$_("Invalid NFS mount path.")",
+    'KCHPOOL6006E': "$_("No logical device selected.")",
+    'KCHPOOL6007E': "$_("The iSCSI target can not be blank.")",
+    'KCHPOOL6008E': "$_("Server name can not be blank.")",
+    'KCHPOOL6009E': "$_("This is not a valid Server Name or IP. please, modify it.")"
 };
 </script>
 </body>
-- 
1.7.10.4




More information about the Kimchi-devel mailing list