PageRenderTime 42ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/themes/speed/js/speed.min.js

https://bitbucket.org/builtbyclick/new-speed-evidence
JavaScript | 1 lines | 1 code | 0 blank | 0 comment | 3 complexity | df444e1e2f68743e3075d4855c29a61a MD5 | raw file
Possible License(s): GPL-2.0, AGPL-1.0, LGPL-3.0, LGPL-2.1, BSD-3-Clause
  1. Backbone.View.prototype.close=function(){this.remove();this.unbind();if(this.onClose){this.onClose()}};var Report=Backbone.Model.extend({forView:function(){var e={1:"Web",2:"SMS",3:"Email",4:"Twitter"};var t=this.toJSON();t.id=t.incident.incidentid;t.link=baseURL+"/reports/view/"+t.incident.incidentid;t.name=t.incident.incidenttitle;t.description=$("<div>"+t.incident.incidentdescription+"</div>").text();t.date=moment(t.incident.incidentdate,"YYYY-MM-DD HH:mm:ss");t.site=t.incident.sharingsourceid;t.source=e[t.incident.incidentmode];t.category=[];_.each(t.categories,function(e){t.category.push(e.category.title)});t.category=t.category.join(", ");t.thumbnail=false;_.each(t.media,function(e){if(e.type==1&&!t.thumbnail)t.thumbnail=e.link_url});t.icon="icon-globe";if(t.incident.incidentmode==4){t.icon="icon-twitter"}else if(t.incident.incidentmode==3){t.icon="icon-envelope"}else if(t.incident.incidentmode==2){t.icon="icon-mobile-phone"}else if(t.incident.incidentmode==1){t.icon="icon-globe";_.each(t.media,function(e){if(e.type==2)t.icon="icon-facetime-video";if(e.type==1&&(t.icon=="icon-globe"||t.icon=="icon-file-text"))t.icon="icon-camera";if(e.type==4&&t.icon=="icon-globe")t.icon="icon-rss"})}if(t.site&&t.site!=="main"){t.url=baseURL+"/reports/sharing/view/"+t.id}else{t.url=baseURL+"/reports/view/"+t.id}return t}});var ReportCollection=Backbone.Collection.extend({model:Report,initialize:function(e,t){}});var ReportListView=Backbone.View.extend({template:_.template($("#reports-list-template").html()),emptyItemTemplate:_.template($("#empty-item-template").html()),initialize:function(e){_.bindAll(this,"addReport","addAll","loading","saveFilter","removeReport");this.model.bind("add",this.addReport);this.model.bind("remove",this.removeReport);this.model.bind("reset",this.addAll);this.container=$(e.container);this.liveReports=e.liveReports},events:{"click .paused":function(){this.liveReports.toggle()},"click .filter-button":function(){$("#middle").toggleClass("filterOpen")},"submit form":"saveFilter","click form input#reset":function(e){liveReports.filter({c:null,m:null,mode:null,q:null,sharing:null});liveReports.updateFormFromFilter()}},render:function(){this.$el.html(this.template({}));this.reportList=this.$("ul.reports-list");if(this.model.length>0){this.addAll()}else{this.reportList.append(this.emptyItemTemplate())}this.container.html(this.el);return this},addReport:function(e){var t=new ReportListLiView({model:e,id:"update_"+e.id,parent:this});this.reportList.append(t.render().el);e.view=t;this.$("li.no-reports").remove()},removeReport:function(){if(this.model.length==0){this.reportList.empty();this.reportList.append(this.emptyItemTemplate())}},addAll:function(){this.reportList.empty();this.model.each(this.addReport)},onClose:function(){this.model.unbind("add",this.addReport);this.model.unbind("reset",this.addAll);this.model.each(function(e){e.view.close()})},loading:function(e){if(e){this.$(".loading").show();this.$("li.no-reports").hide()}else{this.$(".loading").hide();this.$("li.no-reports").hide()}},saveFilter:function(e){filter=$("#latest-updates form").toJSON();filter=_.extend({c:[],m:[],mode:[],q:null,sharing:null},filter);delete filter.form_auth_token;liveReports.filter(filter);e.preventDefault()}});var ReportListLiView=Backbone.View.extend({initialize:function(e){_.bindAll(this,"update","remove","close","togglePopup");this.model.bind("change",this.update);this.model.bind("remove",this.close);this.parent=e.parent;$(document).on("click",function(t){e.parent.$("ul.reports-list li").popover("destroy").removeClass("popped")});$(".popover").on("click",function(e){e.stopPropagation()})},tagName:"li",className:"clearfix",events:{click:"togglePopup"},attributes:function(){var e=this.model.forView();return{"data-placement":"right",title:e.name,"data-content":_.template($("#report-popover-template").html(),e)}},template:_.template($("#report-item-template").html()),render:function(){var e=this.model.forView();this.$el.html(this.template(e));return this},remove:function(){this.$el.popover("destroy");this.$el.remove()},update:function(e){this.render()},onClose:function(){this.model.unbind("change",this.update);this.model.unbind("remove",this.remove)},togglePopup:function(e){var t=this.$el;if(!t.hasClass("popped")){this.parent.$("ul.reports-list li").not("#"+t.attr("id")).popover("destroy").removeClass("popped");t.popover({html:"true",trigger:"manual"}).popover("show").addClass("popped")}else{t.popover("destroy").removeClass("popped")}e.stopPropagation()}});var liveReports={request:null,pollTimeout:null,loaded:null,latestid:0,delay:2e4,filters:{},initialize:function(e){_.bindAll(this,"fetch","startPolling","update","stopPolling","toggle","updateFormFromFilter");dfd=$.Deferred();this.request=dfd.promise();dfd.resolve();this.loaded=$.Deferred();try{var t=JSON.parse(localStorage.getItem("updateFilters"))}catch(n){t={}}t=_.extend({c:[],m:[],mode:[]},t);this.filters=t;this.reports=new ReportCollection;this.listView=new ReportListView({model:this.reports,container:"#latest-updates",liveReports:this});this.listView.render();this.reports.view=this.listView;this.updateFormFromFilter();this.listView.loading(true);liveReports.loaded.done(_.bind(function(){this.listView.loading(false)},this));e=_.extend({},e);if(typeof e.delay!=="undefined"){this.delay==e.delay}},fetch:function(){this.clearPollingTimeout();if(this.request.state()=="pending")return this.request;var e=baseURL+"/api?task=incidents&limit=20";var t=[];for(var n in this.filters){if(this.filters[n]!=null){t.push(n+"="+this.filters[n])}}if(e.indexOf("?")!==-1){var r=e.indexOf("?");var i=e.substr(r+1,e.length).split("&");e=e.substring(0,r);for(var s=0;s<i.length;s++){t.push(i[s])}}e+=t.length>0?"?"+t.join("&"):"";dfd=$.getJSON(e).done(this.update).always(_.bind(function(){this.startPolling();this.loaded.resolve()},this));this.request=dfd.promise();return this.request},startPolling:function(e){if(this.pollTimeout==null||typeof e!=="undefined"){e=typeof e!=="undefined"?e:this.delay;this.clearPollingTimeout();this.pollTimeout=_.delay(this.fetch,e);$("#latest-updates .paused .pause").show();$("#latest-updates .paused .resume").hide()}},clearPollingTimeout:function(){clearTimeout(this.pollTimeout);this.pollTimeout=null},stopPolling:function(){this.clearPollingTimeout();$("#latest-updates .paused .pause").hide();$("#latest-updates .paused .resume").show()},isPolling:function(){if(this.pollTimeout==null)return false;return true},filter:function(e){if(e==undefined){throw"Missing filters"}var t=false;$.each(e,_.bind(function(e,n){var r=this.filters[e];if(r==undefined&&r==null||r!==n){t=true;this.filters[e]=n}},this));localStorage.setItem("updateFilters",JSON.stringify(this.filters));if(t){this.startPolling(0)}},update:function(e){var t=this;if(typeof e.payload!="undefined"){if(typeof e.payload.incidents!="undefined"){_.each(e.payload.incidents,function(t,n){e.payload.incidents[n].id=t.incident.incidentid});this.reports.set(e.payload.incidents)}else{this.reports.set([])}}},toggle:function(e){if(this.pollTimeout==null)this.startPolling();else this.stopPolling();e.preventDefault()},updateFormFromFilter:function(){var e=this.filters;$("#latest-updates form input").attr("checked",false);if(typeof e.q!=="undefined")$("#latest-updates form #q").val(e.q);if(typeof e.m!=="undefined"){_.each(e.m,function(e){$('#latest-updates form input[name="m[]"][value="'+e+'"]').attr("checked","checked")})}if(typeof e.mode!=="undefined"){_.each(e.mode,function(e){$('#latest-updates form input[name="mode[]"][value="'+e+'"]').attr("checked","checked")})}if(typeof e.c!=="undefined"){_.each(e.c,function(e){$('#latest-updates form input[name="c[]"][value="'+e+'"]').attr("checked","checked")})}if(typeof e.sharing!=="undefined"){_.each(e.sharing,function(e){$('#latest-updates form input[name="sharing[]"][value="'+e+'"]').attr("checked","checked")})}}};$(document).ready(function(){liveReports.initialize();liveReports.loaded.done(function(){var e=false;$("#latest-updates").hover(function(){$("#latest-updates .paused").show();$("#latest-updates .filter-button").show();e=liveReports.isPolling();liveReports.stopPolling()},function(){$("#latest-updates .paused").hide();$("#latest-updates .filter-button").hide();if(e)liveReports.startPolling()})});liveReports.startPolling(0)})