UNPKG

c8y-openlayer

Version:

This module is designed to help integrate Openlayer with Cumulocity IoT

114 lines 279 kB
Ext.define("Traccar.Style",{singleton:!0,refreshPeriod:6E4,reconnectTimeout:5E3,normalPadding:10,windowWidth:800,windowHeight:600,formFieldWidth:275,dateTimeFormat24:"Y-m-d H:i:s",dateTimeFormat12:"Y-m-d g:i:s a",timeFormat24:"H:i",timeFormat12:"g:i a",dateFormat:"Y-m-d",weekStartDay:1,deviceWidth:400,toastWidth:300,reportHeight:250,columnWidthNormal:100,mapDefaultLat:49.89767923211528,mapDefaultLon:10.878779590129852,mapDefaultZoom:20,mapRouteColor:"#F06292 #BA68C8 #4DD0E1 #4DB6AC #FF8A65 #A1887F".split(" "), mapRouteWidth:5,mapTextColor:"rgba(50, 50, 50, 1.0)",mapTextStrokeColor:"rgba(255, 255, 255, 1.0)",mapTextStrokeWidth:2,mapTextOffset:2,mapTextFont:"bold 12px sans-serif",mapColorOnline:"rgba(77, 250, 144, 1.0)",mapColorUnknown:"rgba(250, 190, 77, 1.0)",mapColorOffline:"rgba(255, 162, 173, 1.0)",mapScaleNormal:1,mapScaleSelected:1.5,mapMaxZoom:25,mapDelay:500,mapAccuracyColor:"rgba(96, 96, 96, 1.0)",mapGeofenceTextColor:"rgba(14, 88, 141, 1.0)",mapGeofenceColor:"rgba(21, 127, 204, 1.0)",mapGeofenceOverlayOpacity:.2, mapGeofenceWidth:5,mapGeofenceRadius:9,coordinatePrecision:6,numberPrecision:2,reportGridStyle:"borderTop: 1px solid lightgray",chartPadding:"20 40 10 10",chartMarkerRadius:3,chartMarkerHighlightScaling:1.5});Ext.define("Traccar.view.dialog.Base",{extend:Ext.window.Window,bodyPadding:Traccar.Style.normalPadding,resizable:!1,autoScroll:!0,constrain:!0,initComponent:function(){window.innerHeight&&(this.maxHeight=window.innerHeight-2*Traccar.Style.normalPadding);this.callParent()}}); Ext.define("Traccar.view.dialog.RegisterController",{extend:Ext.app.ViewController,alias:"controller.register",onCreateClick:function(){var b=this.lookupReference("form");b.isValid()&&Ext.Ajax.request({scope:this,method:"POST",url:"api/users",jsonData:b.getValues(),callback:this.onCreateReturn})},onCreateReturn:function(b,c,d){c?(this.closeView(),Traccar.app.showToast(Strings.loginCreated)):Traccar.app.showError(d)}}); Ext.define("Traccar.view.dialog.Register",{extend:Traccar.view.dialog.Base,controller:"register",title:Strings.loginRegister,items:{xtype:"form",reference:"form",jsonSubmit:!0,items:[{xtype:"textfield",name:"name",fieldLabel:Strings.sharedName,allowBlank:!1},{xtype:"textfield",name:"email",fieldLabel:Strings.userEmail,validator:function(b){return/(.+)@(.+)\.(.{2,})/.test(b)?!0:Ext.form.field.VTypes.emailText},allowBlank:!1},{xtype:"textfield",name:"password",fieldLabel:Strings.userPassword,inputType:"password", allowBlank:!1}]},buttons:[{text:Strings.sharedSave,handler:"onCreateClick"},{text:Strings.sharedCancel,handler:"closeView"}]}); Ext.define("Traccar.view.dialog.LoginController",{extend:Ext.app.ViewController,alias:"controller.login",init:function(){this.lookupReference("languageField").setValue(Locale.language)},login:function(){var b=this.lookupReference("form");b.isValid()&&(Ext.get("spinner").setVisible(!0),this.getView().setVisible(!1),Ext.Ajax.request({scope:this,method:"POST",url:"api/session",params:b.getValues(),callback:function(b,d,e){Ext.get("spinner").setVisible(!1);204===e.status?(this.getView().setVisible(!0), Traccar.app.showError(Strings.loginFailed)):d?(Traccar.app.userName=this.lookupReference("userField").getValue(),Traccar.app.userPassword=this.lookupReference("passwordField").getValue(),this.lookupReference("rememberField").getValue()?(Ext.util.Cookies.set("user",Ext.util.Base64.encode(Traccar.app.userName),Ext.Date.add(new Date,Ext.Date.YEAR,1)),Ext.util.Cookies.set("password",Ext.util.Base64.encode(Traccar.app.userPassword),Ext.Date.add(new Date,Ext.Date.YEAR,1))):sessionStorage&&(sessionStorage.setItem("Traccar.app.userName", Traccar.app.userName),sessionStorage.setItem("Traccar.app.userPassword",Traccar.app.userPassword)),Traccar.app.setUser(Ext.decode(e.responseText)),this.fireViewEvent("login")):(this.getView().setVisible(!0),401===e.status||400===e.status?Traccar.app.showError(Strings.loginFailed):Traccar.app.showError(e.responseText))}}))},logout:function(){Ext.util.Cookies.clear("user");Ext.util.Cookies.clear("password");Ext.Ajax.request({scope:this,method:"DELETE",url:"api/session",callback:function(){window.location.reload()}})}, onSelectLanguage:function(b){var c,d;b=b.getValue();c=window.location.href;0<=c.indexOf("locale\x3d")?(d=c.substring(0,c.indexOf("locale")),c=c.substring(c.indexOf("locale")),c=c.substring(c.indexOf("\x3d")+1),c=0<=c.indexOf("\x26")?c.substring(c.indexOf("\x26")):"",c=d+"locale\x3d"+b+c):c=0>c.indexOf("?")?c+("?locale\x3d"+b):c+("\x26locale\x3d"+b);window.location.href=c},onAfterRender:function(b){b.focus()},onSpecialKey:function(b,c){c.getKey()===c.ENTER&&this.login()},onLoginClick:function(){Ext.getElementById("submitButton").click(); this.login()},onResetClick:function(){Ext.create("Traccar.view.dialog.Reset").show()}}); Ext.define("Traccar.view.dialog.ResetController",{extend:Ext.app.ViewController,alias:"controller.reset",recaptchaResponse:null,onSendClick:function(){if(this.recaptchaResponse){var b=this.lookupReference("form");b.isValid()&&Ext.Ajax.request({scope:this,method:"POST",url:"api/users/reset",jsonData:{email:b.getValues().email,recaptcha:this.recaptchaResponse},callback:this.onCreateReturn})}else Traccar.app.showMsgCallback(Strings.errorTitle,Strings.loginCaptchaError,function(){grecaptcha.reset()})}, onCreateReturn:function(b,c,d){c?(this.closeView(),Traccar.app.showToast(Strings.loginResetMailSend)):Traccar.app.showError(d)},onSpecialKey:function(b,c){if(c.getKey()===c.ENTER)this.onSendClick()}}); Ext.define("Traccar.view.dialog.Reset",{extend:Traccar.view.dialog.Base,controller:"reset",title:Strings.loginReset,items:{xtype:"form",reference:"form",jsonSubmit:!0,id:"resetForm",items:[{xtype:"textfield",name:"email",fieldLabel:Strings.userEmail,validator:function(b){return/(.+)@(.+)\.(.{2,})/.test(b)?!0:Ext.form.field.VTypes.emailText},allowBlank:!1,enableKeyEvents:!0,listeners:{specialKey:"onSpecialKey"}},{xtype:"box",name:"captcha",fieldLabel:"captcha",id:"recaptcha",enableKeyEvents:!0,listeners:{specialKey:"onSpecialKey", afterrender:function(){var b=this.up().up();grecaptcha.render("recaptcha",{sitekey:Traccar.app.captchaKey,callback:function(c){b.controller.recaptchaResponse=c;b.lookupReference("sendButton").setHidden(!1)},theme:"light"})}}}]},buttons:[{text:Strings.commandSend,handler:"onSendClick",hidden:!0,reference:"sendButton"},{text:Strings.sharedCancel,handler:"closeView"}]}); Ext.define("Traccar.view.dialog.Login",{extend:Traccar.view.dialog.Base,alias:"widget.login",controller:"login",header:!1,closable:!1,items:{xtype:"form",reference:"form",autoEl:{tag:"form",method:"POST",action:"fake-login.html",target:"submitTarget"},items:[{xtype:"image",src:"safectory.svg",alt:Strings.loginLogo,width:180,height:48,style:{display:"block",margin:"10px auto 25px"}},{xtype:"combobox",name:"language",fieldLabel:Strings.loginLanguage,store:"Languages",displayField:"name",valueField:"code", editable:!1,submitValue:!1,listeners:{select:"onSelectLanguage"},reference:"languageField"},{xtype:"textfield",name:"email",reference:"userField",fieldLabel:Strings.userEmail,allowBlank:!1,enableKeyEvents:!0,listeners:{specialKey:"onSpecialKey",afterrender:"onAfterRender"},inputAttrTpl:['autocomplete\x3d"on" autocapitalize\x3d"none"']},{xtype:"textfield",name:"password",reference:"passwordField",fieldLabel:Strings.userPassword,inputType:"password",allowBlank:!1,enableKeyEvents:!0,listeners:{specialKey:"onSpecialKey"}, inputAttrTpl:['autocomplete\x3d"on"']},{xtype:"checkboxfield",inputValue:!0,uncheckedValue:!1,reference:"rememberField",fieldLabel:Strings.userRemember},{xtype:"component",html:'\x3ciframe id\x3d"submitTarget" name\x3d"submitTarget" style\x3d"display:none"\x3e\x3c/iframe\x3e'},{xtype:"component",html:'\x3cinput type\x3d"submit" id\x3d"submitButton" style\x3d"display:none"\x3e'}]},buttons:[{text:Strings.loginReset,handler:"onResetClick",reference:"resetButton"},{text:Strings.loginLogin,handler:"onLoginClick"}]}); Ext.define("Traccar.view.MainController",{extend:Ext.app.ViewController,alias:"controller.mainController",init:function(){this.lookupReference("reportView").setHidden(Traccar.app.getBooleanAttributePreference("ui.disableReport"));this.lookupReference("eventsView").setHidden(Traccar.app.getBooleanAttributePreference("ui.disableEvents"))},listen:{global:{onPermissionsLoaded:"permissionsLoaded",onGroupsLoaded:"groupsLoaded"}},groupsLoadedDone:!1,permissionsLoadedDone:!1,groupsLoaded:function(){(this.groupsLoadedDone= !0,this.permissionsLoadedDone)&&this.showDeviceView()},permissionsLoaded:function(){this.permissionsLoadedDone=!0;this.groupsLoadedDone&&this.permissionsLoadedDone&&this.showDeviceView()},showDeviceView:function(){Traccar.app.hasPermission("Device",!1)&&this.lookupReference("deviceView")&&this.lookupReference("deviceView").setHidden(!1)}}); Ext.define("Traccar.types.Types",{override:"Ext.form.field.VTypes",daterange:function(b,c){b=c.parseDate(b);if(!b)return!1;!c.startDateField||this.dateRangeMax&&b.getTime()==this.dateRangeMax.getTime()?!c.endDateField||this.dateRangeMin&&b.getTime()==this.dateRangeMin.getTime()||(c=c.up("form").down("#"+c.endDateField),c.setMinValue(b),c.validate(),this.dateRangeMin=b):(c=c.up("form").down("#"+c.startDateField),c.setMaxValue(b),c.validate(),this.dateRangeMax=b);return!0},daterangeText:"Start date must be less than end date", password:function(b,c){return c.initialPassField?(c=c.up("form").down("#"+c.initialPassField),b==c.getValue()):!0},passwordText:Strings.loginPasswordNotMatch});Ext.define("Traccar.view.GridPanel",{extend:Ext.grid.Panel,xtype:"customGridPanel",plugins:["gridfilters"],viewConfig:{enableTextSelection:!0,getRowClass:function(){return this.enableTextSelection?"x-selectable":""}}}); Ext.define("Traccar.AttributeFormatter",{singleton:!0,numberFormatterFactory:function(b,c){return function(d){return void 0!==d?Number(d.toFixed(b))+" "+c:null}},coordinateFormatter:function(b,c){return Ext.getStore("CoordinateFormats").formatValue(b,c,Traccar.app.getPreference("coordinateFormat"))},speedFormatter:function(b){return Ext.getStore("SpeedUnits").formatValue(b,Traccar.app.getAttributePreference("speedUnit"))},speedConverter:function(b){return Ext.getStore("SpeedUnits").convertValue(b, Traccar.app.getAttributePreference("speedUnit"))},courseFormatter:function(b){return"N NE E SE S SW W NW".split(" ")[Math.floor(b/45)]},distanceFormatter:function(b){return Ext.getStore("DistanceUnits").formatValue(b,Traccar.app.getAttributePreference("distanceUnit"))},distanceConverter:function(b){return Ext.getStore("DistanceUnits").convertValue(b,Traccar.app.getAttributePreference("distanceUnit"))},volumeFormatter:function(b){return Ext.getStore("VolumeUnits").formatValue(b,Traccar.app.getAttributePreference("volumeUnit"))}, volumeConverter:function(b){return Ext.getStore("VolumeUnits").convertValue(b,Traccar.app.getAttributePreference("volumeUnit"))},durationFormatter:function(b){return Math.floor(b/36E5)+" "+Strings.sharedHourAbbreviation+" "+Math.floor(b%36E5/6E4)+" "+Strings.sharedMinuteAbbreviation},deviceIdFormatter:function(b){return Ext.getStore("Devices").getById(b).get("name")},groupIdFormatter:function(b){var c;return 0!==b?(c=Ext.getStore("AllGroups"),0===c.getTotalCount()&&(c=Ext.getStore("Groups")),(c=c.getById(b))? c.get("name"):b):null},beaconIdFormatter:function(b){var c;return 0!==b?(c=Ext.getStore("Beacons"),(c=c.getById(b))?c.get("name"):b):null},userIdFormatter:function(b){return(b=Ext.getStore("Users").getById(b))?b.get("name"):""},geofenceIdFormatter:function(b){var c;return 0!==b?(c=Ext.getStore("AllGeofences"),0===c.getTotalCount()&&(c=Ext.getStore("Geofences")),(b=c.getById(b))?b.get("name"):""):null},calendarIdFormatter:function(b){var c;return 0!==b?(c=Ext.getStore("AllCalendars"),0===c.getTotalCount()&& (c=Ext.getStore("Calendars")),(b=c.getById(b))?b.get("name"):""):null},driverUniqueIdFormatter:function(b){var c;return 0!==b?(c=Ext.getStore("AllDrivers"),0===c.getTotalCount()&&(c=Ext.getStore("Drivers")),(c=c.findRecord("uniqueId",b,0,!1,!0,!0))?b+" ("+c.get("name")+")":b):null},lastUpdateFormatter:function(b){var c;if(b){b=Math.floor((new Date-b)/1E3);0>b&&(b=0);c=Math.floor(b/86400);if(1<c)return c+" "+Strings.sharedDays;c=Math.floor(b/3600);return 1<c?c+" "+Strings.sharedHours:Math.floor(b/ 60)+":"+Math.floor(b%60)+" "+Strings.sharedMinutes}return null},geofenceNameFormater:function(b){return b.geofenceNames},sendMessagesFormater:function(b){return b&&b.message?b.message:""},commandTypeFormatter:function(b){var c=Strings["command"+b.charAt(0).toUpperCase()+b.slice(1)];return c?c:b},defaultFormatter:function(b){return"number"===typeof b?Number(b.toFixed(Traccar.Style.numberPrecision)):"boolean"===typeof b?b?Ext.Msg.buttonText.yes:Ext.Msg.buttonText.no:b instanceof Date?Traccar.app.getPreference("twelveHourFormat", !1)?Ext.Date.format(b,Traccar.Style.dateTimeFormat12):Ext.Date.format(b,Traccar.Style.dateTimeFormat24):b},getFormatter:function(b){var c=this;switch(b){case "latitude":case "longitude":return function(d){return c.coordinateFormatter(b,d)};case "speed":return this.speedFormatter;case "course":return this.courseFormatter;case "distance":case "accuracy":return this.distanceFormatter;case "duration":return this.durationFormatter;case "deviceId":return this.deviceIdFormatter;case "groupId":return this.groupIdFormatter; case "beaconId":return this.beaconIdFormatter;case "userId":return this.userIdFormatter;case "geofenceId":return this.geofenceIdFormatter;case "calendarId":return this.calendarIdFormatter;case "lastUpdate":return this.lastUpdateFormatter;case "spentFuel":return this.volumeFormatter;case "driverUniqueId":return this.driverUniqueIdFormatter;case "commandType":return this.commandTypeFormatter;case "geofenceNames":return this.geofenceNameFormater;case "sendMessages":return this.sendMessagesFormater;default:return this.defaultFormatter}}, getConverter:function(b){switch(b){case "speed":return this.speedConverter;case "distance":case "accuracy":return this.distanceConverter;case "spentFuel":return this.volumeConverter;default:return function(b){return b}}},getAttributeFormatter:function(b){switch(Ext.getStore("PositionAttributes").getAttributeDataType(b)){case "distance":return this.distanceFormatter;case "speed":return this.speedFormatter;case "driverUniqueId":return this.driverUniqueIdFormatter;case "voltage":return this.numberFormatterFactory(Traccar.Style.numberPrecision, Strings.sharedVoltAbbreviation);case "percentage":return this.numberFormatterFactory(Traccar.Style.numberPrecision,"\x26#37;");case "temperature":return this.numberFormatterFactory(Traccar.Style.numberPrecision,"\x26deg;C");case "volume":return this.volumeFormatter;case "consumption":return this.numberFormatterFactory(Traccar.Style.numberPrecision,Strings.sharedLiterPerHourAbbreviation);default:return this.defaultFormatter}},getAttributeConverter:function(b){switch(Ext.getStore("PositionAttributes").getAttributeDataType(b)){case "distance":return this.distanceConverter; case "speed":return this.speedConverter;case "volume":return this.volumeConverter;default:return function(b){return b}}},getAttributeComboboxRenderer:function(b){switch(b){case "message":return this.comboboxRendererAtrributesMessage;default:return function(b){return b}}},comboboxRendererAtrributesMessage:function(b){return function(c){c=b.store.find(b.valueField,c);return b.store.getAt(c).get(b.displayField)}}}); Ext.define("Traccar.view.edit.ToolbarController",{extend:Ext.app.ViewController,alias:"controller.toolbarController",onAddClick:function(){var b,c=Ext.create(this.objectModel);c.store=this.getView().getStore();c.store instanceof Ext.data.ChainedStore&&(c.store=c.store.getSource());b=Ext.create(this.objectDialog);b.objectStore=this.getView().getStore();b.down("form").loadRecord(c);b.show()},onEditClick:function(){var b,c=this.getView().getSelectionModel().getSelection()[0];b=Ext.create(this.objectDialog); b.objectStore=this.getView().getStore();b.down("form").loadRecord(c);b.show()},onRemoveClick:function(){var b=this.getView().getSelectionModel().getSelection(),c=null;Ext.Msg.show({title:this.removeTitle,message:"Remove "+b.length+" item?",buttons:Ext.Msg.YESNO,buttonText:{yes:Strings.sharedRemove,no:Strings.sharedCancel},fn:function(d){if("yes"===d){for(i=0;i<b.length;i++)c=b[i].store,c.remove(b[i]);c.sync({failure:function(b){c.rejectChanges();Traccar.app.showError(b.exceptions[0].getError().response)}})}}})}, onSelectionChange:function(b,c){b=0===c.length;this.lookupReference("toolbarEditButton").setDisabled(b);this.lookupReference("toolbarRemoveButton").setDisabled(b)}});Ext.define("Traccar.view.BaseWindow",{extend:Ext.window.Window,width:Traccar.Style.windowWidth,height:Traccar.Style.windowHeight,layout:"fit",initComponent:function(){if(window.innerWidth<Traccar.Style.windowWidth||window.innerHeight<Traccar.Style.windowHeight)this.maximized=!0,this.style="border-width: 0";this.callParent()}}); Ext.define("Traccar.view.dialog.AttributeController",{extend:Ext.app.ViewController,alias:"controller.attribute",onSaveClick:function(b){var c,d;c=b.up("window").down("form");c.updateRecord();c=c.getRecord();(d=c.store)?(c.phantom&&d.add(c),d.sync({failure:function(b){d.rejectChanges();Traccar.app.showError(b.exceptions[0].getError().response)}})):c.save();b.up("window").close()},onValidityChange:function(b,c){this.lookupReference("saveButton").setDisabled(!c)},defaultFieldConfig:{name:"value",reference:"valueField", allowBlank:!1,fieldLabel:Strings.stateValue},onNameChange:function(b,c){var d=this.lookupReference("valueField");if(c=b.getStore().getById(c)){b=Ext.clone(this.defaultFieldConfig);switch(c.get("valueType")){case "number":b.xtype="customNumberField";void 0!==c.get("allowDecimals")?b.allowDecimals=c.get("allowDecimals"):b.allowDecimals=!0;b.dataType=c.get("dataType");b.maxValue=c.get("maxValue");b.minValue=c.get("minValue");break;case "boolean":b.xtype="checkboxfield";b.inputValue=!0;b.uncheckedValue= !1;break;case "color":b.xtype="customcolorpicker";break;default:if(c.get("dataType"))switch(b.xtype="combobox",b.queryMode="local",b.editable=!1,c.get("dataType")){case "distanceUnit":b.store="DistanceUnits";b.displayField="name";b.valueField="key";break;case "speedUnit":b.store="SpeedUnits";b.displayField="name";b.valueField="key";break;case "volumeUnit":b.store="VolumeUnits";b.displayField="fullName";b.valueField="key";break;case "timezone":b.store="AllTimezones",b.displayField="key"}else b.xtype= "textfield"}d.getXType()!==b.xtype?(this.getView().down("form").insert(this.getView().down("form").items.indexOf(d),b),this.getView().down("form").remove(d)):"customNumberField"===b.xtype?(d.setConfig(b),d.validate()):"combobox"===b.xtype&&(d.setConfig(b),d.setValue())}}}); Ext.define("Traccar.view.ColorPicker",{extend:Ext.form.field.Picker,xtype:"customcolorpicker",config:{value:"#008000"},editable:!1,createPicker:function(){return Ext.create("Ext.picker.Color",{floating:!0,picker:this,select:function(b){this.picker.setValue("#"+b);this.picker.collapse()}})},setValue:function(b){this.callParent([b]);this.setFieldStyle("background-color:"+b)}}); Ext.define("Traccar.view.CustomNumberField",{extend:Ext.form.field.Number,xtype:"customNumberField",beforeEl:'\x3cdiv style\x3d"width:100%;display:inline-table;"\x3e',unitEl:'\x3cdiv id\x3d"numberUnitEl" style\x3d"display:table-cell;padding-left:10px;vertical-align:middle;width:1px;white-space:nowrap;"\x3e',constructor:function(b){var c="";if(b.dataType){b.beforeBodyEl=this.beforeEl;switch(b.dataType){case "speed":b.units={};b.units.getStore=function(){return Ext.getStore("SpeedUnits")};b.units.getValue= function(){return Traccar.app.getAttributePreference("speedUnit","kn")};c=Ext.getStore("SpeedUnits").findRecord("key",b.units.getValue()).get("name");break;case "distance":b.units={};b.units.getStore=function(){return Ext.getStore("DistanceUnits")};b.units.getValue=function(){return Traccar.app.getAttributePreference("distanceUnit","km")};c=Ext.getStore("DistanceUnits").findRecord("key",b.units.getValue()).get("name");break;case "frequency":b.listeners||(b.listeners={}),b.listeners.afterrender=function(){this.units|| (this.units=Ext.create({xtype:"combobox",renderTo:"numberUnitEl",store:"TimeUnits",displayField:"name",valueField:"key",editable:!1,numberField:this,value:"s",width:"70px",listeners:{select:function(){this.numberField.step=this.getStore().convertValue(1,this.getValue(),!0)}}}))}}b.afterBodyEl=this.unitEl+c+"\x3c/div\x3e\x3c/div\x3e";b.rawToValue=function(b){return this.units?this.units.getStore().convertValue(b,this.units.getValue(),!0):this.parseValue(b)};b.valueToRaw=function(b){return this.units? this.units.getStore().convertValue(b,this.units.getValue(),!1):this.parseValue(b)};b.units&&(b.step=b.units.getStore().convertValue(1,b.units.getValue(),!0))}this.callParent(arguments)}}); Ext.define("Traccar.view.dialog.Attribute",{extend:Traccar.view.dialog.Base,controller:"attribute",title:Strings.sharedAttribute,items:{xtype:"form",listeners:{validitychange:"onValidityChange"},items:[{xtype:"textfield",reference:"nameTextField",name:"name",allowBlank:!1,fieldLabel:Strings.sharedName},{xtype:"textfield",name:"value",reference:"valueField",allowBlank:!1,fieldLabel:Strings.stateValue}]},buttons:[{glyph:"xf00c@FontAwesome",reference:"saveButton",tooltip:Strings.sharedSave,tooltipType:"title", minWidth:0,handler:"onSaveClick"},{glyph:"xf00d@FontAwesome",tooltip:Strings.sharedCancel,tooltipType:"title",minWidth:0,handler:"closeView"}]});Ext.define("Traccar.model.Attribute",{extend:Ext.data.Model,fields:[{name:"priority",type:"int"},{name:"name",type:"string"},{name:"value"},{name:"attribute",type:"string"}]});Ext.define("Traccar.store.Attributes",{extend:Ext.data.Store,model:"Traccar.model.Attribute",sorters:[{property:"priority"}]}); Ext.define("Traccar.view.edit.AttributesController",{extend:Traccar.view.edit.ToolbarController,alias:"controller.attributes",removeTitle:Strings.stateName,init:function(){var b,c,d=0,e;b=Ext.create("Traccar.store.Attributes");b.setProxy(Ext.create("Ext.data.proxy.Memory"));"undefined"===typeof this.getView().record.get("attributes")&&this.getView().record.set("attributes",{});e=this.getView().record.get("attributes");for(c in e)e.hasOwnProperty(c)&&b.add(Ext.create("Traccar.model.Attribute",{priority:d++, name:c,value:e[c]}));b.addListener("add",function(b,c){var d;d=this.getView();for(b=0;b<c.length;b++)d.record.get("attributes")[c[b].get("name")]=c[b].get("value");d.record.dirty=!0},this);b.addListener("update",function(b,c,d){b=this.getView();d===Ext.data.Model.EDIT&&(c.modified.name!==c.get("name")&&delete b.record.get("attributes")[c.modified.name],b.record.get("attributes")[c.get("name")]=c.get("value"),b.record.dirty=!0)},this);b.addListener("remove",function(b,c){var d;d=this.getView();for(b= 0;b<c.length;b++)delete d.record.get("attributes")[c[b].get("name")];d.record.dirty=!0},this);this.getView().setStore(b);this.getView().record instanceof Traccar.model.Device?this.getView().attributesStore="DeviceAttributes":this.getView().record instanceof Traccar.model.Geofence?this.getView().attributesStore="GeofenceAttributes":this.getView().record instanceof Traccar.model.Beacon?this.getView().attributesStore="BeaconAttributes":this.getView().record instanceof Traccar.model.Server?this.getView().attributesStore= "ServerAttributes":this.getView().record instanceof Traccar.model.User&&(this.getView().attributesStore="UserAttributes")},comboConfig:{xtype:"combobox",reference:"nameComboField",name:"name",fieldLabel:Strings.sharedName,displayField:"name",valueField:"key",allowBlank:!1,queryMode:"local",listeners:{change:"onNameChange"}},initDialog:function(b){var c,d=Ext.create("Traccar.view.dialog.Attribute");this.getView().attributesStore&&(this.comboConfig.store=this.getView().attributesStore,c=d.lookupReference("nameTextField"), d.down("form").insert(0,this.comboConfig),d.down("form").remove(c));d.down("form").loadRecord(b);d.show()},onAddClick:function(){var b=Ext.create("Traccar.model.Attribute");b.store=this.getView().getStore();this.initDialog(b)},onEditClick:function(){this.initDialog(this.getView().getSelectionModel().getSelection()[0])}}); Ext.define("Traccar.view.edit.Toolbar",{extend:Ext.toolbar.Toolbar,xtype:"editToolbar",initComponent:function(){this.callParent(arguments);this.add(0,[{xtype:"button",handler:"onAddClick",reference:"toolbarAddButton",glyph:"xf067@FontAwesome",tooltip:Strings.sharedAdd,tooltipType:"title"},{xtype:"button",disabled:!0,handler:"onEditClick",reference:"toolbarEditButton",glyph:"xf040@FontAwesome",tooltip:Strings.sharedEdit,tooltipType:"title"},{xtype:"button",disabled:!0,handler:"onRemoveClick",reference:"toolbarRemoveButton", glyph:"xf00d@FontAwesome",tooltip:Strings.sharedRemove,tooltipType:"title"}])}}); Ext.define("Traccar.view.edit.Attributes",{extend:Traccar.view.GridPanel,xtype:"attributesView",controller:"attributes",tbar:{xtype:"editToolbar"},listeners:{selectionchange:"onSelectionChange"},columns:{defaults:{flex:1,minWidth:Traccar.Style.columnWidthNormal},items:[{text:Strings.sharedName,dataIndex:"name",filter:"string",renderer:function(b){var c;this.attributesStore&&(c=Ext.getStore(this.attributesStore).getById(b));return c&&c.get("name")?c.get("name"):b}},{text:Strings.stateValue,dataIndex:"value", renderer:function(b,c,d){var e;this.attributesStore&&(e=Ext.getStore(this.attributesStore).getById(d.get("name")));return e&&"speed"===e.get("dataType")?Ext.getStore("SpeedUnits").formatValue(b,Traccar.app.getAttributePreference("speedUnit","kn"),!0):e&&"distance"===e.get("dataType")?Ext.getStore("DistanceUnits").formatValue(b,Traccar.app.getAttributePreference("distanceUnit","km"),!0):b}}]}}); Ext.define("Traccar.view.dialog.BaseEditController",{extend:Ext.app.ViewController,alias:"controller.baseEdit",savedStore:{},onSaveClick:function(b){var c,d;b=b.up("window");c=b.down("form");c.updateRecord();c=c.getRecord();(d=c.store)||Ext.isEmpty(savedStore)||(d=savedStore);d?(c.phantom&&d.add(c),d.sync({failure:function(b){d.rejectChanges();savedStore=d;b.exceptions[0].getError().status&&(409==b.exceptions[0].getError().status?Traccar.app.showError(this.getTitle()+Strings.errorAddDuplicate):400== b.exceptions[0].getError().status?Traccar.app.showError(this.getTitle()+Strings.errorAddDatabase):Traccar.app.showError(b.exceptions[0].getError().response))},success:function(){d.reload();this.close()},scope:b})):(c.save(),this.closeView())},showAttributesView:function(b){b=b.up("window").down("form").getRecord();Ext.create("Traccar.view.BaseWindow",{title:Strings.sharedAttributes,items:{xtype:"attributesView",record:b}}).show()}}); Ext.define("Traccar.view.dialog.SavedCommandController",{extend:Traccar.view.dialog.BaseEditController,alias:"controller.savedCommand",defaultFieldConfig:{allowBlank:!1},onTypeChange:function(b,c){var d,e,f,g;g=b.up("window").down("form").getRecord();this.lookupReference("parameters").removeAll();if((c=Ext.getStore("KnownCommands").getById(c))&&c.get("parameters"))for(e=c.get("parameters"),c=0;c<e.length;c++){f=new Traccar.model.KnownAttribute(e[c]);d=Ext.clone(this.defaultFieldConfig);d.key=f.get("key"); d.fieldLabel=f.get("name");g.get("attributes")&&(d.value=g.get("attributes")[f.get("key")]);d.disabled=b.isDisabled();switch(f.get("valueType")){case "number":d.xtype="customNumberField";void 0!==f.get("allowDecimals")?d.allowDecimals=f.get("allowDecimals"):d.allowDecimals=!0;d.dataType=f.get("dataType");d.maxValue=f.get("maxValue");d.minValue=f.get("minValue");break;case "boolean":d.xtype="checkboxfield";d.inputValue=!0;d.uncheckedValue=!1;break;default:"timezone"===f.get("dataType")?(d.xtype="combobox", d.queryMode="local",d.displayField="key",d.editable=!1,d.store="AllTimezones"):d.xtype="textfield"}this.lookupReference("parameters").add(d)}},fillAttributes:function(b){var c,d,e={};b=b.up("window").down("form");b.updateRecord();c=b.getRecord();d=this.lookupReference("parameters").items.items;for(b=0;b<d.length;b++)e[d[b].key]=d[b].getValue();c.set("attributes",e)},onSaveClick:function(b){this.fillAttributes(b);this.callParent(arguments)},onValidityChange:function(b,c){this.lookupReference("saveButton").setDisabled(!c)}}); Ext.define("Traccar.view.permissions.BaseController",{extend:Ext.app.ViewController,alias:"controller.base",init:function(){var b={},c,d;b[this.getView().baseObjectName]=this.getView().baseObject;c=this.getView().linkStoreName;d=this.getView().storeName;c="undefined"===typeof c?d:c;console.log(c);this.getView().setStore(Ext.getStore(d));this.getView().getStore().load({scope:this,callback:function(){Ext.create("Traccar.store."+c).load({params:b,scope:this,callback:function(b,c,d){console.log("Selected records "+ b.length);if(d)for(c=0;c<b.length;c++)console.log(b[c].getId()+" "+b[c]),d=this.getView().getStore().getById(b[c].getId()),this.getView().getSelectionModel().select(d,!0,!0)}})}})},onBeforeSelect:function(b,c){var d={};d[this.getView().baseObjectName]=this.getView().baseObject;d[this.getView().linkObjectName]=c.getId();console.log("Select"+Ext.util.JSON.encode(d));Ext.Ajax.request({scope:this,url:"api/permissions",jsonData:Ext.util.JSON.encode(d),callback:function(d,f,g){f||(b.deselect(c,!0),Traccar.app.showError(g))}})}, onBeforeDeselect:function(b,c){var d={};d[this.getView().baseObjectName]=this.getView().baseObject;d[this.getView().linkObjectName]=c.getId();console.log("DeSelect"+Ext.util.JSON.encode(d));Ext.Ajax.request({scope:this,method:"DELETE",url:"api/permissions",jsonData:Ext.util.JSON.encode(d),callback:function(d,f,g){f||(b.select(c,!0,!0),Traccar.app.showError(g))}})}}); Ext.define("Traccar.view.permissions.Base",{extend:Traccar.view.GridPanel,controller:"base",selModel:{selType:"checkboxmodel",checkOnly:!0,showHeaderCheckbox:!0},listeners:{beforedeselect:"onBeforeDeselect",beforeselect:"onBeforeSelect"}}); Ext.define("Traccar.view.permissions.SavedCommands",{extend:Traccar.view.permissions.Base,xtype:"linkSavedCommandsView",columns:{items:[{text:Strings.sharedDescription,dataIndex:"description",flex:1,minWidth:Traccar.Style.columnWidthNormal,filter:"string"},{text:Strings.sharedType,dataIndex:"type",flex:1,minWidth:Traccar.Style.columnWidthNormal,filter:{type:"list",idField:"type",labelField:"name",store:"AllCommandTypes"},renderer:Traccar.AttributeFormatter.getFormatter("commandType")},{text:Strings.notificationSms, dataIndex:"textChannel",flex:1,minWidth:Traccar.Style.columnWidthNormal,filter:"boolean"}]}}); Ext.define("Traccar.view.dialog.SendCommandController",{extend:Traccar.view.dialog.SavedCommandController,alias:"controller.sendCommand",onSendClick:function(b){this.fillAttributes(b);b=b.up("window").down("form").getRecord();Ext.Ajax.request({scope:this,url:"api/commands/send",jsonData:b.getData(),callback:this.onSendResult})},onValidityChange:function(b,c){this.lookupReference("sendButton").setDisabled(!c||null===this.lookupReference("commandsComboBox").getValue())},onTextChannelChange:function(b, c){b=this.lookupReference("commandType").getStore();b.getProxy().setExtraParam("textChannel",c);b.reload()},onCommandSelect:function(b){var c,d=b.getStore().getById(b.getValue());d.set("deviceId",this.getView().deviceId);c=b.up("window").down("form");b=c.getRecord();c.loadRecord(d);if(b&&d.get("type")===b.get("type"))this.onTypeChange(this.lookupReference("commandType"),d.get("type"));this.lookupReference("newCommandFields").setDisabled(0!==d.getId());this.lookupReference("sendButton").setDisabled(0=== d.getId())},onSendResult:function(b,c,d){c?(this.closeView(),Traccar.app.showToast(202===d.status?Strings.commandQueued:Strings.commandSent)):Traccar.app.showError(d)},closeView:function(){this.lookupReference("commandsComboBox").getStore().removeAll();this.callParent(arguments)}}); Ext.define("Traccar.view.dialog.SendCommand",{extend:Traccar.view.dialog.Base,controller:"sendCommand",title:Strings.commandTitle,items:[{xtype:"combobox",reference:"commandsComboBox",fieldLabel:Strings.deviceCommand,displayField:"description",valueField:"id",store:"DeviceCommands",queryMode:"local",editable:!1,allowBlank:!1,listeners:{select:"onCommandSelect"}},{xtype:"form",listeners:{validitychange:"onValidityChange"},items:[{xtype:"fieldset",reference:"newCommandFields",disabled:!0,items:[{xtype:"checkboxfield", name:"textChannel",reference:"textChannelCheckBox",inputValue:!0,uncheckedValue:!1,fieldLabel:Strings.notificationSms,listeners:{change:"onTextChannelChange"}},{xtype:"combobox",name:"type",reference:"commandType",fieldLabel:Strings.sharedType,store:"CommandTypes",displayField:"name",valueField:"type",editable:!1,allowBlank:!1,listeners:{change:"onTypeChange"}},{xtype:"fieldcontainer",reference:"parameters"}]}]}],buttons:[{xtype:"tbfill"},{glyph:"xf093@FontAwesome",tooltip:Strings.sharedSend,tooltipType:"title", minWidth:0,disabled:!0,reference:"sendButton",handler:"onSendClick"},{glyph:"xf00d@FontAwesome",tooltip:Strings.sharedCancel,tooltipType:"title",minWidth:0,handler:"closeView"}]}); Ext.define("Traccar.view.dialog.BaseEdit",{extend:Traccar.view.dialog.Base,controller:"baseEdit",autoHeight:!0,autoSizeColumn:!0,minWidth:400,buttons:[{text:Strings.sharedAttributes,handler:"showAttributesView"},{xtype:"tbfill"},{glyph:"xf00c@FontAwesome",tooltip:Strings.sharedSave,tooltipType:"title",minWidth:0,handler:"onSaveClick"},{glyph:"xf00d@FontAwesome",tooltip:Strings.sharedCancel,tooltipType:"title",minWidth:0,handler:"closeView"}]}); Ext.define("Traccar.view.ClearableComboBox",{extend:Ext.form.field.ComboBox,xtype:"clearableComboBox",editable:!1,triggers:{clear:{cls:"iconCls: x-fa fa-times",handler:function(b){b.clearValue()}}}});Ext.define("Traccar.view.dialog.DeviceController",{extend:Traccar.view.dialog.BaseEditController,alias:"controller.device",init:function(){Traccar.app.getUser().get("admin")&&this.lookupReference("disabledField").setHidden(!1)}}); Ext.define("Traccar.view.dialog.Device",{extend:Traccar.view.dialog.BaseEdit,layout:"center",controller:"device",title:Strings.sharedDevice,items:{xtype:"form",items:[{xtype:"fieldset",title:Strings.sharedRequired,items:[{xtype:"textfield",name:"name",fieldLabel:Strings.sharedName,allowBlank:!1},{xtype:"textfield",name:"uniqueId",fieldLabel:Strings.deviceIdentifier,allowBlank:!1}]},{xtype:"fieldset",title:Strings.sharedExtra,collapsible:!0,collapsed:!0,items:[{xtype:"textfield",name:"phone",fieldLabel:Strings.sharedPhone}, {xtype:"textfield",name:"model",fieldLabel:Strings.deviceModel},{xtype:"textfield",name:"contact",fieldLabel:Strings.deviceContact},{xtype:"combobox",name:"category",fieldLabel:Strings.deviceCategory,store:"DeviceImages",queryMode:"local",displayField:"name",valueField:"key",editable:!1,listConfig:{getInnerTpl:function(){return'\x3ctable\x3e\x3ctr valign\x3d"middle" \x3e\x3ctd\x3e\x3cdiv align\x3d"center" style\x3d"width:40px;height:40px;" \x3e{[new XMLSerializer().serializeToString(Traccar.DeviceImages.getImageSvg(Traccar.Style.mapColorOnline, false, 0, values.key))]}\x3c/div\x3e\x3c/td\x3e\x3ctd\x3e{name}\x3c/td\x3e\x3c/tr\x3e\x3c/table\x3e'}}}, {xtype:"checkboxfield",inputValue:!0,uncheckedValue:!1,name:"disabled",fieldLabel:Strings.sharedDisabled,hidden:!0,reference:"disabledField"},{xtype:"checkboxfield",inputValue:!0,uncheckedValue:!1,name:"allgeofencesenabled",fieldLabel:Strings.deviceAllGeoFencesEnabled}]}]}}); Ext.define("Traccar.view.permissions.Geofences",{extend:Traccar.view.permissions.Base,xtype:"linkGeofencesView",columns:{items:[{text:Strings.sharedName,dataIndex:"name",flex:1,minWidth:Traccar.Style.columnWidthNormal,filter:"string"},{text:Strings.sharedCalendar,dataIndex:"calendarId",flex:1,minWidth:Traccar.Style.columnWidthNormal,hidden:!0,filter:{type:"list",labelField:"name",store:"AllCalendars"},renderer:Traccar.AttributeFormatter.getFormatter("calendarId")}]}}); Ext.define("Traccar.view.permissions.ComputedAttributes",{extend:Traccar.view.permissions.Base,xtype:"linkComputedAttributesView",columns:{items:[{text:Strings.sharedDescription,dataIndex:"description",flex:1,minWidth:Traccar.Style.columnWidthNormal,filter:"string"},{text:Strings.sharedAttribute,dataIndex:"attribute",flex:1,minWidth:Traccar.Style.columnWidthNormal,filter:{type:"list",labelField:"name",store:"PositionAttributes"},renderer:function(b){return Ext.getStore("PositionAttributes").getAttributeName(b)}}]}}); Ext.define("Traccar.view.permissions.Drivers",{extend:Traccar.view.permissions.Base,xtype:"linkDriversView",columns:{items:[{text:Strings.sharedName,dataIndex:"name",flex:1,minWidth:Traccar.Style.columnWidthNormal,filter:"string"},{text:Strings.deviceIdentifier,dataIndex:"uniqueId",flex:1,minWidth:Traccar.Style.columnWidthNormal,filter:"string"}]}}); Ext.define("Traccar.model.Device",{extend:Ext.data.Model,identifier:"negative",fields:[{name:"id",type:"int"},{name:"name",type:"string"},{name:"uniqueId",type:"string"},{name:"phone",type:"string",allowNull:!0},{name:"model",type:"string",allowNull:!0},{name:"contact",type:"string",allowNull:!0},{name:"category",type:"string",allowNull:!0},{name:"status",type:"string",allowNull:!0},{name:"lastUpdate",type:"date",dateFormat:"c"},{name:"disabled",type:"boolean"},{name:"allgeofencesenabled",type:"boolean"}, {name:"geofenceIds"},{name:"attributes"}],proxy:{type:"rest",api:{create:"api/devices",read:"api/devices",update:"api/devices",destroy:"api/devices"},writer:{writeAllFields:!0}}});Ext.define("Traccar.model.Command",{extend:Ext.data.Model,identifier:"negative",fields:[{name:"id",type:"int"},{name:"description",type:"string"},{name:"deviceId",type:"int"},{name:"type",type:"string"},{name:"textChannel",type:"boolean"},{name:"attributes"}]}); Ext.define("Traccar.view.edit.DevicesController",{extend:Traccar.view.edit.ToolbarController,alias:"controller.devices",config:{listen:{controller:{"*":{selectreport:"selectReport"},root:{selectdevice:"selectDevice"},map:{selectdevice:"selectDevice",deselectfeature:"deselectFeature"}},store:{"#Devices":{update:"onUpdateDevice",create:"onUpdateDevice"}}}},objectModel:"Traccar.model.Device",objectDialog:"Traccar.view.dialog.Device",removeTitle:Strings.sharedDevice,init:function(){var b=this,c,d;d=Traccar.app.getPreference("deviceReadonly", !1)&&!Traccar.app.getUser().get("admin");c=Traccar.app.getPreference("readonly",!1)&&!Traccar.app.getUser().get("admin");this.lookupReference("toolbarAddButton").setDisabled(c||d);this.lookupReference("toolbarDeviceMenu").setHidden(c||d);setInterval(function(){b.getView()&&b.getView().getView().refresh()},Traccar.Style.refreshPeriod)},onCommandClick:function(){var b,c,d;b=this.getView().getSelectionModel().getSelection()[0].get("id");c=Ext.create("Traccar.view.dialog.SendCommand");c.deviceId=b;d= c.lookupReference("commandsComboBox").getStore();d.getProxy().setExtraParam("deviceId",b);Traccar.app.getPreference("limitCommands",!1)||d.add({id:0,description:Strings.sharedNew});d.load({addRecords:!0});d=c.lookupReference("commandType").getStore();d.getProxy().setExtraParam("deviceId",b);d.load();c.show()},updateButtons:function(b){var c,d,e;d=Traccar.app.getPreference("deviceReadonly",!1)&&!Traccar.app.getUser().get("admin");c=Traccar.app.getPreference("readonly",!1)&&!Traccar.app.getUser().get("admin"); e=0===b.length;this.lookupReference("toolbarEditButton").setDisabled(e||c||d);this.lookupReference("toolbarRemoveButton").setDisabled(e||c||d);c=this.lookupReference("toolbarDeviceMenu");c.device=e?null:b[0];c.setDisabled(e)},onSelectionChange:function(b,c){this.updateButtons(c);var d=[];Ext.each(c,function(b){d.push(b.id)});0<c.length?(this.fireEvent("selectdevice",c[0],!0),this.fireEvent("devicesids",d)):this.fireEvent("deselectfeature")},selectDevice:function(b){this.getView().getSelectionModel().select([b], !1,!0);this.updateButtons(this.getView().getSelectionModel().getSelected().items);this.getView().getView().focusRow(b)},selectReport:function(b){void 0!==b&&this.deselectFeature()},onUpdateDevice:function(){this.updateButtons(this.getView().getSelectionModel().getSelected().items)},deselectFeature:function(){this.getView().getSelectionModel().deselectAll()}}); Ext.define("Traccar.view.ArrayListFilter",{extend:Ext.grid.filters.filter.List,alias:"grid.filter.arraylist",type:"arraylist",constructor:function(b){this.callParent([b]);this.filter.setFilterFn(function(b){var d,e;d=b.get(this.getProperty());e=this.getValue();if(Ext.isArray(d))for(b=0;b<d.length;b++){if(-1!==e.indexOf(d[b]))return!0}else if(-1!==e.indexOf(d))return!0;return!1})}}); Ext.define("Traccar.view.grids.BaseController",{extend:Ext.app.ViewController,alias:"controller.gridBase",init:function(b){var c;storeName=this.getView().storeName;c=this.getView();c.setStore(Ext.getStore(storeName));c.getStore().load();(b=c.baseModel.get(c.propertyName))&&b.forEach(function(b){c.getSelectionModel().select(c.getStore().find("id",b),!0)})},onBeforeSelect:function(b,c){},onBeforeDeselect:function(b,c){},onSaveGrid:function(b,c){var d=[],e=this.getView();c=e.getSelectionModel().getSelection(); Ext.each(c,function(b){d.push(b.id)});e.baseStore.getById(e.baseModel.get("id")).set(e.propertyName,d);e.baseStore.sync({failure:function(b){e.baseStore.rejectChanges();Traccar.app.showError(b.exceptions[0].getError().response)},success:function(c,d){e.baseStore.reload();b.up("window").close()}})}}); Ext.define("Traccar.view.grids.Base",{extend:Traccar.view.GridPanel,controller:"gridBase",selModel:{selType:"checkboxmodel",checkOnly:!0,showHeaderCheckbox:!0},listeners:{beforedeselect:"onBeforeDeselect",beforeselect:"onBeforeSelect"},tbar:{items:[{handler:"onSaveGrid",glyph:"xf0c7@FontAwesome",tooltip:Strings.sharedSave,tooltipType:"title"}]}}); Ext.define("Traccar.view.grids.Geofences",{extend:Traccar.view.grids.Base,xtype:"linkGeofenceGrid",columns:{items:[{text:Strings.sharedName,dataIndex:"name",flex:1,minWidth:Traccar.Style.columnWidthNormal,filter:"string"}]}}); Ext.define("Traccar.view.grids.Notifications",{extend:Traccar.view.grids.Base,xtype:"linkNotificationGrid",columns:{items:[{text:Strings.sharedName,dataIndex:"name",filter:"string",flex:3},{text:Strings.notificationType,dataIndex:"type",flex:4,renderer:function(b){return Traccar.app.getEventString(b)},filter:{type:"list",idField:"type",labelField:"name",store:"AllNotificationTypes"}},{text:Strings.notificationAlways,dataIndex:"always",renderer:Traccar.AttributeFormatter.getFormatter("always"),filter:"boolean", flex:2},{text:Strings.notificationWeb,dataIndex:"web",renderer:Traccar.AttributeFormatter.getFormatter("web"),filter:"boolean",flex:2},{text:Strings.notificationMail,dataIndex:"mail",renderer:Traccar.AttributeFormatter.getFormatter("mail"),filter:"boolean",flex:2}]}}); Ext.define("Traccar.view.permissions.Notifications",{extend:Traccar.view.permissions.Base,xtype:"linkNotificationsView",columns:{items:[{text:Strings.notificationType,dataIndex:"type",flex:2,renderer:function(b){return Traccar.app.getEventString(b)},filter:{type:"list",idField:"type",labelField:"name",store:"AllNotificationTypes"}},{text:Strings.notificationAlways,dataIndex:"always",flex:1,minWidth:Traccar.Style.columnWidthNormal,renderer:Traccar.AttributeFormatter.getFormatter("always"),filter:"boolean"}, {text:Strings.notificationWeb,dataIndex:"web",flex:1,minWidth:Traccar.Style.columnWidthNormal,renderer:Traccar.AttributeFormatter.getFormatter("web"),filter:"boolean"},{text:Strings.notificationMail,dataIndex:"mail",flex:1,minWidth:Traccar.Style.columnWidthNormal,renderer:Traccar.AttributeFormatter.getFormatter("mail"),filter:"boolean"}]}}); Ext.define("Traccar.view.dialog.SelectDeviceController",{extend:Ext.app.ViewController,alias:"controller.selectDevice",onSaveClick:function(b){var c,d;c=this.lookupReference("deviceField").getValue();d=this.getView().record.data;Ext.Ajax.request({url:"api/attributes/computed/test?deviceId\x3d"+c,method:"POST",jsonData:Ext.util.JSON.encode(d),callback:function(b,c,d){c?Ext.Msg.alert(Strings.sharedInfoTitle,d.responseText||d.statusText):Traccar.app.showError(d)}});b.up("window").close()},onDeviceChange:function(b, c){this.lookupReference("saveButton").setDisabled(null===c)}}); Ext.define("Traccar.view.dialog.SelectDevice",{extend:Traccar.view.dialog.Base,controller:"selectDevice",title:Strings.sharedDevice,items:{xtype:"form",items:[{xtype:"combobox",reference:"deviceField",store:"Devices",queryMode:"local",displayField:"name",valueField:"id",editable:!1,listeners:{change:"onDeviceChange"}}]},buttons:[{glyph:"xf00c@FontAwesome",reference:"saveButton",tooltip:Strings.sharedSave,tooltipType:"title",minWidth:0,handler:"onSaveClick",disabled:!0},{glyph:"xf00d@FontAwesome", tooltip:Strings.sharedCancel,tooltipType:"title",minWidth:0,handler:"closeView"}]}); Ext.define("Traccar.view.dialog.ComputedAttributeController",{extend:Traccar.view.dialog.BaseEditController,alias:"controller.computedAttribute",onAttributeChange:function(b,c){(b=Ext.getStore("PositionAttributes").getById(c))?(this.getView().lookupReference("typeComboField").setValue(b.get("valueType")),this.getView().lookupReference("typeComboField").setReadOnly(!0)):this.getView().lookupReference("typeComboField").setReadOnly(!1)},onCheckClick:function(b){var c;c=Ext.create("Traccar.view.dialog.SelectDevice"); b=b.up("window").down("form");b.updateRecord();c.record=b.getRecord();c.show()}}); Ext.define("Traccar.view.dialog.ComputedAttribute",{extend:Traccar.view.dialog.BaseEdit,controller:"computedAttribute",title:Strings.sharedComputedAttribute,items:{xtype:"form",items:[{xtype:"textfield",name:"description",fieldLabel:Strings.sharedDescription},{xtype:"combobox",name:"attribute",fieldLabel:Strings.sharedAttribute,store:"PositionAttributes",displayField:"name",valueField:"key",listeners:{change:"onAttributeChange"}},{xtype:"textareafield",name:"expression",fieldLabel:Strings.sharedExpression, allowBlank:!1},{xtype:"combobox",name:"type",reference:"typeComboField",store:"AttributeValueTypes",fieldLabel:Strings.sharedType,displayField:"name",valueField:"id",editable:!1}]},buttons:[{glyph:"xf128@FontAwesome",tooltip:Strings.sharedCheckComputedAttribute,tooltipType:"title",minWidth:0,handler:"onCheckClick"},{glyph:"xf00c@FontAwesome",tooltip:Strings.sharedSave,tooltipType:"title",minWidth:0,handler:"onSaveClick"},{glyph:"xf00d@FontAwesome",tooltip:Strings.sharedCancel,tooltipType:"title", minWidth:0,handler:"closeView"}]});Ext.define("Traccar.model.ComputedAttribute",{extend:Ext.data.Model,identifier:"negative",fields:[{name:"id",type:"int"},{name:"description",type:"string"},{name:"type",type:"string"},{name:"attribute",type:"string"},{name:"expression",type:"string"}]}); Ext.define("Traccar.view.edit.ComputedAttributesController",{extend:Traccar.view.edit.ToolbarController,alias:"controller.computedAttributes",objectModel:"Traccar.model.ComputedAttribute",objectDialog:"Traccar.view.dialog.ComputedAttribute",removeTitle:Strings.sharedComputedAttribute}); Ext.define("Traccar.view.edit.ComputedAttributes",{extend:Traccar.view.GridPanel,xtype:"computedAttributesView",controller:"computedAttributes",store:"ComputedAttributes",tbar:{xtype:"editToolbar"},listeners:{selectionchange:"onSelectionChange"},columns:{defaults:{flex:1,minWidth:Traccar.Style.columnWidthNormal},items:[{text:Strings.sharedDescription,dataIndex:"description",filter:"string"},{text:Strings.sharedAttribute,dataIndex:"attribute",filter:{type:"list",labelField:"name",store:"PositionAttributes"}, renderer:function(b){return Ext.getStore("PositionAttributes").getAttributeName(b)}},{text:Strings.sharedExpression,dataIndex:"expression"},{text:Strings.sharedType,dataIndex:"type",filter:{type:"list",labelField:"name",store:"AttributeValueTypes"},renderer:function(b){var c=Ext.getStore("AttributeValueTypes").getById(b);return c?c.get("name"):b}}]}}); Ext.define("Traccar.view.DeviceMenuController",{extend:Ext.app.ViewController,alias:"controller.deviceMenu",config:{listen:{controller:{"*":{devicesids:"selectDevicesIds"}}}},devicesSelected:null,init:function(){},onGeofencesClick:function(b,c,d){this.getView().up().device.data.allgeofencesenabled?alert(Strings.deviceGeofenceNotEditable):Ext.create("Traccar.view.BaseWindow",{title:Strings.sharedGeofence,items:{xtype:"linkGeofenceGrid",baseStore:Ext.getStore("Devices"),baseModel:this.getView().up().device, storeName:"Geofences",propertyName:"geofences"}}).show()},selectDevicesIds:function(b){this.devicesSelected=b},onNotificationsClick:function(){Ext.create("Traccar.view.BaseWindow",{title:Strings.sharedNotifications,items:{xtype:"linkNotificationGrid",baseStore:Ext.getStore("Devices"),baseModel:this.getView().up().device,storeName:"Notifications",propertyName:"notifications"}}).show()},onComputedAttributesClick:function(){Ext.create("Traccar.view.BaseWindow",{title:Strings.sharedComputedAttributes, items:{xtype:"linkComputedAttributesView",baseObjectName:"deviceId",linkObjectName:"attributeId",storeName:"ComputedAttributes",baseObject:this.getView().up("deviceMenu").device.getId()}}).show()},onDriversClick:function(){Ext.create("Traccar.view.BaseWindow",{title:Strings.sharedDrivers,items:{xtype:"linkDriversView",baseObjectName:"deviceId",linkObjectName:"driverId",storeName:"Drivers",baseObject:this.getView().up("deviceMenu").device.getId()}}).show()},onCommandsClick:function(){Ext.create("Traccar.view.BaseWindow", {title:Strings.sharedSavedCommands,items:{xtype:"linkSavedCommandsView",baseObjectName:"deviceId",linkObjectName:"commandId",storeName:"Commands",baseObject:this.getView().up("deviceMenu").device.getId()}}).show()},onDeviceDistanceClick:function(){var b,c=Ext.create("Traccar.view.dialog.DeviceDistance");c.deviceId=this.getView().up("deviceMenu").device.getId();(b=Ext.getStore("LatestPositions").findRecord("deviceId",c.deviceId,0,!1,!1,!0))&&c.lookupReference("totalDistance").setValue(b.get("attributes").totalDistance); c.show()},onChangeOwnerClick:function(){Ext.ComponentQuery.query("#changeObjectOwnerWindowId").forEach(function(b){b.close()});Ext.create("Traccar.view.BaseWindow",{title:"Chan