StatJson.min.js 2.1 KB

1
  1. var StatJson=new Class({options:{},initialize:function(t,o){this.setOptions(o);this.context=t},load:function(){if(this.context.statJson){this.json=JSON.parse(this.context.statJson)}else{this.json={total:{publishedCount:0,errorCount:0},batch:{}}}},sumit:function(){this.context.statJson=JSON.stringify(this.json)},addBatch:function(t,o){if(!this.json.batch[t]){this.json.batch[t]={publishedCount:0,errorCount:0}}if(o)this.currentBatch=this.json.batch[t]},deleteBatch:function(t){var o=this.json;if(o.batch[t]){var i=o.batch[t];if(i.publishedCount){o.total.publishedCount=o.total.publishedCount-i.publishedCount}if(i.errorCount){o.total.errorCount=o.total.errorCount-i.errorCount}delete this.json.batch[t]}},addData:function(t){var o=t;var i=this.json.total;var u=this.currentBatch;if(o.docStatus=="published"){i.publishedCount++;u.publishedCount++;this.addCount(i,o);this.addCount(u,o)}else if(o.docStatus=="error"){i.errorCount++;u.errorCount++}},addCount:function(t,o){if(o.city){var i=t[o.city];if(!i){i=t[o.city]={publishedCount:0}}i.publishedCount++;if(o.county){var u=i[o.county];if(!u){u=i[o.county]={publishedCount:0}}u.publishedCount++;if(o.brach){var n=u[o.brach];if(!n){n=u[o.brach]={publishedCount:0}}n.publishedCount++}}}},reduceCount:function(t,o){if(o.city){var i=t[o.city];if(!i){i=t[o.city]={publishedCount:0}}i.publishedCount--;if(o.county){var u=i[o.county];if(!u){u=i[o.county]={publishedCount:0}}u.publishedCount--;if(o.brach){var n=u[o.brach];if(!n){n=u[o.brach]={publishedCount:0}}n.publishedCount--}}}},getCity:function(){var t=this.json.total;var o=[];for(var i in t){if(i!="publishedCount"&&i!="errorCount"){if(t[i].publishedCount>0){o.push(i)}}}return o},changeData:function(t,o){var i=t;var u;if(i.$importBatchName&&this.json.batch[i.$importBatchName]){u=this.json.batch[i.$importBatchName]}var n=this.json.total;if(o.status=="error"){n.errorCount--;if(u)u.errorCount--}if(o.status=="published"){n.publishedCount--;this.reduceCount(n,o);if(u){u.publishedCount--;this.reduceCount(u,o)}}if(i.docStatus=="error"){n.errorCount++;if(u)u.errorCount++}if(i.docStatus=="published"){n.publishedCount++;this.addCount(n,i);if(u){u.publishedCount++;this.addCount(u,i)}}}});