UNPKG

dhxmvp

Version:

A complete boilerplate for building online, offline and syncable MVP Single Page Applications using DHTMLX.

1 lines 5.09 kB
$dhx.ui.mvp.presenters.declare({presenter:function(){"strict";var e={start:function(){var e=this;e.view;console.log("MAIN:PRESENTER: start from MAIN:PRESENTER")},destroy:function(){$dhx.debug.log("MAIN:PRESENTER: destroy from MAIN:PRESENTER")},subscriber:function(e,t){var o,i,s=$dhx.ui.mvp.presenters.get("presenter"),c=s.view,l=0,a=$dhx.getRandomColor(),n=0,r="";console.log("Presenter Received Message: ",t),"create"==t.method&&(o=t.collection,c.chart_collections_data.exists(o)&&(l=c.chart_collections_data.get(o).items,a=c.chart_collections_data.get(o).color,c.chart_collections_data.remove(o)),l+=1,c.chart_collections_data.add({id:o,items:l,collection:o,color:a}),c.chart_collections_size.exists(o)&&(n=+c.chart_collections_size.get(o).size,a=c.chart_collections_size.get(o).color,c.chart_collections_size.remove(o)),delete t.model.id,console.log(t.model),r=""+JSON.stringify(t.model),i=new Blob([$dhx.UTF8.decode(r)],{type:"text/html"}),n+=i.size,c.chart_collections_size.add({id:o,size:n,collection:o,color:a}),i=null)},sidebarOnSelectHandler:function(e,t){var o=$dhx.ui.mvp.presenters.get("presenter"),i=o.view;"logout"==e&&o.do_logout(),"logout"!=e&&("help"==e&&(e="help/1"),i._router.dispatch(e,!0),window.dhx4.callEvent("onSidebarSelect",[e,this.cells(e)])),$dhx.ui.mvp.ui.isMobile||("help/1"==e&&(e="help"),i.toolbar.setItemText("title",window.dhx4.template("<img src='assets/icons/64/#image#' width='32' style='position:relative;float:left; margin-top:10px; margin-right: 10px;' /><span style='font-weight: bold; font-size: 14px;'>#text#</span>",{text:i.sidebar.cells(e).getText().text,image:i.sidebar.cells(e).getText().text.toLowerCase()+".png"})))},toolbarOnClickHandler:function(e){var t=$dhx.ui.mvp.presenters.get("presenter");t.view;"logout"==e&&t.do_logout()},layoutOnExpandHandler:function(e){var t=$dhx.ui.mvp.presenters.get("presenter");t.view},do_logout:function(){var e=this;e.view;window.location.reload()},add_sidebar_buttons:function(){var e=this,t=e.view;t.sidebar.addItem({id:"help",text:"Help",icon:"help.png"}),$dhx.ui.mvp.ui.isMobile&&t.sidebar.addItem([{id:"sep10",type:"separator"},{id:"logout",text:"Logout",icon:"logout.png"}])},adjust_to_mobile:function(){var e=this,t=e.view;try{$dhx.ui.mvp.ui.isMobile?(t.layout.cells("b").setText("Stats"),t.layout.cells("b").collapse(),t.layout.cells("b").setText("Stats")):t.status_bar.setText("")}catch(o){console.log(o.stack)}},build_ui:function(){var e=this,t=e.view;$dhx.showDirections("Starting UI"),$dhx.ui.mvp.ui.isMobile||t._toolbar(),t.status_bar=t.sidebar.attachStatusBar(),e.add_sidebar_buttons(),t._layout(),t._form(),t._chart_database_collections(),t._chart_collections_data(),t._chart_collections_size(),e.draw_chart_database_collections(),e.draw_chart_collections_data(),e.draw_chart_collections_size(),e.adjust_to_mobile(),$dhx.hideDirections()},askNotificationPermission:function(e){$dhx.ui.mvp.ui.askNotificationPermission({onSuccess:function(t){document.getElementById("dhx_npermission").value=t,e.onSuccess&&e.onSuccess()}})},askLocationPermission:function(e){navigator.geolocation.getCurrentPosition(function(t){e.onSuccess&&e.onSuccess(t)},function(t){e.onFail&&e.onFail(t)})},addBubble:function(e,t){var o=this,i=o.view,s=i.sidebar.cells(e).getBubble()||0;""===s&&(s=0),s=+s,s+=t,i.sidebar.cells(e).setBubble(s)},clearBubble:function(e){var t=this,o=t.view;o.sidebar.cells(e).clearBubble()},start_database:function(e){var t=this;t.view;$dhx.showDirections("Starting database ... "),$dhx.hideDirections(),console.warn("Syncing application"),$dhx.showDirections("Syncing application"),t.model.schema.sync({onSuccess:function(){$dhx.hideDirections(),$dhx.showDirections("Starting UI"),t.build_ui(),e.onSuccess&&e.onSuccess()}})},draw_chart_database_collections:function(){var e=this,t=e.view;for(var o in e.model.schema.io)t.chart_database_collections.add({id:o,items:1,collection:o,color:$dhx.getRandomColor()})},draw_chart_collections_data:function(){var e=this,t=e.view,o=Object.keys(e.model.schema.io),i=(o.length,null),s=[],c=function(){var l=0;i=o.shift(),i?e.model.schema.io[i].readAll({onSuccess:function(e,o,a){e.models.forEach(function(e){l+=1}),t.chart_collections_data.exists(i)&&t.chart_collections_data.remove(i),t.chart_collections_data.add({id:i,items:l,collection:i,color:$dhx.getRandomColor()}),s.push({collection:i,items:l}),c()}}):t.layout.cells("c").progressOff()};t.layout.cells("c").progressOn(),c()},draw_chart_collections_size:function(){var e=this,t=e.view,o=Object.keys(e.model.schema.io),i=(o.length,null),s=[],c=function(){i=o.shift(),i?e.model.schema.io[i].readAll({onSuccess:function(e,o,l){var a,n="";e.models.forEach(function(e){n+=JSON.stringify(e.toJSON())}),a=new Blob([$dhx.UTF8.decode(n)],{type:"text/html"}),t.chart_collections_size.exists(i)&&t.chart_collections_size.remove(i),t.chart_collections_size.add({id:i,size:(a.size/1024).toFixed(2),collection:i,color:$dhx.getRandomColor()}),console.log("TTTTTTTTTTTT: ",a),s.push({collection:i,size:a.size}),a=null,c()}}):t.layout.cells("c").progressOff()};t.layout.cells("c").progressOn(),c()}};return e}()});