//Polyfilling if (!String.prototype.trim) { //https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/Trim String.prototype.trim = function () { return this.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, ''); }; } if (!Array.prototype.swap) { Array.prototype.swap = function(a,b){ //don't attempt to swap if indexes invalid if(Math.min(a,b)<0 || Math.max(a,b)>=this.length) return this; //indexes are valid, then swap var tmp = this[a]; this[a] = this[b]; this[b] = tmp; return this; } } if (!Array.prototype.remove) { Array.prototype.remove = function(a){ //don't attempt to swap if index is invalid if(a<0 || a>=this.length) return undefined; //index is valid, then remove return this.splice(a, 1)[0]; } } if (!Array.prototype.contains) { Array.prototype.contains = function(a){ var ret = false this.forEach(function(elem){ if(elem===a) ret = true; }); return ret; } } if (!String.prototype.escapeHtml) { // http://stackoverflow.com/a/6234804 String.prototype.escapeHtml = function () { return this .replace(/&/g, "&") .replace(//g, ">") .replace(/"/g, """) .replace(/'/g, "'"); }; } // End of Polyfilling function escapeHtml(unsafe){ // http://stackoverflow.com/a/6234804 return unsafe .replace(/&/g, "&") .replace(//g, ">") .replace(/"/g, """) .replace(/'/g, "'"); } function ensureArray(variable){ if( variable !== null && typeof(variable) === "object" && ( variable.constructor === Array || ( variable.prop && variable.prop.constructor === Array ) ) ) return variable; else return new Array(); } var pedidos = []; var pedidoCache = {}; function viewUpdate(apiid){ var v = ''; if(typeof(apiid)!=='number'){ v+='

< Voltar

'; v+=''; v+=''; v+=''; v+=''; v+=''; v+=''; v+=''; v+=''; v+=''; ensureArray(pedidos).forEach(function(pedido){ v+=''; v+=''; v+=''; v+=''; v+=''; }); v+=''; v+='
Número do pedidoClienteVisualizar
'+(pedido.noped.escapeHtml())+''+(pedido.cliente.escapeHtml())+'Visualizar
'; }else{ if(typeof(pedidoCache[apiid])==='undefined'){ jQuery.get( restApi, { 'pedido':apiid, }, function(data, textStatus, jqXHR){ pedidoCache[apiid] = data; viewUpdate(apiid); }, 'json' ); return }else{ var pedido = pedidoCache[apiid]; v+='

< Voltar

'; v+='

Número do pedido: '+pedido.noped.escapeHtml()+'

'; v+='

Cliente: '+pedido.cliente.escapeHtml()+'

'; v+='

Itens:

'; v+=''; v+=''; v+=''; v+=''; v+=''; v+=''; v+=''; v+=''; v+=''; v+=''; if(pedido.items.length){ pedido.items.forEach(function(item){ v+=''; v+=''; v+=''; v+=''; v+=''; v+=''; }); }else{ v+=''; } v+=''; v+='
Código do itemDescriçãoMarcaQuantidade
'+item.cod.escapeHtml()+''+item.descr.escapeHtml()+''+item.marca.escapeHtml()+''+item.qtd.escapeHtml()+'
Nenhuma linha para exibir
'; } } $('#content').html(v); return }; viewUpdate(); jQuery.get( restApi, {}, function(data, textStatus, jqXHR){ pedidos = data; viewUpdate(); }, 'json' );