[Kimchi-devel] [PATCH v3 1/5] [UI] kimchi.message - Enhancement

Hongliang Wang hlwang at linux.vnet.ibm.com
Wed Mar 5 07:23:54 UTC 2014


Sometimes we want to show the message at a specific position, other
than at the top of the browser.

  In this patch, we introduced a new parameter to the function with
which we can place the message wherever we want.

Signed-off-by: Hongliang Wang <hlwang at linux.vnet.ibm.com>
---
 ui/js/src/kimchi.message.js | 27 +++++++++++++++------------
 1 file changed, 15 insertions(+), 12 deletions(-)

diff --git a/ui/js/src/kimchi.message.js b/ui/js/src/kimchi.message.js
index f997a73..35e3db9 100644
--- a/ui/js/src/kimchi.message.js
+++ b/ui/js/src/kimchi.message.js
@@ -15,16 +15,19 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-kimchi.message = function(msg, level) {
-    if ($('#messageField').size() < 1) {
-        $(document.body).append('<div id="messageField"></div>');
+kimchi.message = function(msg, level, node) {
+    var container = node || $('#messageField');
+    if ($(container).size() < 1) {
+        container = $('<div id="messageField"/>').appendTo(document.body);
     }
     var message = '<div class="message ' + (level || '') + '" style="display: none;">';
-    message += '<div class="close">X</div>';
+    if(!node) {
+        message += '<div class="close">X</div>';
+    }
     message += '<div class="content">' + msg + '</div>';
     message += '</div>';
     var $message = $(message);
-    $('#messageField').append($message);
+    $(container).append($message);
     $message.fadeIn(100);
 
     setTimeout(function() {
@@ -33,7 +36,7 @@ kimchi.message = function(msg, level) {
         });
     }, 4000);
 
-    $('#messageField').on("click", ".close", function(e) {
+    $(container).on("click", ".close", function(e) {
         $(this).parent().fadeOut(200, function() {
             $(this).remove();
         });
@@ -98,16 +101,16 @@ kimchi.confirm = function(settings, confirmCallback, cancelCallback) {
     });
 };
 
-kimchi.message.warn = function(msg) {
-    kimchi.message(msg, 'warn');
+kimchi.message.warn = function(msg, node) {
+    kimchi.message(msg, 'warn', node);
 };
-kimchi.message.error = function(msg) {
-    kimchi.message(msg, 'error');
+kimchi.message.error = function(msg, node) {
+    kimchi.message(msg, 'error', node);
 };
 kimchi.message.error.code = function(code) {
     msg = code + ": " + i18n[code]
     kimchi.message(msg, 'error');
 };
-kimchi.message.success = function(msg) {
-    kimchi.message(msg, 'success');
+kimchi.message.success = function(msg, node) {
+    kimchi.message(msg, 'success', node);
 };
-- 
1.8.1.4




More information about the Kimchi-devel mailing list