No al cierre de webs
ShareCode
Permalink: http://www.treeweb.es/u/974/ 01/02/2011

ShareCode

1 var MongoString = function() {2  var that = this;3  4  this.dom = document.createElement('div');5  this.dom.setAttribute('contentEditable', true);6  this.dom.setAttribute('component', 'MongoString');7  8  this.setData = function(data) {9  that.dom.innerHTML = data; // TODO: change this by contentText10  };11  12 };13 14 var MongoNumber = function() {15  var that = this;16  17  this.dom = document.createElement('div');18  this.dom.setAttribute('contentEditable', true);19  this.dom.setAttribute('component', 'MongoNumber');20  21  this.dom.addEventListener('keyup', function(){22  console.log(""+parseFloat(this.innerHTML));23  }, true);24  25  this.setData = function(data) {26  that.dom.innerHTML = data; // TODO: change this by contentText27  };28 };29 30 var MongoBoolean = function() {31  var that = this;32  33  this.dom = document.createElement('div');34  this.dom.setAttribute('component', 'MongoBoolean');35 36  this.check = document.createElement('input');37  this.check.setAttribute('type', 'checkbox');38  this.dom.appendChild(this.check);39 40  this.setData = function(data) {41  that.check.checked = data;42  };43 };44 45 var MongoId = function() {46  var that = this;47  48  this.dom = document.createElement('div');49  this.dom.setAttribute('component', 'MongoId');50  51  this.setData = function(data) {52  that.dom.innerHTML = data; // TODO: change this by contentText53  };54 };55 56 var MongoNull = function() {57  var that = this;58  59  this.dom = document.createElement('div');60  this.dom.setAttribute('component', 'MongoNull');61  this.dom.innerHTML = 'null';62 };63 64 var MongoUndefined = function() {65  var that = this;66  67  this.dom = document.createElement('div');68  this.dom.setAttribute('component', 'MongoUndefined');69  this.dom.innerHTML = 'undefined';70 };71 72 var MongoKeyValue = function() {73  var that = this;74  75  var key = '';76  77  this.dom = document.createElement('div');78  this.dom.setAttribute('component', 'MongoKeyValue');79  80  this.key = document.createElement('div');81  this.key.classList.add('key');82  this.dom.appendChild(this.key);83  84  this.value = document.createElement('div');85  this.value.classList.add('value');86  this.dom.appendChild(this.value);87  88  this.setKey = function(k) {89  key = k;90  that.key.innerHTML = k; // TODO user contentText (check spelling)91  };92 };93 94 var MongoDocument = function() {95  96  var that = this;97  98  this.items = null;99  100  this.dom = document.createElement('div');101  this.dom.setAttribute('component', 'MongoDocument');102  103  this.setData = function(data) {104  // TODO: clear this105  for (i in data) { // TODO: change i by key106  var type = typeof data[i];107  if ('_id' == i) {108  type = 'id';109  } else if ('object' == type && data[i] instanceof Array) {110  type = 'array';111  } else if ('object' == type && null === data[i]) {112  type = 'null';113  }114  115  var mkv = new MongoKeyValue();116  mkv.setKey(i);117  118  switch (type) {119  case 'id':120  var mi = new MongoId();121  mi.setData(data[i]);122  mkv.value.appendChild(mi.dom);123  break;124  case 'undefined':125  var mu = new MongoUndefined();126  mkv.value.appendChild(mu.dom);127  break;128  case 'null':129  var mn = new MongoNull();130  mkv.value.appendChild(mn.dom);131  break;132  case 'boolean':133  var mb = new MongoBoolean();134  mb.setData(data[i]);135  mkv.value.appendChild(mb.dom);136  break;137  case 'string':138  var ms = new MongoString();139  ms.setData(data[i]);140  mkv.value.appendChild(ms.dom);141  break;142  case 'number':143  var mn = new MongoNumber();144  mn.setData(data[i]);145  mkv.value.appendChild(mn.dom);146  break;147  case 'object':148  var mo = new MongoDocument();149  mo.setData(data[i]);150  mkv.value.appendChild(mo.dom);151  break;152  case 'array':153  console.log('ocho');154  break;155  }156  157  that.dom.appendChild(mkv.dom);158  159  //that.dom.innerHTML += i + ':' + data[i] + '(' + type + ')<br>';160  }161  };162  163 };164 165 var MongoCollection = function() {166  167  var that = this;168  169  this.documents = [];170  171  this.dom = document.createElement('div');172  this.dom.setAttribute('component', 'MongoCollection');173  174  this.SetData = function(data) {175  // TODO: destroy all items176  for (i in data) {177  var d = data[i];178  var item = new MongoDocument();179  item.setData(d);180  that.dom.appendChild(item.dom);181  }182  };183  184 };
Enlace
El enlace para compartir es: