]> git.nbdom.net Git - nb.git/commitdiff
Fix this.form_submit_clean action attribute bug
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Tue, 11 Aug 2015 01:37:09 +0000 (02:37 +0100)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Tue, 11 Aug 2015 01:37:09 +0000 (02:37 +0100)
lib/js/nb.js

index 48f94bee86e0dffc2cc998b5d7f312d558d7341e..8b227793874cddb166d52e33c9bc138667c4bdf4 100644 (file)
@@ -4,39 +4,29 @@
  * Date: 28.03.15
  * See: http://www.w3schools.com/jquery/jquery_ref_selectors.asp
  */
+var nb = new NB();
 function NB() {
 
   this.form_submit_clean = function(f) {
     var i = 0;
-    var msg = '';
     var url = '';
-    msg += f.action + '\n';
+    var action = f.getAttribute('action');
+
+    //if (typeof(action) == 'undefined') action = '';
 
     for(i=0;i<f.length;i++) {
       var p = f[i];
       if (!p.name) continue;
       if (p.value=='') continue;
       if (p.value=='undefined') continue;
-      msg += p.name + '=' + p.value + '\n';
   // NB 02.09.13               url += (url ? '&' : '?') + escape(p.name) + '=' + escape(p.value);
       url += (url ? '&' : '?') + encodeURI(p.name) + '=' + encodeURI(p.value);
     }
 
-    url = f.action + url;
+    url = (action == '?' ? '' : action) + url;
 
     //document.location = url;
 
-  /*
-  if (izi_opt['test_version']) {
-    html_msg(''
-      + '<a href="#" onclick="window.location=\''+(url)+'\'; return false;">'
-      + (url)
-      + '</a>'
-    );
-    return false;
-  }
-  */
-
     //if (url == window.location) return false;
     window.location = url;
     return false;
@@ -74,7 +64,7 @@ function NB() {
       if ((xhr.readyState == 4) && (xhr.status == 200)) xhr_content = xhr.responseText;
     }
 
-    catch (e) { console.log (e) }
+    catch (e) { console.log ('NB.get_http:'+e) }
     return xhr_content;
 
   };
@@ -122,32 +112,60 @@ function NB() {
 
   };
 
-  this.json_debug = function(url) {
-    $.getJSON(url,function(data) {
-      var tag = '';
-      if (typeof(data) == 'string') {
-        tag = 'span';
-      } else if ($.isArray(data)) {
-        tag = 'ul';
-      } else {
-        tag = 'fieldset';
+  this.data2html = function(data) {
+
+    if (typeof(data) == 'string') {
+      //if (data == '') return '&nbsp;';
+      return data;
+    }
+
+    var items = [];
+
+    if ($.isArray(data)) {
+      if (!data.length) return '';
+
+      if (typeof(data[0]) == 'object') {
+        for (var i=0;i<data.length;i++) {
+          items.push( nb.data2html(data[i]) );
+        }
+        return items.join('');
       }
-      var items = [];
-      $.each( data, function( key, val ) {
-        //console.log(key+' = '+val);
-        if (tag == 'span') {
-          tag = 'span class="'+key+'"'
-          items.push( v );
-        } else if (tag == 'ul') {
-          items.push( '<li class="'+val+'">'+val+'</li>' );
-        } else if (tag == 'fieldset') {
-          items.push( '<dl class="'+key+'"><dt>'+key+'</dt><dd>'+val+'</dd>' );
+
+      for (var i=0;i<data.length;i++) {
+        if (typeof(data[i]) != 'string') {
+          //data[i] = nb.data2html(data[i]);
+          items.push( '<li>'+nb.data2html(data[i])+'</li>' );
+        } else {
+          items.push( '<li>'+data[i]+'</li>' );
         }
-      });
-      $( '<'+tag+'/>', {
-        //"class": "my-new-list",
-        html: items.join( "" )
-      }).prependTo( "#msg" );
+      }
+      return '<ul class="_test">' + items.join('') + '</ul>';
+
+    }
+
+    var key = '';
+    var val = '';
+    for (var key in data) {
+      val = data[key];
+      if (typeof(val) != 'string') { val = nb.data2html(val); }
+      //items.push( '<col class="key">' + key + '</col><col class="val">' + val + '</col>' );
+      items.push( '<dl class="_test"><dt>' + key + '</dt><dd>' + val + '</dd></dl>' );
+      //items.push( '<dt>' + key + '</dt><dd>' + val + '</dd>' );
+    }
+
+    //return '<colgroup class="_test">' + items.join('') + '</colgroup>';
+    return items.join('');
+    return '<div class="_test">' + items.join('') + '</div>';
+    return '<dl class="_test">' + items.join('') + '</dl>';
+    return '<div>' + items.join('') + '</div>';
+  }
+
+  this.json2html = function(url) {
+    $.getJSON(url,function(data) {
+      if ($.isArray(data) && data.length == 1) data = data[0];
+      var html = nb.data2html(data);
+      //console.log(nb.data2html(data));
+      if (html != '') $(html).prependTo( "#msg" );
       //console.log(typeof(data));
     });
   }