
namespace("userSmarts.sx");namespace("userSmarts.sx");$namespace.Plugin=Class.create(userSmarts.runtime.Activator);$prototype.initialize=function(superClass,properties){superClass.call(this,properties);userSmarts.sx.Plugin.instance=this;};$namespace.Plugin.getDefault=function(){return userSmarts.sx.Plugin.instance;};$prototype.start=function(context){var layer=this.getAlertLayer();this.alertLayerServiceRef=context.registerService("userSmarts.maps.context.Layer",layer,{});layer=this.getFacilityLayer();this.facilityLayerServiceRef=context.registerService("userSmarts.maps.context.Layer",layer,{});layer=this.getEventLayer();this.eventLayerServiceRef=context.registerService("userSmarts.maps.context.Layer",layer,{});};$prototype.stop=function(context){this.alertLayerServiceRef.unregister();this.facilityLayerServiceRef.unregister();this.eventLayerServiceRef.unregister();};$namespace.Plugin.find=function(path){return userSmarts.sx.Plugin.getDefault().getBundleContext().getURI(path);};$prototype.getAlertLayer=function(){if(!this.alertLayer){var styles=[{name:"default",title:"default",legendURL:"pub/wms?request=GetLegendGraphic&service=WMS&version=1.1.1"+"&layer=alerts&width=172&height=128&format=image/gif"}];styles['current']=0;var server=new userSmarts.maps.context.Server({baseURL:'pub/wms?',url:"pub/wms?",title:'SX Alerts WMS',service:'WMS',version:'1.1.1'});this.alertLayer=new userSmarts.maps.context.Layer({server:server,name:"alerts",title:"Current Alerts",srs:'EPSG:4326',visible:true,transience:true,opacity:0.6,refreshProperties:{modified:1},styles:styles});}
return this.alertLayer;};$prototype.getAlertVectorLayer=function(){if(!this.alertVectorLayer){this.alertVectorLayer=new OpenLayers.Layer.Vector("Alerts");}
return this.alertVectorLayer;};$prototype.getFacilityLayer=function(){if(!this.facilityLayer){var styles=[{name:"default",title:"default",legendURL:"pub/wms?request=GetLegendGraphic&service=WMS&version=1.1.1"+"&layer=facilities&width=128&height=244&format=image/gif"}];styles['current']=0;var server=new userSmarts.maps.context.Server({baseURL:"pub/wms?",url:"pub/wms?",title:'SX Facilities WMS',service:'WMS',version:'1.1.1'});this.facilityLayer=new userSmarts.maps.context.Layer({server:server,name:"facilities",title:"Facilities",srs:'EPSG:4326',queryable:false,visible:false,transience:true,opacity:1.0,refreshProperties:{modified:1},styles:styles});}
return this.facilityLayer;};$prototype.getEventLayer=function(){if(!this.eventLayer){var server=new userSmarts.maps.context.Server({baseURL:"pub/wms?",url:'pub/wms?',title:'userSmarts WMS'});this.eventLayer=new userSmarts.maps.context.Layer({server:server,name:'events',title:'Events Layer',srs:'EPSG:4326',visible:false,transience:true,refreshProperties:{modified:1}});}
return this.eventLayer;};$namespace.Plugin.loadUser=function(id){var deferred=new Deferred();if(id){var user=new userSmarts.sx.model.users.pub.User();user.setURL("pub/users/"+id+".atom");var def=user.get();def.addCallback(function(u){var userName=u.getUserName();var fullName=u.getFullName();var groups=u.getGroups();u.dispose();var ps=userSmarts.runtime.Platform.getPropertyService();ps.setProperty("user","fullName",fullName);ps.setProperty("user","groups",groups);ps.setProperty("user","username",userName);deferred.callback(userName);});}else{deferred.callback(null);}
return deferred;};$namespace.Plugin.loadWorkspace=function(wid){var deferred=new Deferred();if(wid){var workspace=new userSmarts.sx.model.workspaces.pub.Workspace();workspace.setURL("pub/workspaces/"+wid+".atom");var def=workspace.get();def.addCallback(function(ws){var id=ws.getId();var title=ws.getTitle();var summary=ws.getSummary();var link=ws.getLink();var bbox=ws.getBoundingBox();var w=userSmarts.runtime.Platform.getWorkspace();setp(w,"id",id);setp(w,"label",title);setp(w,"description",summary);setp(w,"link",{rel:"alternate",href:link,title:title});setp(w,"aoi",bbox);var wlinks=[];var links=ws.getLinks();for(var rel in links){wlinks.push({rel:rel,href:links[rel],title:(rel=="defaultMap"?"Default Map":(rel=="maps"?"Maps":(rel=="reports"?"Reports":(rel=="situations"?"Situations":rel))))});}
setp(w,"links",wlinks);ws.dispose();var ps=userSmarts.runtime.Platform.getPropertyService();ps.setProperty("workspace","id",id);ps.setProperty("workspace","label",title);ps.setProperty("workspace","description",summary);ps.setProperty("workspace","aoi",bbox);ps.setProperty("workspace","link",link);deferred.callback(w);});}else{deferred.callback(null);}
return deferred;};$namespace.Plugin.isUserInRole=function(roleName){var result=false;var ps=userSmarts.runtime.Platform.getPropertyService();var groups=ps.getProperty("user","groups");if(groups){for(var i=0;i<groups.length;++i){if(groups[i]==roleName||groups[i]=="ADMIN"){result=true;break;}else if((roleName.indexOf("CREATE")==0&&groups[i]=="CREATE_*")||(roleName.indexOf("EDIT")==0&&groups[i]=="EDIT_*")||(roleName.indexOf("DELETE")==0&&groups[i]=="DELETE_*")){result=true;break;}}}
return result;};$namespace.Plugin.ROLE_OPTIONS=[{label:"Generic User",value:"USER"},{label:"Create Maps",value:"CREATE_MAP"},{label:"Create Layers",value:"CREATE_LAYER"},{label:"Create Situations",value:"CREATE_SITUATION"},{label:"Create Reports",value:"CREATE_REPORT"},{label:"Create Annotations",value:"CREATE_ANNOTATION"},{label:"Create Users",value:"CREATE_USER"},{label:"Create Workspaces",value:"CREATE_WORKSPACE"},{label:"Edit Maps",value:"EDIT_MAP"},{label:"Edit Layers",value:"EDIT_LAYER"},{label:"Edit Situations",value:"EDIT_SITUATION"},{label:"Edit Reports",value:"EDIT_REPORT"},{label:"Edit Annotations",value:"EDIT_ANNOTATION"},{label:"Edit Users",value:"EDIT_USER"},{label:"Edit Workspaces",value:"EDIT_WORKSPACE"},{label:"Delete Maps",value:"DELETE_MAP"},{label:"Delete Layers",value:"DELETE_LAYER"},{label:"Delete Situations",value:"DELETE_SITUATION"},{label:"Delete Reports",value:"DELETE_REPORT"},{label:"Delete Annotations",value:"DELETE_ANNOTATION"},{label:"Delete Users",value:"DELETE_USER"},{label:"Delete Workspaces",value:"DELETE_WORKSPACE"},{label:"Administrator",value:"ADMIN"},{label:"Create Any",value:"CREATE_*"},{label:"Edit Any",value:"EDIT_*"},{label:"Delete Any",value:"DELETE_*"}];$namespace.Plugin.ROLE_DATATYPE={uri:{namespaceURI:"http://www.usersmarts.com/sx/core/workspaces",prefix:"ws",localPart:"roles"},facets:{enumeration:userSmarts.sx.Plugin.ROLE_OPTIONS}};namespace("userSmarts.sx.management");namespace("userSmarts.sx.management");namespace("userSmarts.sx.management");$namespace.ApplicationLauncher=Class.create();$prototype.initialize=function(superClass,properties){setdefault(this,properties);};$prototype.launch=function(){this.loadUserInfo();};$prototype.loadUserInfo=function(){var ps=userSmarts.runtime.Platform.getPropertyService();var user=ps.getProperty("user","username");var def=userSmarts.sx.Plugin.loadUser(user);def.addCallback(bind(this.onUserLoaded,this));def.addErrback(function(e){alert("Error loading user information: "+e);});};$prototype.onUserLoaded=function(){var ps=userSmarts.runtime.Platform.getPropertyService();var workspaceId=ps.getProperty("workspace","id");this.loadWorkspace(workspaceId);};$prototype.loadWorkspace=function(workspaceId){if(workspaceId){userSmarts.runtime.Platform.runApplication(this.applicationId);}else{this.promptForWorkspace();}};$prototype.promptForWorkspace=function(){var dialog=new userSmarts.sx.model.workspaces.dialogs.WorkspaceChooserDialog();var def=dialog.open();def.addCallback(bind(this.onWorkspaceChosen,this));def.addErrback(function(e){alert("Error selecting workspace: "+e);});};$prototype.onWorkspaceChosen=function(workspaceId){if(workspaceId=="ADMIN"){userSmarts.runtime.Platform.runApplication("com.usersmarts.sx.management.app.application");}else if(workspaceId){var ps=userSmarts.runtime.Platform.getPropertyService();ps.setProperty("workspace","id",workspaceId);userSmarts.runtime.Platform.runApplication(this.applicationId);}};namespace("userSmarts.sx.management.app");namespace("userSmarts.sx.management.app");namespace("userSmarts.sx.management.app");$namespace.Application=Class.create();$prototype.run=function(args){var def=userSmarts.sx.Plugin.loadWorkspace("alertSmarts");def.addCallback(this.runWorkbench,this);};$prototype.shutdown=function(){var wb=userSmarts.ui.PlatformUI.workbench;if(wb){wb.close();}};$prototype.runWorkbench=function(){var advisor=new userSmarts.sx.management.app.WorkbenchAdvisor();var display=userSmarts.ui.PlatformUI.createDisplay();userSmarts.ui.PlatformUI.createAndRunWorkbench(display,advisor);};namespace("userSmarts.sx.management.app");$namespace.ActionBarAdvisor=Class.create(userSmarts.ui.application.ActionBarAdvisor);$prototype.initialize=function(superClass,configurer){superClass.call(this,configurer);};$prototype.fillCoolBar=function(coolBar){};namespace("userSmarts.sx.management.app");$namespace.SessionBar=Class.create(userSmarts.wt.widgets.Control);$prototype.initialize=function(superClass,properties){properties=setdefault(properties,{'class':'session-bar'});superClass.call(this,properties);};$prototype.update=function(){replaceChildNodes(this.node,DIV(null,A({href:"inplace.jsp"},"Exit")));};namespace("userSmarts.sx.management.app");$namespace.PerspectiveFilter=Class.create(Bean);$prototype.initialize=function(superClass,properties){superClass.call(this,properties);};$prototype.filter=function(item){var result=false;result=("userSmarts.sx.management.app.AdminPerspective"==item.id);return result;};namespace("userSmarts.sx.management.app");$namespace.WorkbenchWindowAdvisor=Class.create(userSmarts.ui.application.WorkbenchWindowAdvisor);$prototype.initialize=function(superClass,windowConfigurer){superClass.call(this,windowConfigurer);};$prototype.createActionBarAdvisor=function(actionBarConfigurer){return new userSmarts.sx.management.app.ActionBarAdvisor(actionBarConfigurer);};$prototype.postWindowOpen=function(){};$prototype.createWindowContents=function(shell){var window=this.getWindowConfigurer().getWindow();shell.setLayout(new userSmarts.wt.layout.RowLayout({type:"vertical"}));var display=shell.getDisplay();shell.setBounds(0,0,display.getWidth(),display.getHeight());var header=new userSmarts.wt.widgets.Composite({id:"page-header",parent:shell,layoutData:{height:"35px",width:"*"}});header.setLayout(new userSmarts.wt.layout.RowLayout({type:"horizontal"}));var perspectiveBar=new userSmarts.ui.PerspectiveBar({id:"perspectiveBar",parent:header,perspectiveFilter:new userSmarts.sx.management.app.PerspectiveFilter(),layoutData:{height:"100%",width:"50%"}});var sb=new userSmarts.sx.management.app.SessionBar({id:"sessionBar",parent:header,padding:{top:3,left:0,right:5,bottom:3},layoutData:{width:"50%",height:"100%"}});this.getWindowConfigurer().createPageComposite(shell);window.getPageComposite().setLayoutData({width:"100%",height:"*"});var sb=new userSmarts.wt.widgets.Control({id:"statusBar",parent:shell,layoutData:{height:"20px"}});shell.layout();};namespace("userSmarts.sx.management.app");$namespace.WorkbenchAdvisor=Class.create(userSmarts.ui.application.WorkbenchAdvisor,"init");$prototype.init=function(superClass){superClass.call(this);};$prototype.createWorkbenchWindowAdvisor=function(windowConfigurer){return new userSmarts.sx.management.app.WorkbenchWindowAdvisor(windowConfigurer);};$prototype.getInitialWindowPerspectiveId=function(){return"userSmarts.sx.management.app.AdminPerspective";};namespace("userSmarts.sx.management.app");$namespace.AdminPerspective=Class.create();$prototype.createInitialLayout=function(layout){layout.createBox("left",userSmarts.ui.PageLayout.ID_ROOT_BOX,{orientation:userSmarts.ui.BoxLayout.VERTICAL,width:'400',height:'100%'});layout.createBox("right",userSmarts.ui.PageLayout.ID_ROOT_BOX,{orientation:userSmarts.ui.BoxLayout.VERTICAL,width:'*',height:'100%'});var c1r1=layout.createFolder("c1r1","left",{width:'100%',height:'*'});var editorArea=layout.createFolder(userSmarts.ui.PageLayout.ID_EDITOR_AREA,"right",{width:'100%',height:'*'});c1r1.addView("userSmarts.sx.model.workspaces.views.WorkspacesView");};namespace("userSmarts.sx.model.alerts");namespace("userSmarts.sx.model.alerts");namespace("userSmarts.sx.model.alerts");$namespace.AlertController=Class.create();$prototype.initialize=function(superClass){};$prototype.setProperty=function(property,value){};$prototype.getProperty=function(property){if(property=="focus"){return this["focus"];}
return null;};$prototype.onAlertFocused=function(event){var id=event.newValue;this['focus']=id;signalp("alert","focus",id);};namespace("userSmarts.sx.model.alerts.views");namespace("userSmarts.sx.model.alerts.views");namespace("userSmarts.sx.model.alerts.views");$namespace.AlertsView=Class.create(userSmarts.ui.views.ListView);$prototype.initialize=function(superClass,desc){superClass.call(this,desc);this.model=new userSmarts.sx.model.alerts.models.AlertsModel({pageSize:50});connect(this.model,'modified',this,this.onListUpdated);this.selected=null;};$prototype.init=function(site){userSmarts.ui.views.ListView.prototype.init.call(this,site);var ps=userSmarts.runtime.Platform.getPropertyService();ps.connect("map","aoi",this,this.onAOIChange);connect(this.model,"populating",this,this.displayQueryingMessage);connect(this.model,"modified",this,this.displayListingMessage);};$prototype.contributeToActionBars=function(){var actionbars=this.getSite().getActionBars();var tbmgr=actionbars.getToolbarManager();var mbmgr=actionbars.getMenuBarManager();var action=new userSmarts.sx.model.alerts.actions.ConstrainAction({showText:true});tbmgr.add(action);mbmgr.add(action);action=new userSmarts.wt.action.Action({id:'zoomToAlertAction',text:"Zoom to Alert",toolTipText:'Zoom to selected alert',showText:true,run:bind(this.zoomToSelectedAlert,this),image:"image.alert.zoom.single"});tbmgr.add(action);mbmgr.add(action);mbmgr.add(new userSmarts.wt.action.HorizontalSeparator());userSmarts.ui.views.ListView.prototype.contributeToActionBars.call(this);};$prototype.setSelection=function(obj){this.setProperty("selected",obj);this.getMapLayer();var ps=userSmarts.runtime.Platform.getPropertyService();ps.setProperty("alert","selected",obj);};$prototype.onSelectionChange=function(event){var selection=event.newValue;if(selection){var id=selection.getId();if(id!=this.selected){this.setSelection(id);var geometry=selection.getWhere();if(geometry){this.selectedAlertAOI=geometry.getEnvelope();}}}else{this.setSelection(null);this.view=null;}};$prototype.onListUpdated=function(event){this.checkSelected();this.getMapLayer();};$prototype.getMapLayer=function(){var layer=userSmarts.sx.Plugin.getDefault().getAlertLayer();layer.server.url=layer.server.baseURL+"startIndex="+this.model.getStartIndex()+"&startPage="+this.model.getStartPage()+"&count="+this.model.getPageSize()+"&selected="+this.selected+"&useAnd="+this.model.getAndTerms()+"&q="+this.model.getKeywords().toString(" ")+"&requestId="+Math.random();var sortElement=this.model.getSortElement();if(sortElement){layer.server.url+="&sortElement="+sortElement+"&sortOrder="+this.model.getSortOrder();}
layer.setProperty("modified",true);return layer;};$prototype.checkSelected=function(){var present=false;if(this.selected){var rows=this.model.getRows();for(var i=0;i<rows.length;++i){var id=rows[i].getId();if(id==this.selected){present=true;this.list.select(rows[i]);}}}
if(!present){this.setSelection(null);this.selectedAlertAOI=null;}};$prototype.zoomToSelectedAlert=function(){if(this.selectedAlertAOI){var ps=userSmarts.runtime.Platform.getPropertyService();ps.setProperty("map","aoi",this.selectedAlertAOI);}else{alert("Must select an Alert from the list first!");}};$prototype.zoomToPageOfAlerts=function(){if(this.model&&this.model.bbox){var ps=userSmarts.runtime.Platform.getPropertyService();ps.setProperty("map","aoi",this.model.getBoundingBox());}};$prototype.onAOIChange=function(event){this.setAOI(event.newValue);};$prototype.setAOI=function(aoi){if(aoi&&this.model){this.model.setAOI(aoi);}};$prototype.displayQueryingMessage=function(){var slmgr=this.getSite().getActionBars().getStatusLineManager();slmgr.setMessage("Querying Alerts...");};$prototype.displayListingMessage=function(){var slmgr=this.getSite().getActionBars().getStatusLineManager();slmgr.setMessage("Listing Alerts...");};namespace("userSmarts.sx.model.alerts.models");namespace("userSmarts.sx.model.alerts.models");namespace("userSmarts.sx.model.alerts.models");$namespace.AlertsModel=Class.create(userSmarts.pub.atom.FeedModel);$prototype.initialize=function(superClass,properties){properties=setdefault(properties,{collection:new userSmarts.pub.atom.GeoCollection()});superClass.call(this,properties);this.addColumn(new userSmarts.pub.atom.EntryColumn({name:"title",index:0,order:true}));this.addColumn(new userSmarts.pub.atom.EntryColumn({label:"Event",name:"event",index:1,order:true}));this.addColumn(new userSmarts.pub.atom.EntryColumn({label:"Category",name:"category",index:2,order:true}));this.addColumn(new userSmarts.pub.atom.EntryColumn({label:"ETN",name:"etn",index:3,order:true}));this.addColumn(new userSmarts.pub.atom.EntryColumn({label:"Issued",name:"issued",index:4,order:false}));this.addColumn(new userSmarts.pub.atom.EntryColumn({label:"Expires",name:"expires",index:5,order:true}));this.addColumn(new userSmarts.pub.atom.EntryColumn({label:"Id",name:"id",index:6,order:true}));this.addColumn(new userSmarts.pub.atom.EntryColumn({name:"link",index:7,order:true,getLabel:function(r){var l=r.getLink("related");if(typeof(l)=="string"&&l.length>1){var span=SPAN({},A({href:l,target:"_blank"},"[link]"));connect(span,"onclick",function(evt){evt.stopPropagation();});return span;}}}));this.setSortElement(this.columns[5].name);this.setSortOrder(this.columns[5].order);var ps=userSmarts.runtime.Platform.getPropertyService();ps.connect("alerts","keywords",this,this.onKeywordChange);this.heartbeatFunc=bind(this.ping,this);this.heartbeatFunc();};$prototype.getImage=function(){return userSmarts.runtime.Platform.getTheme().getImage("image.alert");};$prototype.setAOI=function(aoi){if(!this.collection.getURL()){this.collection.setURL("pub/alerts.atom");}
this.setBoundingBox(aoi);};$prototype.onKeywordChange=function(event){var constraint=event.newValue;if(constraint){var keywords=constraint.keywords;var useAnd=constraint.useAnd;this.setKeywords(keywords);this.setAndTerms(useAnd);this.populate(0);}};$prototype.getColumnClassName=function(column,row){if(column.index==0){var evtNode=row.getExtension("event");if(evtNode&&evtNode.value){return evtNode.value+"-alert";}}
return null;};$prototype.ping=function(){if(this.collection.getURL()){this.populate(this.getOffset());}
this.heartbeat=setTimeout(this.heartbeatFunc,60000);};namespace("userSmarts.sx.model.alerts.actions");namespace("userSmarts.sx.model.alerts.actions");namespace("userSmarts.sx.model.alerts.actions");$namespace.ConstrainAction=Class.create(userSmarts.wt.action.StatefulAction);$prototype.initialize=function(superClass,properties){properties=setdefault(properties,{id:'constraintAlertsAction',text:"Constrain",checkedText:"Unconstrain",toolTipText:'Constrain alerts by keywords',image:"image.alert.constrain"});superClass.call(this,properties);};$prototype.run=function(){var keywords="";var useAnd=true;var ps=userSmarts.runtime.Platform.getPropertyService();var checked=this.isChecked();if(!checked){ps.setProperty("alerts","keywords",{keywords:[],useAnd:false});}else{var constraint=ps.getProperty("alerts","keywords")||{};var dialog=new userSmarts.sx.model.alerts.dialogs.KeywordsDialog({sep:" "});dialog.setKeywords(constraint.keywords);dialog.setMatchAll(constraint.useAnd);var deferred=dialog.open();deferred.addCallback(bind(this.onDialogClosed,this));}};$prototype.onDialogClosed=function(dialog){var ps=userSmarts.runtime.Platform.getPropertyService();if(dialog){ps.setProperty("alerts","keywords",{keywords:dialog.getKeywords(),useAnd:dialog.getMatchAll()});}else{this.setChecked(false);}};namespace("userSmarts.sx.model.alerts.dialogs");namespace("userSmarts.sx.model.alerts.dialogs");namespace("userSmarts.sx.model.alerts.dialogs");$namespace.KeywordsDialog=Class.create(userSmarts.wt.dialogs.CDialog);$prototype.initialize=function(superClass,properties){properties=setdefault(properties,{title:"Constrain Alerts By Keywords",width:300,height:225,modal:false,enableKeys:true,enableDrag:true,showClose:true,keywords:"",sep:",",matchAll:true});superClass.call(this,properties);};$prototype.createDialogArea=function(composite){composite.setLayout(new userSmarts.wt.layout.RowLayout({type:"vertical"}));new userSmarts.wt.forms.Text({parent:composite,layoutData:{width:"100%",height:"*"},value:"Enter keywords, separated by "+
(this.sep==" "?"spaces":"'"+this.sep+"'")+", to use in constraining search:"});this.keywordsField=new userSmarts.wt.forms.FieldControl({parent:composite,layoutData:{width:"100%",height:30},binding:new BeanPropertyBinding(this,'keywords')});new userSmarts.wt.forms.Text({parent:composite,layoutData:{width:"100%",height:"*"},value:"Basic alert keywords are: 'TOR', 'SVR', 'SMW', 'FFW', "+"'Earthquake', 'MOTION', and two-letter state abbreviations."});var ctrl=new userSmarts.wt.widgets.Control({parent:composite,layoutData:{width:"100%",height:50}});var input=INPUT({type:'checkbox'});input.checked=!this.matchAll;this.matchAllCheckbox=input;ctrl.getNode().appendChild(input);ctrl.getNode().appendChild(SPAN({'class':'form-text'},"Match any of these keywords?"));ctrl.getNode().appendChild(BR());ctrl.getNode().appendChild(SPAN({'class':'form-text'},"   (uncheck to match all)"));};$prototype.focus=function(){this.keywordsField.focus();};$prototype.setKeywords=function(keywords){if(keywords&&typeof(keywords.push)=="function"){this.keywords=keywords.toString(this.sep);}else if(typeof(keywords)=="string"){this.keywords=keywords;}};$prototype.getKeywords=function(){if(!this.keywords){return[];}
return this.keywords.split(this.sep);};$prototype.getMatchAll=function(){return!this.matchAllCheckbox.checked;};$prototype.setMatchAll=function(bool){this.matchAll=(bool===true||bool==="true");};$prototype.okPressed=function(){this.keywords=this.keywordsField.getValue();if(this.deferred){this.deferred.callback(this);this.deferred=null;}};namespace("userSmarts.sx.model.events");namespace("userSmarts.sx.model.events");namespace("userSmarts.sx.model.events.perspectives");namespace("userSmarts.sx.model.events.perspectives");namespace("userSmarts.sx.model.events.perspectives");$namespace.EventPerspective=function(){};$namespace.EventPerspective.prototype.createInitialLayout=function(layout){layout.createBox("left",userSmarts.ui.PageLayout.ID_ROOT_BOX,{orientation:userSmarts.ui.BoxLayout.VERTICAL,width:'400',height:'100%'});layout.createBox("right",userSmarts.ui.PageLayout.ID_ROOT_BOX,{orientation:userSmarts.ui.BoxLayout.VERTICAL,width:'*',height:'100%'});var c1r1=layout.createFolder("c1r1","left",{width:'100%',height:'*'});var editorArea=layout.createFolder(userSmarts.ui.PageLayout.ID_EDITOR_AREA,"right",{width:'100%',height:'*'});c1r1.addView("userSmarts.sx.model.events.views.EventsView");};namespace("userSmarts.sx.model.events.views");namespace("userSmarts.sx.model.events.views");namespace("userSmarts.sx.model.events.views");$namespace.EventsView=Class.create(userSmarts.ui.views.ListView);$prototype.initialize=function(superClass,properties){superClass.call(this,properties);this.listeners=[];this.model=new userSmarts.pub.atom.FeedModel({pageSize:50});this.model.addColumn(new userSmarts.pub.atom.EntryColumn({label:"Title",name:"title",order:true}));this.model.addColumn(new userSmarts.pub.atom.EntryColumn({name:"summary",order:true}));this.model.addColumn(new userSmarts.pub.atom.EntryColumn({label:"Last Modified",name:"updated",order:true,format:new DateFormat()}));this.model.addColumn(new userSmarts.pub.atom.EntryColumn({label:"Location",name:"where/placeName",order:true}));var workspace=userSmarts.runtime.Platform.getWorkspace();this.model.setSource(workspace.getLink("events").href);};$prototype.init=function(site){userSmarts.ui.views.ListView.prototype.init.call(this,site);this.listeners.push(connect(this.model,'modified',this,this.onModelUpdated));var context=userSmarts.sx.Plugin.getDefault().getBundleContext();this.eventServiceRef=context.registerService("userSmarts.event.EventHandler",this,{topics:["sx.events"]});};$prototype.contributeToActionBars=function(){var actionbars=this.getSite().getActionBars();var tbmgr=actionbars.getToolbarManager();var mbmgr=actionbars.getMenuBarManager();var action=new userSmarts.sx.model.events.actions.ZoomToEventAction();tbmgr.add(action);mbmgr.add(action);mbmgr.add(new userSmarts.wt.action.HorizontalSeparator());action=new userSmarts.sx.model.events.actions.CreateEventAction();tbmgr.add(action);mbmgr.add(action);action=new userSmarts.sx.model.events.actions.EditEventAction();tbmgr.add(action);mbmgr.add(action);action=new userSmarts.sx.model.events.actions.DeleteEventAction();mbmgr.add(action);mbmgr.add(new userSmarts.wt.action.HorizontalSeparator());userSmarts.ui.views.ListView.prototype.contributeToActionBars.call(this);};$prototype.setSelection=function(obj){this.setProperty("selected",obj);var ps=userSmarts.runtime.Platform.getPropertyService();ps.setProperty("sx.events","selected",obj);};$prototype.onSelectionChange=function(event){this.setSelection(event.newValue);};$prototype.onEventsChange=function(event){var property=event.propertyName;if(property=="created"||property=="deleted"){this.model.populate(this.model.getOffset());}
var slmgr=this.getSite().getActionBars().getStatusLineManager();slmgr.setMessage("Event "+property);};$prototype.handleEvent=function(event){var property=event.getProperty("type");if(property=="created"||property=="updated"||property=="deleted"){this.model.populate(this.model.getOffset());}};$prototype.onModelUpdated=function(event){this.checkSelected();this.getMapLayer();};$prototype.getSelectedId=function(){if(this.selected){return this.selected.getId();}
return"";}
$prototype.getMapLayer=function(){var workspace=userSmarts.runtime.Platform.getWorkspace();var layer=userSmarts.sx.Plugin.getDefault().getEventLayer();layer.server.url=layer.server.baseURL+"startIndex="+this.model.getStartIndex()+"&startPage="+this.model.getStartPage()+"&count="+this.model.getPageSize()+"&selected="+this.getSelectedId()+"&workspace="+workspace.id+"&random="+Math.random();layer.visible=true;layer.setProperty("modified",true);return layer;};$prototype.checkSelected=function(){var present=false;if(this.selected){var rows=this.model.getRows();for(var i=0;i<rows.length;++i){if(this.selected.equals(rows[i])){present=true;this.list.select(rows[i]);}}}
if(!present){this.setSelection(null);}};$prototype.dispose=function(){for(var i=this.listeners.length-1;i>=0;--i){disconnect(this.listeners[i]);this.listeners[i]=null;}
userSmarts.ui.views.ListView.prototype.dispose.call(this);};namespace("userSmarts.sx.model.events.editors");namespace("userSmarts.sx.model.events.editors");namespace("userSmarts.sx.model.events.editors");$namespace.EventEditor=Class.create(userSmarts.ui.MultiPageEditorPart);$prototype.initialize=function(superclass,properties){superclass.call(this,properties);};$prototype.init=function(site,input){userSmarts.ui.MultiPageEditorPart.prototype.init.call(this,site,input);this.loadedListener=connect(input,"loaded",this,this.onInputLoaded);this.updatedListener=connect(input,"updated",this,this.onInputUpdated);};$prototype.createPages=function(){this.input.load();};$prototype.createEventPages=function(){if(!this.hasPages()){this.addPage(new userSmarts.sx.model.events.editors.EventPageOne());this.addPage(new userSmarts.sx.model.events.editors.EventPageTwo());}};$prototype.doSave=function(){this.input.save();};$prototype.onInputLoaded=function(event){var success=event.newValue;if(success){if(!this.outer||!this.tabControl){this.createPartControl();}
this.createEventPages();this.outer.update();this.updateTab();var ps=userSmarts.runtime.Platform.getPropertyService();ps.setProperty("editor","initialized",this);}else{var wb=userSmarts.ui.PlatformUI.getWorkbench();var page=wb.getActiveWorkbenchWindow().getActivePage();page.closeEditor(this,false);}};$prototype.onInputUpdated=function(event){this.dirty=false;for(var p=0;p<this.pages.length;++p){this.pages[p].dirty=false;}
this.updateTab();};$prototype.contributeToActionBars=function(){var bars=this.getSite().getActionBars();var tbmgr=bars.getToolbarManager();var mbmgr=bars.getMenuBarManager();if(!this.saveEditorAction){this.saveEditorAction=new userSmarts.wt.action.SaveEditorAction({editor:this});if(userSmarts.sx.model.workspaces.Plugin!=undefined){if(userSmarts.sx.model.workspaces.Plugin.isUserInRole("EDIT_EVENT")){this.editable=true;tbmgr.add(this.saveEditorAction);mbmgr.add(this.saveEditorAction);}else{this.editable=false;}}else{this.editable=true;tbmgr.add(this.saveEditorAction);mbmgr.add(this.saveEditorAction);}}};$prototype.getMap=function(){return null;};$prototype.getViewContext=function(){return null;};$prototype.getViewContextModel=function(){return null;};$prototype.dispose=function(){if(this.loadedListener){disconnect(this.loadedListener);this.loadedListener=null;}
if(this.updatedListener){disconnect(this.updatedListener);this.updatedListener=null;}
userSmarts.ui.MultiPageEditorPart.prototype.dispose.call(this);};namespace("userSmarts.sx.model.events.editors");$namespace.EventEditorInput=Class.create(userSmarts.ui.EditorInput);$prototype.initialize=function(superClass,properties){superClass.call(this,properties);if(!this.event&&this.url){this.event=new userSmarts.sx.model.events.pub.Event({url:this.url});}else if(this.event&&!this.name){this.name=this.event.getTitle();}
this.createdCallback=bind(this.onCreated,this);this.savedCallback=bind(this.onUpdated,this);this.errback=bind(this.onError,this);}
$prototype.getEvent=function(){return this.event;};$prototype.equals=function(other){if(this.url){if(other.url){return this.url==other.url;}else if(other.event){return this.url==other.event.url;}}else if(this.event){if(other.event){return this.event.equals(other.event);}else if(other.url){return this.event.url==other.url;}}
return false;};$prototype.get=function(){return this.event.get();};$prototype.del=function(){return this.event.del();};$prototype.load=function(){if(!this.event.url){this.setDirty(true);this.setProperty("loaded",true);}else{var def=this.get();def.addCallback(bind(this.onEventLoaded,this));def.addErrback(this.errback);}};$prototype.onEventLoaded=function(eventObj){this.setProperty("loaded",true);};$prototype.save=function(){if(!this.event.url){var workspace=userSmarts.runtime.Platform.getWorkspace();var collURL=workspace.getLink("events").href;var collection=new userSmarts.pub.atom.GeoCollection({url:collURL});var def=collection.add(this.event);def.addCallback(this.createdCallback);def.addErrback(this.errback);}else{var def=this.event.put();def.addCallback(this.savedCallback);def.addErrback(handleResponseError);}};$prototype.onUpdated=function(){this.setDirty(false);var event=new userSmarts.event.Event("sx.events",{type:"updated",id:this.event.getId()});var context=userSmarts.sx.Plugin.getDefault().getBundleContext();var ref=context.getServiceReference("userSmarts.event.EventAdmin");var eventService=ref.getService();eventService.sendEvent(event);this.setProperty("updated",true);};$prototype.onCreated=function(entry){this.event.url=entry.getLink();this.event.setId(entry.getId());var collection=entry.getCollection();if(collection){collection.dispose();}
this.setDirty(false);var event=new userSmarts.event.Event("sx.events",{type:"created",id:this.event.getId()});var context=userSmarts.sx.Plugin.getDefault().getBundleContext();var ref=context.getServiceReference("userSmarts.event.EventAdmin");var eventService=ref.getService();eventService.sendEvent(event);this.setProperty("updated",true);};$prototype.onError=function(e){handleResponseError(e);this.setProperty("loaded",false);};namespace("userSmarts.sx.model.events.editors");$namespace.EventPageOne=Class.create(userSmarts.ui.EditorPart);$prototype.initialize=function(superclass,properties){superclass.call(this,properties);this.label="Overview";this.listeners=[];};$prototype.createPartControl=function(){if(!this.control){this.control=new userSmarts.wt.widgets.Composite({'class':'multi-editor-page',layoutData:{width:"100%",height:"100%"},padding:{top:10,left:10,right:10,bottom:10}});this.control.setLayout(new userSmarts.wt.layout.RowLayout({type:"vertical"}));var comp1=new userSmarts.wt.widgets.Composite({parent:this.control,layoutData:{width:"100%",height:50}});comp1.setLayout(new userSmarts.wt.layout.RowLayout({type:"horizontal"}));this.titleField=new userSmarts.wt.forms.FieldComposite({parent:comp1,layoutData:{width:"50%",height:"100%"},validator:null,binding:new BeanPropertyBinding(this.input.event,"title"),showLabelOnTop:true,title:"Title: "});this.typeField=new userSmarts.wt.forms.SelectComposite({parent:comp1,layoutData:{width:"50%",height:"100%"},datatype:{facets:{enumeration:[{label:"Generic Event",value:"urn:usersmarts:sx:event"}]}},binding:new BeanPropertyBinding(this.input.event.extensions["typeName"],"value"),showLabelOnTop:true,title:"Event Type"});var timeLabel=new userSmarts.wt.forms.Label({parent:this.control,layoutData:{width:"100%",height:25},margin:{top:5,left:0,right:0,bottom:0},value:"Date/Time: "});var time=this.input.event.getTime();if(!time){time=new userSmarts.sx.model.events.pub.Time();time.setStartTime(new Date());this.input.event.setTime(time);}
var startTime=time.getStartTime();var endTime=time&&time.isTimeRange()?time.getEndTime():null;this.timePeriod=new userSmarts.wt.widgets.TimePeriodComposite({parent:this.control,layoutData:{width:"100%",height:40},isRange:(time?time.isTimeRange():true),startTime:startTime,endTime:endTime});this.listeners.push(connect(this.timePeriod,"modified",this,this.onTimeUpdated));this.descField=new userSmarts.wt.forms.TextAreaComposite({parent:this.control,layoutData:{width:"50%",height:150},validator:null,binding:new BeanPropertyBinding(this.input.event,"summary"),showLabelOnTop:true,title:"Description: "});var contentsLabel=new userSmarts.wt.forms.Label({parent:this.control,value:"Contents:",layoutData:{width:"100%",height:20}});this.contentsControl=new userSmarts.wt.widgets.RichText({parent:this.control,layoutData:{width:"100%",height:"*"},border:{style:"solid",top:1,left:1,right:1,bottom:1},binding:new BeanPropertyBinding(this,"content")});}
return this.control;};$prototype.updateControl=function(){};$prototype.getContent=function(){var event=this.getEditorInput().getEvent();return event.getContent();};$prototype.setContent=function(value){var event=this.getEditorInput().getEvent();event.setContent(value);event.setContentType("html");};$prototype.contributeToActionBars=function(tbmgr){if(!this.saveEditorAction){this.saveEditorAction=new userSmarts.wt.action.Action({id:'com.usersmarts.sx.model.events.editors.save',text:'Save',toolTipText:'Save Event',image:"image.save",run:bind(this.doSave,this)});}
if(userSmarts.sx.Plugin.isUserInRole("EDIT_EVENT")){this.editable=true;tbmgr.add(this.saveEditorAction);}else{this.editable=false;}};$prototype.onInputChange=function(event){this.setProperty("dirty",true);};$prototype.onTimeUpdated=function(){var time=this.input.event.getTime();if(!time){time=new userSmarts.sx.model.events.pub.Time();this.input.event.setTime(time);}
var sd=this.timePeriod.getStartTime();time.setStartTime(sd);if(this.timePeriod.isTimeRange()){var ed=this.timePeriod.getEndTime();time.isRange=true;time.setEndTime(ed);}else{time.isRange=false;}
this.setProperty("dirty",true);};$prototype.doSave=function(){this.input.save();this.setProperty("dirty",false);};$prototype.onEditorChange=function(event){this.contentsControl.setEnabled(false);};$prototype.onPerspectiveChange=function(event){this.contentsControl.setEnabled(false);};$prototype.dispose=function(){for(var i=0;i<this.listeners.length;++i){disconnect(this.listeners[i]);this.listeners[i]=null;}
this.listeners=null;userSmarts.ui.EditorPart.prototype.dispose.call(this);};namespace("userSmarts.sx.model.events.editors");$namespace.EventPageTwo=Class.create(userSmarts.ui.EditorPart);$prototype.initialize=function(superclass,properties){superclass.call(this,properties);this.label="Location";};$prototype.createPartControl=function(){if(!this.control){this.control=new userSmarts.sx.model.events.editors.EventMap({layoutData:{width:"100%",height:"100%"},mapOptions:{maxExtent:new OpenLayers.Bounds(-180,0,-40,90),restrictedExtent:new OpenLayers.Bounds(-180,-90,180,90)},center:new OpenLayers.LonLat(-95.0,38.5),zoom:3});this.addedListener=connect(this.control,"featureAdded",this,this.onFeatureAdded);this.removedListener=connect(this.control,"featureRemoved",this,this.onFeatureRemoved);this.enabledListener=connect(this.control,"enabled",this,this.displayGeometries);}
return this.control;};$prototype.contributeToActionBars=function(tbmgr){var action=new userSmarts.geo.GeocodeAction({out:bind(this.displayGeocodedResult,this)});tbmgr.add(action);};$prototype.dispose=function(){disconnect(this.addedListener);disconnect(this.removedListener);disconnect(this.enabledListener);this.addedListener=null;this.removedListener=null;this.enabledListener=null;userSmarts.ui.EditorPart.prototype.dispose.call(this);};$prototype.getEvent=function(){return this.input.event;};$prototype.onFeatureAdded=function(event){try{var feature=event.newValue;var fgeom=feature.geometry;var geometry=openLayersToGeometry(fgeom);if(geometry){var name=prompt("Enter a name for this location:","");var location=new userSmarts.geo.Location();location.setName(name);location.setWhere(geometry);this.getEvent().setLocation(location);feature.name=name;}
var features=this.getMap().getFeatures().clone();for(var i=0;i<features.length;++i){if(features[i]!=feature){this.getMap().removeFeature(features[i]);}}
this.setProperty("dirty",true);}catch(e){getLogger().logError("Error capturing drawn AOI on map, cause: "+e);}};$prototype.onFeatureRemoved=function(event){var location=this.getEvent().getLocation();if(location){location.dispose();}
this.getEvent().setLocation(null);this.setProperty("dirty",true);};$prototype.displayGeocodedResult=function(result){this.control.removeAllFeatures();if(result){this.getEvent().setLocation(result);var geom=result.getWhere();var env=geom.getEnvelope();this.control.addGeometry(geom,{style:OpenLayers.Feature.Vector.style['default'],locationObj:result,name:result.getName()});this.control.zoomToExtent(env);}};$prototype.getMap=function(){return this.control;};$prototype.displayGeometries=function(){var event=this.getEvent();var location=event.getLocation();if(location){var geometry=location.getWhere();var aoi=null;this.getMap().addGeometry(geometry,{name:location.getName()});if(!aoi){aoi=geometry.getEnvelope();}else{var env=geometry.getEnvelope();aoi.points[0].x=Math.min(env.getPoints()[0].x,aoi.points[0].x);aoi.points[0].y=Math.min(env.getPoints()[0].y,aoi.points[0].y);aoi.points[1].x=Math.max(env.getPoints()[1].x,aoi.points[1].x);aoi.points[1].y=Math.max(env.getPoints()[1].y,aoi.points[1].y);}}
if(aoi){var map=this.getMap();map.setPreferredExtent(aoi);}};namespace("userSmarts.sx.model.events.editors");$namespace.EventMap=Class.create(userSmarts.maps.ol.Map);$prototype.initialize=function(superClass,properties){superClass.call(this,properties);};$prototype.addLayers=function(){userSmarts.maps.ol.Map.prototype.addLayers.call(this);};$prototype.addControls=function(){var fabind=bind(this.onFeatureAdded,this);var controls=[new OpenLayers.Control.DrawFeature(this.vectorLayer,OpenLayers.Handler.Polygon,{'displayClass':'olControlDrawFeaturePolygon'}),new OpenLayers.Control.DrawFeature(this.vectorLayer,OpenLayers.Handler.Path,{'displayClass':'olControlDrawFeaturePath'}),new OpenLayers.Control.DrawFeature(this.vectorLayer,OpenLayers.Handler.Point,{'displayClass':'olControlDrawFeaturePoint'})];for(var c=0;c<controls.length;++c){controls[c].featureAdded=fabind;}
var navTool=new OpenLayers.Control.Navigation();controls.splice(0,0,navTool);var helpTool=new userSmarts.maps.ol.control.Help();controls.push(helpTool);var panel=new OpenLayers.Control.Panel({defaultControl:navTool,CLASS_NAME:"OpenLayers.Control.EditingToolbar"});panel.displayClass="olControlEditingToolbar";panel.addControls(controls);this.map.addControl(panel);this.selectFeatureControl=new userSmarts.maps.ol.control.SelectFeature(this.vectorLayer,{onSelect:bind(this.onFeatureSelect,this),onUnselect:bind(this.onFeatureUnselect,this),onKeyPressed:bind(this.onKeyPressed,this),onDoubleClickFeature:bind(this.onDoubleClickFeature,this)});this.map.addControl(this.selectFeatureControl);this.selectFeatureControl.activate();};$prototype.onFeatureAdded=function(feature){feature.state=OpenLayers.State.INSERT;this.setProperty("featureAdded",feature);};$prototype.selectFeature=function(feature){if(this.selectedFeature&&this.selectedFeature.geometry){if(this.selectedFeature.popup){this.removePopup(this.selectedFeature.popup);this.selectedFeature.popup=null;}
this.selectFeatureControl.unselect(this.selectedFeature);}
if(feature){this.selectFeatureControl.select(feature);}};$prototype.onFeatureSelect=function(feature){this.selectedFeature=feature;var title=feature.name||"Unnamed Location";var html=this.generatePopupHtml(title,feature.locationObj||feature.geometry);feature.popup=this.addPopup("Location",html,feature.geometry.getBounds().getCenterLonLat(),300,100);};$prototype.onFeatureUnselect=function(feature){if(feature&&feature.popup){this.removePopup(feature.popup);feature.popup=null;}
this.selectedFeature=null;};$prototype.onKeyPressed=function(code){switch(code){case OpenLayers.Event.KEY_DELETE:var features=this.getSelectedVectors();if(features.length>0){var feature=features[0];if(confirm("Delete this AOI?")){this.removePopup(feature.popup);this.removeVector(feature);this.setProperty("featureRemoved",feature);}}};};$prototype.onDoubleClickFeature=function(feature){if(confirm("Delete this AOI?")){this.removePopup(feature.popup);this.removeVector(feature);this.setProperty("featureRemoved",feature);}};$prototype.generatePopupHtml=function(name,obj){var title=name;var description="";if(obj&&obj instanceof userSmarts.geo.Location){description="Address: "+Coerce.toString(obj.getAddress1(),"")+" "+
Coerce.toString(obj.getAddress2(),"")+"<br/>";description+="City: "+Coerce.toString(obj.getCity(),"N/A")+"<br/>";description+="Region: "+Coerce.toString(obj.getRegion(),"N/A")+"<br/>";description+="Zip: "+Coerce.toString(obj.getPostal(),"N/A");}else if(obj instanceof Geometry){description="Center: "+obj.getCenter().x+","+obj.getCenter().y;}else if(typeof(obj.getBounds)=="function"){var center=obj.getBounds().getCenterLonLat();description="Center: "+center.lon+","+center.lat;}else if(obj instanceof OpenLayers.LonLat){description="Center: "+obj.lon+","+obj.lat;}else{description="Unknown AOI";}
var html='<div style="font:12px small Arial; font-weight:bold;">'+title+'</div>';html+='<div style="font:12px small Arial;">';html+=description;html+='</div>';return html;};namespace("userSmarts.sx.model.events.actions");namespace("userSmarts.sx.model.events.actions");namespace("userSmarts.sx.model.events.actions");$namespace.CreateEventAction=Class.create(userSmarts.wt.action.Action);$prototype.initialize=function(superClass,properties){properties=setdefault(properties,{id:"userSmarts.sx.model.events.actions.event.create",text:"Create",toolTipText:"Create New Event",image:"image.event.add"});superClass.call(this,properties);this.callback=bind(this.onSuccess,this);this.errback=bind(this.onError,this);this.dialogCallback=bind(this.onDialogClosed,this);};$prototype.run=function(){var event=new userSmarts.sx.model.events.pub.Event();event.setTitle("New Event");event.setSummary("[Provide a description of the event here]");event.setTypeName("urn:usersmarts:sx:event");var input=new userSmarts.sx.model.events.editors.EventEditorInput({event:event});var page=userSmarts.ui.PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();page.openEditor(input,"userSmarts.sx.model.events.editors.EventEditor",true);};$prototype.onDialogClosed=function(event){if(event){var workspace=userSmarts.runtime.Platform.getWorkspace();var collURL=workspace.getLink("events").href;var collection=new userSmarts.pub.atom.GeoCollection({url:collURL});var def=collection.add(event);def.addCallback(this.callback);def.addErrback(this.errback);}};$prototype.onSuccess=function(entry){var event=new userSmarts.event.Event("sx.events",{type:"created",id:entry.getId()});var context=userSmarts.sx.Plugin.getDefault().getBundleContext();var ref=context.getServiceReference("userSmarts.event.EventAdmin");var eventService=ref.getService();eventService.sendEvent(event);};$prototype.onError=function(e){handleResponseError(e);};namespace("userSmarts.sx.model.events.actions");$namespace.EditEventAction=Class.create(userSmarts.wt.action.Action);$prototype.initialize=function(superClass,properties){properties=setdefault(properties,{id:"userSmarts.sx.model.events.actions.event.edit",text:"Edit",toolTipText:"Edit Selected Event",image:"image.event.edit"});superClass.call(this,properties);var ps=userSmarts.runtime.Platform.getPropertyService();this.listener=ps.connect("sx.events","selected",this,this.onEventSelected);};$prototype.run=function(){var ps=userSmarts.runtime.Platform.getPropertyService();var event=ps.getProperty("sx.events","selected");if(event){var name=event.getTitle();var url=event.getLink();var input=new userSmarts.sx.model.events.editors.EventEditorInput({name:name,url:url});var page=userSmarts.ui.PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();page.openEditor(input,"userSmarts.sx.model.events.editors.EventEditor",true);}};$prototype.onEventSelected=function(event){if(event.newValue){if(!this.isEnabled())this.setEnabled(true);}else{if(this.isEnabled())this.setEnabled(false);}};namespace("userSmarts.sx.model.events.actions");$namespace.DeleteEventAction=Class.create(userSmarts.wt.action.Action);$prototype.initialize=function(superClass,properties){properties=setdefault(properties,{id:"userSmarts.sx.model.events.actions.event.delete",text:"Delete",toolTipText:"Delete Selected Event",image:"image.event.delete"});superClass.call(this,properties);this.callback=bind(this.onSuccess,this);this.errback=bind(this.onError,this);};$prototype.run=function(){var ps=userSmarts.runtime.Platform.getPropertyService();var event=ps.getProperty("sx.events","selected");if(event&&confirm("Deleted event '"+event.getTitle()+"' ?")){try{var editorId="userSmarts.sx.events.editors.EventEditor";var matchFlag=userSmarts.ui.WorkbenchPage.MATCH_INPUT;var input=new userSmarts.sx.model.events.editors.EventEditorInput({event:event});var wb=userSmarts.ui.PlatformUI.getWorkbench();var page=wb.getActiveWorkbenchWindow().getActivePage();var editors=page.findEditors(input,editorId,matchFlag);for(var e=0;e<editors.length;++e){page.closeEditor(editors[e],false);}}catch(e){getLogger().logError("Error closing open editor for event - "+e);}
var def=event.del();def.addCallback(this.callback);def.addErrback(this.errback);}};$prototype.onSuccess=function(){var event=new userSmarts.event.Event("sx.events",{type:"deleted"});var context=userSmarts.sx.Plugin.getDefault().getBundleContext();var ref=context.getServiceReference("userSmarts.event.EventAdmin");var eventService=ref.getService();eventService.sendEvent(event);};$prototype.onError=function(e){handleResponseError(e);};namespace("userSmarts.sx.model.events.actions");$namespace.ZoomToEventAction=Class.create(userSmarts.wt.action.Action);$prototype.initialize=function(superClass,properties){properties=setdefault(properties,{id:"userSmarts.sx.model.events.actions.event.zoom",text:"Zoom",toolTipText:"Zoom to Selected Event",image:"image.event.zoom"});superClass.call(this,properties);};$prototype.run=function(){var ps=userSmarts.runtime.Platform.getPropertyService();var event=ps.getProperty("sx.events","selected");if(event){var geometry=event.getWhere();if(geometry){ps.setProperty("map","aoi",geometry);}else{getLogger().logWarning("Selected event has no geometry");}}else{getLogger().logWarning("Must select an event first!");}};namespace("userSmarts.sx.model.events.dialogs");namespace("userSmarts.sx.model.events.dialogs");namespace("userSmarts.sx.model.events.dialogs");$namespace.CreateEventDialog=Class.create(userSmarts.wt.dialogs.CDialog);$prototype.initialize=function(superClass,properties){properties=setdefault(properties,{width:400,height:500,modal:false,enableKeys:true,enableDrag:true,showClose:true});superClass.call(this,properties);};$prototype.createDialogArea=function(composite){composite.setLayout(new userSmarts.wt.layout.RowLayout({type:"vertical"}));this.titleField=new userSmarts.wt.forms.FieldControl({parent:composite,updateOnBoundsChange:true,layoutData:{width:"100%",height:50},validator:null,value:"",showLabel:true,title:"Title: "});this.descField=new userSmarts.wt.forms.TextAreaControl({parent:composite,updateOnBoundsChange:true,layoutData:{width:"100%",height:100},validator:null,value:"",showLabel:true,title:"Description: "});var mapLabel=new userSmarts.wt.widgets.Control({'class':"form-input-field-label",parent:composite,updateOnBoundsChange:true,layoutData:{width:"100%",height:20},margin:{top:5,left:0,right:0,bottom:0}});mapLabel.getNode().appendChild(document.createTextNode("Area of Interest: "));var navTool=new OpenLayers.Control.Navigation();this.selectionTool=new userSmarts.maps.ol.control.SelectBox();var panel=new OpenLayers.Control.Panel({defaultControl:navTool,CLASS_NAME:"OpenLayers.Control.EditingToolbar"});panel.displayClass="olControlEditingToolbar";panel.addControls([navTool,this.selectionTool]);this.map=new userSmarts.maps.ol.Map({parent:composite,updateOnBoundsChange:false,layoutData:{width:"100%",height:"*"},padding:{top:0,left:3,right:3,bottom:3},mapOptions:{maxExtent:new OpenLayers.Bounds(-180,0,-40,90),restrictedExtent:new OpenLayers.Bounds(-180,0,-40,90),controls:[panel]},center:new OpenLayers.LonLat(-95.0,38.5),zoom:2,addControls:function(){}});composite.update();};$prototype.focus=function(){this.titleField.focus();};$prototype.okPressed=function(){if(this.deferred){this.deferred.callback(this.buildEvent());this.deferred=null;}};$prototype.buildEvent=function(){var event=new userSmarts.sx.model.events.pub.Event();event.setTitle(this.titleField.getValue());event.setSummary(this.descField.getValue());event.setWhere(this.getSelectedRegion());event.setTypeName("urn:usersmarts:events:sample");return event;};$prototype.getSelectedRegion=function(){var region;var bounds=this.selectionTool.getSelection();if(bounds){region=new Geometry("Box");region.addPoint(new Point(bounds.left,bounds.bottom));region.addPoint(new Point(bounds.right,bounds.top));}
return region;};$prototype.close=function(){this.map.dispose();userSmarts.wt.dialogs.CDialog.prototype.close.call(this);};namespace("userSmarts.sx.model.events.pub");namespace("userSmarts.sx.model.events.pub");namespace("userSmarts.sx.model.events.pub");$namespace.Event=Class.create(userSmarts.pub.atom.GeoEntry);$prototype.initialize=function(superClass,properties){superClass.call(this,properties);};$prototype.getTypeName=function(){var tnNode=this.getExtension("typeName");if(tnNode&&tnNode.value){return tnNode.value;}
return null;};$prototype.setTypeName=function(typeName){this.setExtension("typeName",typeName,"http://www.usersmarts.com/repo");};$prototype.getTime=function(){var timeNode=this.getExtension("timePeriod");if(timeNode&&timeNode.value){if(isXmlNode(timeNode.value)){var time=userSmarts.sx.model.events.pub.Time.parse(timeNode.value);this.setTime(time);return time;}else if(typeof(timeNode.value.setStartTime)!="undefined"){return timeNode.value;}}
return null;};$prototype.setTime=function(time){this.setExtension("timePeriod",time,"http://www.usersmarts.com/sx/core/event");};$prototype.getLocation=function(){var node=this.getExtension("where");if(node&&node.value){if(isXmlNode(node.value)){var location=userSmarts.geo.Location.parse(node.value);this.setLocation(location);return location;}else if(typeof(node.value.setWhere)!="undefined"){return node.value;}}
return null;};$prototype.setLocation=function(location){this.setExtension("where",location,"http://www.georss.org/georss");};$prototype.getWhere=function(){var location=this.getLocation();if(location){return location.getWhere();}
return null;};$prototype.setWhere=function(geometry){var location=this.getLocation();if(!location){this.setLocation(new Location());location=this.getLocation();}
location.setWhere(geometry);};$prototype.appendElement=function(parentNode,tagName,content,uri){if(!parentNode||!tagName||!content)return null;if(tagName=="timePeriod"){var time=this.getTime();if(time){time.toXml(parentNode);}}else if(tagName=="where"){var location=this.getLocation();if(location){location.toXml(parentNode);}}else{return userSmarts.pub.atom.GeoEntry.prototype.appendElement.call(this,parentNode,tagName,content,uri);}};namespace("userSmarts.sx.model.events.pub");$namespace.Time=Class.create(Bean);$prototype.initialize=function(superClass,properties){properties=setdefault(properties,{isRange:false});superClass.call(this,properties);this.format=new DateFormat();};$prototype.isTimeRange=function(){return this.isRange;};$prototype.getStartTime=function(){return this.startTime;};$prototype.setStartTime=function(time){this.startTime=time;};$prototype.getEndTime=function(){return this.endTime;};$prototype.setEndTime=function(time){this.endTime=time;this.isRange=true;};$prototype.toXml=function(parentNode){var ns="http://www.usersmarts.com/sx/core/event";var tp;var doc;if(!parentNode){doc=createXMLDocument('timePeriod',ns,null);tp=doc.documentElement;}else{if(parentNode.nodeType!=9){doc=parentNode.ownerDocument;tp=createElementNS(ns,"timePeriod",doc);parentNode.appendChild(tp);}}
if(!tp)return null;if(this.isTimeRange()){var sdt=createElementNS(ns,"startDateTime",doc);var stt=this.format.format(this.getStartTime(),true);sdt.appendChild(doc.createTextNode(stt));tp.appendChild(sdt);var edt=createElementNS(ns,"endDateTime",doc);var ett=this.format.format(this.getEndTime(),true);edt.appendChild(doc.createTextNode(ett));tp.appendChild(edt);}else{var sdt=createElementNS(ns,"singleDateTime",doc);var stt=this.format.format(this.getStartTime(),true);sdt.appendChild(doc.createTextNode(stt));tp.appendChild(sdt);}
return tp;};$namespace.Time.parse=function(xml){if(!isXmlNode(xml)||DOMUtils.getName(xml)!="timePeriod"){return null;}
var format=new DateFormat();var time=null;var singleDTNode=DOMUtils.getChild(xml,"singleDateTime");if(singleDTNode){var dateText=scrapeText(singleDTNode);time=new userSmarts.sx.events.pub.Time({isRange:false,startTime:format.parseObject(dateText)});}else{var startDTNode=DOMUtils.getChild(xml,"startDateTime");var endDTNode=DOMUtils.getChild(xml,"endDateTime");if(startDTNode&&endDTNode){var startText=scrapeText(startDTNode);var endText=scrapeText(endDTNode);time=new userSmarts.sx.events.pub.Time({isRange:true,startTime:format.parseObject(startText),endTime:format.parseObject(endText)});}}
return time;};namespace("userSmarts.sx.model.facilities.views");namespace("userSmarts.sx.model.facilities.views");namespace("userSmarts.sx.model.facilities.views");$namespace.FacilitiesView=Class.create(userSmarts.ui.views.ListView);$prototype.initialize=function(superClass,properties){superClass.call(this,properties);this.model=new userSmarts.sx.model.facilities.models.FacilitiesModel();connect(this.model,'modified',this,this.onListUpdated);};$prototype.init=function(site){userSmarts.ui.views.ListView.prototype.init.call(this,site);var ps=userSmarts.runtime.Platform.getPropertyService();ps.connect("map","aoi",this,this.onAOIChange);ps.connect("facility","filter",this,this.onFilterChange);this.model.setFilter(ps.getProperty("facility","filter"));};$prototype.contributeToActionBars=function(){var actionbars=this.getSite().getActionBars();var tbmgr=actionbars.getToolbarManager();var mbmgr=actionbars.getMenuBarManager();var action=new userSmarts.sx.model.facilities.actions.ConstrainByAlertAction({checked:true});tbmgr.add(action);mbmgr.add(action);action=new userSmarts.wt.action.Action({id:'zoomToFacilityAction',text:"Zoom to Facility",toolTipText:'Zoom to selected facility',run:bind(this.zoomToSelectedFacility,this),image:"image.facility.zoom.single"});tbmgr.add(action);mbmgr.add(action);mbmgr.add(new userSmarts.wt.action.HorizontalSeparator());userSmarts.ui.views.ListView.prototype.contributeToActionBars.call(this);};$prototype.displayMessage=function(msg){var slmgr=this.getSite().getActionBars().getStatusLineManager();slmgr.setMessage(msg);};$prototype.setSelection=function(obj){this.setProperty("selected",obj);var ps=userSmarts.runtime.Platform.getPropertyService();ps.setProperty("facilities","selected",obj);var layer=this.getMapLayer();layer.selectedFacility=obj;layer.setProperty("modified",true);};$prototype.onSelectionChange=function(event){try{if(event.newValue){var facility=event.newValue;this.setSelection(facility.getId());this.selectedFacilityAOI=facility.getWhere().getEnvelope();}else{this.setSelection(null);this.view=null;}}catch(e){alert("Error handling selected facility");}};$prototype.onListUpdated=function(event){this.checkSelected();this.getMapLayer();};$prototype.checkSelected=function(){var present=false;if(this.selected){var rows=this.model.getRows();for(var i=0;i<rows.length;++i){if(rows[i].getId()==this.selected){present=true;this.list.select(rows[i]);}}}
if(!present){this.setSelection(null);this.selectedFacilityAOI=null;}};$prototype.zoomToSelectedFacility=function(){if(this.selectedFacilityAOI){var ps=userSmarts.runtime.Platform.getPropertyService();ps.setProperty("map","aoi",this.selectedFacilityAOI);}else{alert("Must select an Facility from the list first!");}};$prototype.zoomToPageOfFacilities=function(){if(this.model){var ps=userSmarts.runtime.Platform.getPropertyService();ps.setProperty("map","aoi",this.model.getBoundingBox());}};$prototype.onAOIChange=function(event){if(event.oldValue!=event.newValue){this.setAOI(event.newValue);}};$prototype.setAOI=function(aoi){if(aoi&&this.model){this.model.setBoundingBox(aoi);}};$prototype.onFilterChange=function(event){this.model.setFilter(event.newValue);};$prototype.getMapLayer=function(){var layer=userSmarts.sx.Plugin.getDefault().getFacilityLayer();var isVisible=layer.server.url!=layer.server.baseURL;layer.server.url=layer.server.baseURL+"startIndex="+this.model.getStartIndex()+"&startPage="+this.model.getStartPage()+"&selected="+this.selected+"&useAnd="+this.model.getAndTerms()+"&q="+this.model.getKeywords().toString(" ")+"&selectionFilter="+this.model.getFilter();var sortElement=this.model.getSortElement();if(sortElement){layer.server.url+="&sortElement="+sortElement+"&sortOrder="+this.model.getSortOrder();}
if(!isVisible){layer.show();}else{layer.setProperty("modified",true);}
return layer;};namespace("userSmarts.sx.model.facilities.views");$namespace.ReportFacilitiesView=Class.create(userSmarts.ui.views.ListView);$prototype.initialize=function(superClass,desc){superClass.call(this,desc);this.defaultModel=new userSmarts.sx.model.facilities.models.EmptyTableModel({pageSize:50});};$prototype.init=function(site){userSmarts.ui.views.TableView.prototype.init.call(this,site);var page=userSmarts.ui.PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();connect(page,"activeEditor",this,this.onEditorChange);var ps=userSmarts.runtime.Platform.getPropertyService();ps.connect("editor","initialized",this,this.onEditorChange);};$prototype.contributeToActionBars=function(){var actionbars=this.getSite().getActionBars();var tbmgr=actionbars.getToolbarManager();var mbmgr=actionbars.getMenuBarManager();var ns=userSmarts.sx.model.facilities.actions;this.alertConstraintAction=new ns.ConstrainModelByAlertAction({control:this});tbmgr.add(this.alertConstraintAction);mbmgr.add(this.alertConstraintAction);this.annConstraintAction=new ns.ConstrainByAnnotationAction({control:this});tbmgr.add(this.annConstraintAction);mbmgr.add(this.annConstraintAction);mbmgr.add(new userSmarts.wt.action.HorizontalSeparator());userSmarts.ui.views.ListView.prototype.contributeToActionBars.call(this);};$prototype.onEditorChange=function(event){var constrainByAlerts=false;var editor=event.newValue;if(editor&&typeof(editor.getFacilitiesModel)=="function"){var def=editor.getFacilitiesModel();def.addCallback(bind(function(model){if(model){this.model=model;this.list.setProperty("model",model);if(model.getFilterStr().indexOf("alert")>0){this.alertConstraintAction.setChecked(true);}else{this.alertConstraintAction.setChecked(false);}
if(model.getFilterStr().indexOf("report")>0){this.annConstraintAction.setChecked(true);}else{this.annConstraintAction.setChecked(false);}}else{this.model=this.defaultModel;this.list.setProperty("model",this.defaultModel);this.alertConstraintAction.setChecked(false);this.annConstraintAction.setChecked(false);}},this));return;}
this.alertConstraintAction.setChecked(false);this.annConstraintAction.setChecked(false);if(this.list.model!=this.defaultModel){this.list.setProperty("model",this.defaultModel);}};$prototype.displayMessage=function(msg){var slmgr=this.getSite().getActionBars().getStatusLineManager();slmgr.setMessage(msg);};$prototype.setSelection=function(obj){this.setProperty("selected",obj.id);this.model.setSelection(obj.id);userSmarts.runtime.Platform.getPropertyService().setProperty("report","facility",obj);};$prototype.onSelectionChange=function(event){if(event.newValue){var wrapper=event.newValue;var node=wrapper.getNode();var idNode=node.getElementsByTagName("id").item(0);var id=scrapeText(idNode);if(id!=this.selected){this.setSelection({id:id});var geometry=new Geometry("Box");var coordinatesNode=node.getElementsByTagName("coordinates").item(0);var coordinate=scrapeText(coordinatesNode);var point=coordinate.split(",");geometry.addPoint(new Point(point[0]*1-0.005,point[1]*1-0.005));geometry.addPoint(new Point(point[0]*1+0.005,point[1]*1+0.005));this.selectedFacilityAOI=geometry.getEnvelope();}}else{this.setSelection({id:null});this.selectedFacilityAOI=null;}};namespace("userSmarts.sx.model.facilities.models");namespace("userSmarts.sx.model.facilities.models");namespace("userSmarts.sx.model.facilities.models");$namespace.FacilitiesModel=Class.create(userSmarts.pub.atom.FeedModel);$prototype.initialize=function(superClass,properties){properties=setdefault(properties,{pageSize:50,aois:[],keywords:[""],useAndOperator:true,selected:null,collection:new userSmarts.pub.atom.GeoCollection({url:"pub/facilities/0/index.xml",factory:new userSmarts.pub.atom.DefaultEntryFactory({entryClass:"userSmarts.sx.model.facilities.pub.Facility"})})});superClass.call(this,properties);var icon=userSmarts.runtime.Platform.getTheme().getImage("image.facility");this.addColumn(new userSmarts.pub.atom.EntryColumn({label:"Id",name:"id",index:0,order:true,visible:false}));this.addColumn(new userSmarts.pub.atom.EntryColumn({label:"Name",name:"title",index:0,order:true,fallback:"Un-titled Facility",image:icon}));this.addColumn(new userSmarts.pub.atom.EntryColumn({label:"Address",name:"fullAddress",index:2,order:true}));this.addColumn(new userSmarts.pub.atom.EntryColumn({label:"County",name:"county",index:3,order:true}));this.addColumn(new userSmarts.pub.atom.EntryColumn({label:"Phone#",name:"phone",index:4,order:true}));this.addColumn(new userSmarts.pub.atom.EntryColumn({label:"Facility Type",name:"type",index:5,order:true}));this.addColumn(new userSmarts.pub.atom.EntryColumn({label:"Capacity",name:"capacity",index:6,order:true}));};$prototype.setFilter=function(f){var filter="";if(f&&f.values&&typeof(f.values.push)=="function"){filter=f.values.toString(",");}
this.setCollectionParameter("selectionFilter",filter);this.populate(0);};$prototype.getFilter=function(){return this.getCollectionParameter("selectionFilter");};namespace("userSmarts.sx.model.facilities.models");$namespace.ReportFacilitiesModel=Class.create(userSmarts.sx.model.facilities.models.FacilitiesModel);$prototype.initialize=function(superClass,properties){superClass.call(this,properties);};$prototype.onLoaded=function(coll){this.updateLayer();userSmarts.sx.model.facilities.models.FacilitiesModel.prototype.onLoaded.call(this,coll);};$prototype.updateLayer=function(){var layer=this.layer;if(layer){var selected=this.selected||"";layer.refreshProperties={modified:true};layer.server.baseURL="pub/wms?";layer.server.url=layer.server.baseURL+"modcount="+Math.random()+"&startIndex="+this.getStartIndex()+"&startPage="+this.getStartPage()+"&selected="+selected+"&useAnd="+this.getAndTerms()+"&q="+this.getKeywords().toString(" ")+"&selectionFilter="+this.getFilterStr();var sortElement=this.getSortElement();if(sortElement){layer.server.url+="&sortElement="+sortElement+"&sortOrder="+this.getSortOrder();}
layer.setProperty("modified",true);}};$prototype.getFilter=function(){var filter=userSmarts.sx.model.facilities.models.FacilitiesModel.prototype.getFilter.call(this);if(!filter){filter={values:[]}}else{filter={values:filter.split(",")}}
return filter;};$prototype.getFilterStr=function(){return userSmarts.sx.model.facilities.models.FacilitiesModel.prototype.getFilter.call(this)||"";};$prototype.setSelection=function(id){this.selected=id;};$namespace.EmptyTableModel=Class.create(userSmarts.wt.widgets.TableModel);$prototype.initialize=function(superClass,properties){superClass.call(this,properties);this.columns=[];};$prototype.size=function(){return 0;};$prototype.populate=function(){this.buffer=[];this.setProperty("modified",true);};namespace("userSmarts.sx.model.facilities.actions");namespace("userSmarts.sx.model.facilities.actions");namespace("userSmarts.sx.model.facilities.actions");$namespace.ConstrainByAlertAction=Class.create(userSmarts.wt.action.StatefulAction);$prototype.initialize=function(superClass,properties){properties=setdefault(properties,{id:"constrainByAlertAction",text:"Constrain by Alert",checkedText:"Unconstrain by Alert",toolTipText:"Constrain using selected alert",image:"image.facility.constrain.alert"});superClass.call(this,properties);if(this.checked){this.listen();}};$prototype.run=function(){if(this.isChecked()){this.listen();}else{this.ignore();}};$prototype.listen=function(){var ps=userSmarts.runtime.Platform.getPropertyService();var id=ps.getProperty("alert","selected");var filter=ps.getProperty("facility","filter");if(!filter)filter={values:[]};filter.values.push("urn:alert:"+(id||""));ps.setProperty("facility","filter",filter);this.alertListener=ps.connect("alert","selected",this,this.onSelectionChange);};$prototype.ignore=function(){var ps=userSmarts.runtime.Platform.getPropertyService();ps.disconnect(this.alertListener);this.alertListener=null;var filter=ps.getProperty("facility","filter");if(filter){this.replaceExistingSelection(filter,null);}
ps.setProperty("facility","filter",filter);};$prototype.onSelectionChange=function(event){var id=event.newValue;var ps=userSmarts.runtime.Platform.getPropertyService();var filter=ps.getProperty("facility","filter");if(!filter){filter={values:["urn:alert:"+(id||"")]};}else{this.replaceExistingSelection(filter,id);}
ps.setProperty("facility","filter",filter);};$prototype.replaceExistingSelection=function(filter,id){var index=-1;for(var i=0;i<filter.values.length;++i){if(filter.values[i].indexOf("urn:alert")>=0){index=i;break;}}
if(index>=0){filter.values.splice(index,1);}
if(id){filter.values.push("urn:alert:"+(id||""));}};namespace("userSmarts.sx.model.facilities.actions");$namespace.ConstrainByAnnotationAction=Class.create(userSmarts.wt.action.StatefulAction);$prototype.initialize=function(superClass,properties){properties=setdefault(properties,{id:"constrainByAnnotationsAction",text:"Constrain by Annotations",checkedText:"Unconstrain by Annotations",toolTipText:"Constraint using map annotations",image:"image.facility.constrain.annotation"});superClass.call(this,properties);};$prototype.run=function(){var ps=userSmarts.runtime.Platform.getPropertyService();if(this.isChecked()){if(this.control){var model=this.control.model;if(model){var id=model.reportId;var filter=model.getFilter();filter=this.replaceExistingSelection(filter,id);model.setFilter(filter);}}}else{if(this.control){var model=this.control.model;if(model){var id=model.reportId;var filter=model.getFilter();filter=this.replaceExistingSelection(filter,null);model.setFilter(filter);}}}};$prototype.onSelectionChange=function(event){var id=null;var selection=event.newValue;if(selection&&selection.id){id=selection.id;}
if(this.control){var model=this.control.model;if(model){var filter=model.getFilter();filter=this.replaceExistingSelection(filter,id);model.setFilter(filter);}}};$prototype.replaceExistingSelection=function(filter,id){if(!filter){filter={values:[]};if(id){filter.values.push("urn:report:"+(id||""));}
return filter;}
var index=-1;for(var i=0;i<filter.values.length;++i){if(filter.values[i].indexOf("urn:report")>=0){index=i;break;}}
if(index>=0){filter.values.splice(index,1);}
if(id){filter.values.push("urn:report:"+(id||""));}
return filter;};namespace("userSmarts.sx.model.facilities.actions");$namespace.ConstrainModelByAlertAction=Class.create(userSmarts.wt.action.StatefulAction);$prototype.initialize=function(superClass,properties){properties=setdefault(properties,{id:"constrainModelByAlertAction",text:"Constrain by Alert",toolTipText:"Constrain using selected alert",image:"image.facility.constrain.alert"});superClass.call(this,properties);};$prototype.run=function(){if(this.control){var model=this.control.model;if(model){if(this.isChecked()){var id=model.selectedAlert;var filter=model.getFilter();filter=this.replaceExistingSelection(filter,id);model.setFilter(filter);}else{var filter=model.getFilter();filter=this.replaceExistingSelection(filter,null);model.setFilter(filter);}}else{if(this.isChecked()){this.setChecked(false);}}}else{if(this.isChecked()){this.setChecked(false);}}};$prototype.replaceExistingSelection=function(filter,id){if(!filter){filter={values:[]};if(id){filter.values.push("urn:alert:"+(id||""));}
return filter;}
var index=-1;for(var i=0;i<filter.values.length;++i){if(filter.values[i].indexOf("urn:alert")>=0){index=i;break;}}
if(index>=0){filter.values.splice(index,1);}
if(id){filter.values.push("urn:alert:"+(id||""));}
return filter;};namespace("userSmarts.sx.model.facilities.pub");namespace("userSmarts.sx.model.facilities.pub");namespace("userSmarts.sx.model.facilities.pub");$namespace.Facility=Class.create(userSmarts.pub.atom.GeoEntry);$prototype.initialize=function(superClass,properties){superClass.call(this,properties);this.facNS="http://www.usersmarts.com/sx/facilities";};$prototype.getFullAddress=function(){var tnNode=this.getExtension("fullAddress");if(tnNode&&tnNode.value){return tnNode.value;}
return null;};$prototype.setFullAddress=function(addr){this.setExtension("fullAddress",addr,this.facNS);};$prototype.getCounty=function(){var tnNode=this.getExtension("county");if(tnNode&&tnNode.value){return tnNode.value;}
return null;};$prototype.setCounty=function(county){this.setExtension("county",county,this.facNS);};$prototype.getPhone=function(){var tnNode=this.getExtension("phone");if(tnNode&&tnNode.value){return tnNode.value;}
return null;};$prototype.setPhone=function(phone){this.setExtension("phone",phone,this.facNS);};$prototype.getType=function(){var tnNode=this.getExtension("type");if(tnNode&&tnNode.value){return tnNode.value;}
return null;};$prototype.setType=function(type){this.setExtension("type",type,this.facNS);};$prototype.getCapacity=function(){var tnNode=this.getExtension("capacity");if(tnNode&&tnNode.value){return tnNode.value;}
return null;};$prototype.setCapacity=function(cap){this.setExtension("capacity",cap,this.facNS);};namespace("userSmarts.sx.model.watches.actions");namespace("userSmarts.sx.model.watches.actions");namespace("userSmarts.sx.model.watches.actions");$namespace.CreateWatchAction=Class.create(userSmarts.wt.action.Action);$prototype.initialize=function(superClass,properties){properties=setdefault(properties,{id:"usersmarts.sx.model.watches.actions.createwatch",text:"Create",toolTipText:"Create new watch",image:"image.watch.add"});superClass.call(this,properties);};$prototype.run=function(){var dialog=new userSmarts.sx.model.watches.dialogs.CreateWatchDialog();var deferred=dialog.open();deferred.addCallback(bind(this.dialogCallback,this));};$prototype.dialogCallback=function(watch){if(!watch)return;var resource=new userSmarts.pub.Resource({url:"pub/watches/",params:{format:"text/xml"}});var d=resource.post(watch);d.addCallback(bind(this.postCallback,this));d.addErrback(handleResponseError);};$prototype.postCallback=function(data){var ps=userSmarts.runtime.Platform.getPropertyService();ps.setProperty("atom:watches","status","updated");var watch=data.responseXML.documentElement;var id=getNodeAttribute(watch,"id");var title=scrapeText(watch.firstChild);var url="pub/watches/"+id+".xml";var input=new userSmarts.sx.model.watches.editors.WatchEditorInput({name:title,url:url});var page=userSmarts.ui.PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();page.openEditor(input,"userSmarts.sx.model.watches.editors.WatchEditor",true);};namespace("userSmarts.sx.model.watches.actions");$namespace.ModifyWatchAction=Class.create(userSmarts.wt.action.Action);$prototype.initialize=function(superClass,properties){properties=setdefault(properties,{id:"usersmarts.sx.model.watches.actions.editwatch",text:"Edit",toolTipText:"Edit selected watch",image:"image.watch.edit"});superClass.call(this,properties);};$prototype.run=function(){var ps=userSmarts.runtime.Platform.getPropertyService();var p=ps.getProperty("feed","selected");if(p==undefined){alert("Please select a watch to modify.");}else{var url=p.links.alternate;if(!url){alert("Entry missing URL for editing. Aborting!")}else{var label=p.title||p.id||"[watch]";var input=new userSmarts.sx.model.watches.editors.WatchEditorInput({name:label,url:url});var page=userSmarts.ui.PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();page.openEditor(input,"userSmarts.sx.model.watches.editors.WatchEditor",true);}}};namespace("userSmarts.sx.model.watches.actions");$namespace.RefreshWatchesAction=Class.create(userSmarts.wt.action.Action);$prototype.initialize=function(superClass,properties){properties=setdefault(properties,{id:"usersmarts.sx.model.watches.actions.refreshwatches",text:"Refresh",toolTipText:"Refresh list of watches",image:"image.refresh"});superClass.call(this,properties);};$prototype.run=function(){alert("refreshing watch list");};namespace("userSmarts.sx.model.watches.actions");$namespace.RemoveWatchesAction=Class.create(userSmarts.wt.action.Action);$prototype.initialize=function(superClass,properties){properties=setdefault(properties,{id:"usersmarts.sx.model.watches.actions.removewatch",text:"Remove",toolTipText:"Remove selected watch(es)",image:"image.watch.delete"});superClass.call(this,properties);this.run=this.runMethod;};$prototype.runMethod=function(){var ps=userSmarts.runtime.Platform.getPropertyService();var p=ps.getProperty("feed","selected");if(p==undefined){alert("Please select a a watch to modify.");}else{var url=p.links.alternate;if(!url){alert("Entry missing URL for editing. Aborting!")}else if(confirm("Are you sure you want to remove watch \""+p.title+"\"")){var resource=new userSmarts.pub.Resource({url:url});var d=resource.del();d.addCallback(bind(this.delCallback,this));d.addErrback(handleResponseError);}}};$prototype.delCallback=function(){var ps=userSmarts.runtime.Platform.getPropertyService();ps.setProperty("atom:watches","status","deleted");}
namespace("userSmarts.sx.model.watches.actions");$namespace.RemoveActionAction=Class.create(userSmarts.wt.action.Action);$prototype.initialize=function(superClass,properties){properties=setdefault(properties,{id:"usersmarts.sx.model.watches.actions.removeaction",text:"Remove Action",toolTipText:"Remove selected action(s)",showText:true,image:"image.delete"});superClass.call(this,properties);};$prototype.run=function(){var ps=userSmarts.runtime.Platform.getPropertyService();var action=ps.getProperty("actions","selected");if(action==undefined){alert("Please select an action to remove.");}else{if(confirm("Are you sure that you want to remove: \""+action.getLabel()+"\"")){var watch=this.input.watch;watch.removeAction(action);this.input.getActionModel().populate();ps.setProperty("actions","selected",null);}}};namespace("userSmarts.sx.model.watches.actions");$namespace.CreateActionAction=Class.create(userSmarts.wt.action.Action);$prototype.initialize=function(superClass,properties){properties=setdefault(properties,{id:"usersmarts.sx.model.watches.actions.createwatch",text:"Create Action",toolTipText:"Create new action",showText:true,image:"image.add"});superClass.call(this,properties);};$prototype.run=function(){var dialog=new userSmarts.sx.model.watches.dialogs.CreateActionDialog();var deferred=dialog.open();deferred.addCallback(bind(this.dialogCallback,this));};$prototype.dialogCallback=function(action){if(action){var watch=this.input.watch;watch.addAction(action);this.input.getActionModel().populate();}};namespace("userSmarts.sx.model.watches.actions");$namespace.RemoveConditionAction=Class.create(userSmarts.wt.action.Action);$prototype.initialize=function(superClass,properties){properties=setdefault(properties,{id:"usersmarts.sx.model.watches.actions.removecondition",text:"Remove Condition",toolTipText:"Remove selected condition(s)",showText:true,image:"image.delete"});superClass.call(this,properties);};$prototype.run=function(){var ps=userSmarts.runtime.Platform.getPropertyService();var condition=ps.getProperty("conditions","selected");if(condition==undefined){alert("Please select a condition to remove.");}else{if(confirm("Are you sure that you want to remove: \"Condition #"+condition.getId()+"\"")){var watch=this.input.watch;watch.removeCondition(condition);this.input.getConditionModel().populate();}}};namespace("userSmarts.sx.model.watches.actions");$namespace.CreateConditionAction=Class.create(userSmarts.wt.action.Action);$prototype.initialize=function(superClass,properties){properties=setdefault(properties,{id:"usersmarts.sx.model.watches.actions.createcondition",text:"Create Condition",toolTipText:"Create new condition",showText:true,image:"image.add"});superClass.call(this,properties);};$prototype.run=function(){var watch=this.input.watch;var id=watch.getConditions().length+1;var condition=new userSmarts.sx.model.watches.pub.Condition({id:id});watch.addCondition(condition);this.input.getConditionModel().populate();};namespace("userSmarts.sx.model.watches.actions");$namespace.SaveWatchAction=Class.create(userSmarts.wt.action.Action);$prototype.initialize=function(superClass,properties){properties=setdefault(properties,{id:"usersmarts.sx.model.watches.actions.savewatch",text:"Save Watch",toolTipText:"Save Watch",showText:true,image:"image.save"});superClass.call(this,properties);};$prototype.run=function(){this.input.save();};namespace("userSmarts.sx.model.watches.views");namespace("userSmarts.sx.model.watches.views");namespace("userSmarts.sx.model.watches.views");$namespace.WatchesView=Class.create(userSmarts.ui.views.ListView);$prototype.initialize=function(superClass,properties){superClass.call(this,properties);var linkFormatter={parseObject:function(input){return null;},format:function(input){return A({href:input||"",target:"_top"},"[link]");}};this.model=new userSmarts.pub.atom.FeedModel({pageSize:5});this.model.getImage=function(c,r){if(c.index==0){var theme=userSmarts.runtime.Platform.getTheme();var icon=theme.getImage("image.watch");return icon;}}
this.model.addColumn(new userSmarts.pub.atom.EntryColumn({label:"Title",name:"title",index:0,order:true}));this.model.addColumn(new userSmarts.pub.atom.EntryColumn({label:null,name:"summary",index:1,order:true}));this.model.setSource("pub/watches/");var ps=userSmarts.runtime.Platform.getPropertyService();ps.connect("atom:watches","status",this,this.refreshList);};$prototype.init=function(site){userSmarts.ui.views.ListView.prototype.init.call(this,site);connect(this.model,"populating",this,this.displayQueryingMessage);connect(this.model,"modified",this,this.displayListingMessage);};$prototype.contributeToActionBars=function(){var actionbars=this.getSite().getActionBars();var tbmgr=actionbars.getToolbarManager();var mbmgr=actionbars.getMenuBarManager();var action=new userSmarts.sx.model.watches.actions.CreateWatchAction();tbmgr.add(action);mbmgr.add(action);var action=new userSmarts.sx.model.watches.actions.RemoveWatchesAction();tbmgr.add(action);mbmgr.add(action);var action=new userSmarts.sx.model.watches.actions.ModifyWatchAction();tbmgr.add(action);mbmgr.add(action);mbmgr.add(new userSmarts.wt.action.HorizontalSeparator());userSmarts.ui.views.ListView.prototype.contributeToActionBars.call(this);};$prototype.setSelection=function(obj){this.setProperty("selected",obj);var ps=userSmarts.runtime.Platform.getPropertyService();ps.setProperty("feed","selected",obj);};$prototype.onSelectionChange=function(event){this.setSelection(event.newValue);};$prototype.displayQueryingMessage=function(){var slmgr=this.getSite().getActionBars().getStatusLineManager();slmgr.setMessage("Querying Feeds...");};$prototype.displayListingMessage=function(){var slmgr=this.getSite().getActionBars().getStatusLineManager();slmgr.setMessage("Listing Feeds...");};$prototype.refreshList=function(event){if(event.newValue){if(event.newValue=="updated"||event.newValue=="deleted"){this.model.populate();}}}
namespace("userSmarts.sx.model.watches.perspectives");namespace("userSmarts.sx.model.watches.perspectives");namespace("userSmarts.sx.model.watches.perspectives");$namespace.WatchPerspective=function(){};$namespace.WatchPerspective.prototype.createInitialLayout=function(layout){var rootBoxId=userSmarts.ui.PageLayout.ID_ROOT_BOX;var editorAreaId=userSmarts.ui.PageLayout.ID_EDITOR_AREA;layout.createBox("left",rootBoxId,{orientation:userSmarts.ui.BoxLayout.VERTICAL,width:'400',height:'100%'});layout.createBox("right",rootBoxId,{orientation:userSmarts.ui.BoxLayout.VERTICAL,width:'*',height:'100%'});var c1r1=layout.createFolder("c1r1","left",{width:'100%',height:'100%'});c1r1.addView("userSmarts.sx.model.watches.views.WatchesView");var editorArea=layout.createFolder(editorAreaId,"right",{width:'100%',height:'100%'});};namespace("userSmarts.sx.model.watches.models");namespace("userSmarts.sx.model.watches.models");namespace("userSmarts.sx.model.watches.models");$namespace.ActionsTableModel=Class.create(userSmarts.wt.widgets.TableModel);$prototype.initialize=function(superClass,properties){properties=setdefault(properties,{columns:[],items:{},modified:new Date(),maximumRows:25,currentRow:0,buffer:[],pageSize:10});superClass.call(this,properties);this.addColumn({name:"title",index:1,order:true,getLabel:function(row){return row.getLabel();},getImage:function(row){var theme=userSmarts.runtime.Platform.getTheme();var icon;var type=row.getType();if(type=="tag"){icon=theme.getImage("image.tag");}else if(type=="email"){icon=theme.getImage("image.email");}else if(type=="text"){icon=theme.getImage("image.font");}else if(type=="im"){icon=theme.getImage("image.collaboration");}
return icon;}});this.addColumn(new userSmarts.sx.model.watches.models.ActionTableColumn({name:"title",index:1,order:true}));};$prototype.getImage=function(column,row){if(column&&typeof(column.getImage)=='function'){return column.getImage(row);}else{return null;}};$prototype.isSelected=function(row){return false;};$prototype.size=function(){return(this.buffer.length)?this.buffer.length:0;};$prototype.populate=function(position){this.setProperty("modified",true);};$prototype.addColumn=function(column){this.columns.push(column);}
namespace("userSmarts.sx.model.watches.models");$namespace.ActionTableColumn=Class.create(userSmarts.wt.widgets.TableColumn);$prototype.initialize=function(superClass,properties){superClass.call(this,properties);}
$prototype.getLabel=function(row){var name;var box;var actionNode=row;var type=actionNode.getType();var params=actionNode.getParameters();this.setParamLabels(type,params);var div=DIV();connect(div,"onclick",this,this.onclick);var tbody=TBODY();var table=TABLE({cellSpacing:'2',cellspacing:'2',cellPadding:'2',cellpadding:'2'},tbody);table.style.width="90%";div.appendChild(table);for(var idx=0;idx<params.length;idx++){name=params[idx].label;try{box=new userSmarts.wt.forms.Field({size:50,parent:null,binding:new BeanPropertyBinding(params[idx],"value")});tbody.appendChild(TR({},TD({width:"125"},B({},name+":")),TD({width:"75%"},box.paint())));}catch(e){getLogger().logError("Error creating column for action: "+e);}}
return div;};$prototype.equals=function(row){return false;}
$prototype.onclick=function(event){event.stopPropagation();};$prototype.getImage=function(row){var theme=userSmarts.runtime.Platform.getTheme();var icon;var actionNode=row;var type=actionNode.getType();if(type=="tag"){icon=theme.getImage("image.tag");}else if(type=="email"){icon=theme.getImage("image.email");}else if(type=="text"){icon=theme.getImage("image.font");}else if(type=="im"){icon=theme.getImage("image.collaboration");}
return icon;};$prototype.setParamLabels=function(type,params){var actions=userSmarts.sx.model.watches.pub.Action.ACTIONS;var action;for(var t=0;t<actions.length;t++){if(actions[t].type==type){action=actions[t];}}
for(var o=0;o<params.length;++o){if(params[o].label)continue;var name=params[o].name;for(var p=0;p<action.params.length;p++){if(action.params[p].name==name){params[o].label=action.params[p].label;}}}}
namespace("userSmarts.sx.model.watches.models");$namespace.ConditionsTableModel=Class.create(userSmarts.wt.widgets.TableModel);$prototype.initialize=function(superClass,properties){properties=setdefault(properties,{columns:[],items:{},modified:new Date(),maximumRows:25,currentRow:0,buffer:[],pageSize:10});superClass.call(this,properties);this.addColumn({name:"title",index:1,order:true,getLabel:function(row){return"Condition #"+row.getId();}});this.addColumn(new userSmarts.sx.model.watches.models.ConditionTableColumn({name:"title",index:1,order:true}));};$prototype.getImage=function(column,row){if(column&&typeof(column.getImage)=='function'){return column.getImage(row);}else{return null;}};$prototype.isSelected=function(row){return false;};$prototype.size=function(){return(this.buffer.length)?this.buffer.length:0;};$prototype.populate=function(position){this.setProperty("modified",true);};$prototype.addColumn=function(column){this.columns.push(column);}
namespace("userSmarts.sx.model.watches.models");$namespace.ConditionTableColumn=Class.create(userSmarts.wt.widgets.TableColumn);$prototype.initialize=function(superClass,properties){superClass.call(this,properties);};$prototype.getLabel=function(row){var name;var box;this.conditionNode=row;this.operation=this.conditionNode.getOperation();this.property=this.conditionNode.getPropertyName();this.values=[];var div=DIV();connect(div,"onclick",this,this.onclick);try{var odt=this.getOperationsDatatype(this.operation);var operationProps={size:1,parent:null,binding:new BeanPropertyBinding(this.conditionNode,'operation'),optionModel:new userSmarts.wt.forms.DefaultOptionModel({datatype:odt})};var operationSelect=new userSmarts.wt.forms.Select(operationProps);var pdt=this.getPropertiesDatatype(this.property);var propertyProps={size:1,parent:null,binding:new BeanPropertyBinding(this.conditionNode,"propertyName"),optionModel:new userSmarts.wt.forms.DefaultOptionModel({datatype:pdt})};this.propertySelect=new userSmarts.wt.forms.Select(propertyProps);this.value=new SPAN();var literal=new userSmarts.wt.forms.Field({size:12,parent:null,binding:new BeanPropertyBinding(this.conditionNode,"literal")});}catch(e){getLogger().logError("Error building column for condition: "+e);}
div.appendChild(B({},"Property: "));div.appendChild(this.propertySelect.paint());div.appendChild(document.createTextNode("  "));div.appendChild(operationSelect.paint());div.appendChild(document.createTextNode("  "));div.appendChild(this.value);connect(this.propertySelect.select,"onchange",this,this.onSelectChange);this.initValue();return div;};$prototype.equals=function(row){return false;};$prototype.onclick=function(event){event.stopPropagation();};$prototype.getOperations=function(){if(!this.operations){this.operations=[{name:"PropertyIsEqualTo",label:"Equals",args:1},{name:"PropertyIsNotEqualTo",label:"Not Equal To",args:1},{name:"PropertyIsGreaterThan",label:"Greater Than",args:1},{name:"PropertyIsGreaterThanOrEqualTo",label:"Greater Than or Equals",args:1},{name:"PropertyIsLessThan",label:"Less Than",args:1},{name:"PropertyIsLessThanOrEqualTo",label:"Less Than or Equals",args:1},{name:"PropertyIsNull",label:"Is NULL",args:0},{name:"PropertyIsLike",label:"Is Like",args:1},{name:"PropertyIsBetween",label:"Is Between",args:2}];}
return this.operations;};$prototype.getOperationsDatatype=function(property){var operationOptions=[];var operations=this.getOperations();for(var x=0;x<operations.length;x++){if(operations[x].name==property){operationOptions.push({label:operations[x].label,value:operations[x].name,selected:true});}else{operationOptions.push({label:operations[x].label,value:operations[x].name});}}
return{uri:{namespaceURI:"http://www.usersmarts.com/sx/core/watch/properties",prefix:"watches",localPart:"operations"},facets:{enumeration:operationOptions}};};$prototype.getProperties=function(){if(!this.properties){this.properties=[{name:"cap:event",label:"Event",datatype:{name:"eventTypes",baseType:"xsd:string",enumeration:[{label:"Tornado",value:"TOR"},{label:"Earthquake",value:"Earthquake"},{label:"Severe Thunderstorm Warning",value:"SVR"},{label:"Flash Flood Warning",value:"FFW"},{label:"Severe Marine Warning",value:"SMW"},{label:"Extreme Wind Warning",value:"EWW"},{label:"Motion Detection",value:"MOTION"}]}},{name:"cap:type",label:"Sensor Type",datatype:{baseType:"xsd:string"}},{name:"cap:category",label:"Category",datatype:{name:"categoryTypes",baseType:"xsd:string",enumeration:[{label:"Geophysical (inc. landslide)",value:"Geo"},{label:"Meteorological (inc. flood)",value:"Met"},{label:"General emergency and public safety",value:"Safety"},{label:"Law envorcement, military, local/private security",value:"Security"},{label:"Rescue and recovery",value:"Rescue"},{label:"Fire suppression and rescue",value:"Fire"},{label:"Medical and public health",value:"Health"},{label:"Pollution and other environmental",value:"Env"},{label:"Public and private transportation",value:"Transport"},{label:"Utility, telecommunication, other non-transport infrastructure",value:"Infra"},{label:"Chemical, Biological, Radiological, Nuclear",value:"CbrNE"},{label:"Other events",value:"Other"}]}},{name:"cap:severity",label:"Severity",datatype:{name:"severityType",baseType:"xsd:string",enumeration:[{label:"High",value:"10"},{label:"Medium",value:"5"},{label:"Low",value:"1"},{label:"None",value:"0"}]}}];}
return this.properties;};$prototype.getPropertiesDatatype=function(property){var propertyOptions=[];var properties=this.getProperties();for(var x=0;x<properties.length;x++){if(properties[x].name==property){propertyOptions.push({label:properties[x].label,value:properties[x].name,selected:true});}else{propertyOptions.push({label:properties[x].label,value:properties[x].name});}}
return{uri:{namespaceURI:"http://www.usersmarts.com/sx/core/watch/properties",prefix:"watches",localPart:"properties"},facets:{enumeration:propertyOptions}};};$prototype.getLiteralDatatype=function(property){return{uri:{namespaceURI:"http://www.usersmarts.com/sx/core/watch/properties#enumerations",prefix:"watches",localPart:"enumeration"},facets:{enumeration:property.datatype.enumeration}};};$prototype.initValue=function(){var value=this.propertySelect.select.value;for(var t=0;t<this.properties.length;t++){if(this.properties[t].name==value){var property=this.properties[t];if(property.datatype.enumeration){var ldt=this.getLiteralDatatype(property);var literalProps={size:1,parent:null,optionModel:new userSmarts.wt.forms.DefaultOptionModel({datatype:ldt}),binding:new BeanPropertyBinding(this.conditionNode,'literal')};var literalSelect=new userSmarts.wt.forms.Select(literalProps);this.value.appendChild(literalSelect.paint());}else{var literal=new userSmarts.wt.forms.Field({size:12,parent:null,binding:new BeanPropertyBinding(this.conditionNode,'literal')});this.value.appendChild(literal.paint());}}}};$prototype.onSelectChange=function(){var value=this.propertySelect.select.value;while(this.value.firstChild){this.value.removeChild(this.value.firstChild);}
for(var t=0;t<this.properties.length;t++){if(this.properties[t].name==value){var property=this.properties[t];if(property.datatype.enumeration){var ldt=this.getLiteralDatatype(property);var literalProps={size:1,parent:null,optionModel:new userSmarts.wt.forms.DefaultOptionModel({datatype:ldt}),binding:new BeanPropertyBinding(this.conditionNode,'literal')};var literalSelect=new userSmarts.wt.forms.Select(literalProps);this.value.appendChild(literalSelect.paint());}else{var literal=new userSmarts.wt.forms.Field({size:12,parent:null,binding:new BeanPropertyBinding(this.conditionNode,'literal')});this.value.appendChild(literal.paint());}}}};namespace("userSmarts.sx.model.watches.dialogs");namespace("userSmarts.sx.model.watches.dialogs");namespace("userSmarts.sx.model.watches.dialogs");$namespace.CreateActionDialog=Class.create(userSmarts.wt.dialogs.CDialog);$prototype.initialize=function(superClass,properties){properties=setdefault(properties,{title:"Create Watch Action",modal:false,useTables:false,enableKeys:true,width:300,height:150});superClass.call(this,properties);};$prototype.createDialogArea=function(composite){composite.setLayout(new userSmarts.wt.layout.VerticalRowLayout());this.actionTypeSelect=new userSmarts.wt.forms.SelectComposite({parent:composite,updateOnBoundsChange:true,layoutData:{width:"100%",height:"50%"},validator:null,options:this.getActionOptions(),showLabel:true,title:"Type: "});this.actionField=new userSmarts.wt.forms.FieldComposite({parent:composite,updateOnBoundsChange:true,layoutData:{width:"100%",height:"50%"},validator:null,value:"",showLabel:true,title:"Label: "});};$prototype.getActionOptions=function(){var options=[];var actions=userSmarts.sx.model.watches.pub.Action.ACTIONS;for(var q=0;q<actions.length;q++){options.push(OPTION({value:actions[q].id},actions[q].label));}
return options;};$prototype.focus=function(){this.actionTypeSelect.focus();};$prototype.okPressed=function(){if(this.deferred){this.deferred.callback(this.getAction());this.deferred=null;}};$prototype.getAction=function(){var d=new Date();var id=(d.getTime()-d.getMilliseconds())/1000;var label=this.actionField.getValue()||"Label "+Math.random();var action=this.getSelectedAction();var type=action.type;var d=new Date();var id=(d.getTime()-d.getMilliseconds())/1000;return new userSmarts.sx.model.watches.pub.Action({id:id,label:label,type:type,params:action.params.clone()});};$prototype.getSelectedAction=function(){var actions=userSmarts.sx.model.watches.pub.Action.ACTIONS;var selection=this.actionTypeSelect.getSelectedValue();for(var q=0;q<actions.length;q++){if(selection==actions[q].id){return actions[q];}}};namespace("userSmarts.sx.model.watches.dialogs");$namespace.CreateWatchDialog=Class.create(userSmarts.wt.dialogs.CDialog);$prototype.initialize=function(superClass,properties){properties=setdefault(properties,{title:"Create Watch Dialog",modal:true,useTables:false,enableKeys:true,width:300,height:200,image:"image.watch"});superClass.call(this,properties);};$prototype.createDialogArea=function(composite){composite.setLayout(new userSmarts.wt.layout.RowLayout({type:"vertical"}));this.titleField=new userSmarts.wt.forms.FieldControl({parent:composite,updateOnBoundsChange:true,layoutData:{width:"100%",height:"30%"},validator:null,value:"",showLabel:true,title:"Title: "});this.descField=new userSmarts.wt.forms.TextAreaControl({parent:composite,updateOnBoundsChange:true,layoutData:{width:"100%",height:"70%"},validator:null,value:"",showLabel:true,title:"Description: "});};$prototype.focus=function(){this.titleField.focus();};$prototype.getWatch=function(){var title=this.titleField.getValue();var description=this.descField.getValue();if(!title){return null;}
var ns="http://www.usersmarts.com/us/sx/core/watch";var doc=DOMUtils.newDocument("watch",ns);var root=doc.documentElement;var d=new Date();var uid=(d.getTime()-d.getMilliseconds())/1000;var titleE=createElementNS(ns,"title",doc);titleE.appendChild(doc.createTextNode(title));root.appendChild(titleE);var summaryE=createElementNS(ns,"summary",doc);summaryE.appendChild(doc.createTextNode(description));root.appendChild(summaryE);var conditionE=createElementNS(ns,"condition",doc);root.appendChild(conditionE);return root;};$prototype.okPressed=function(){if(this.deferred){this.deferred.callback(this.getWatch());this.deferred=null;}};namespace("userSmarts.sx.model.watches.pub");namespace("userSmarts.sx.model.watches.pub");namespace("userSmarts.sx.model.watches.pub");$namespace.Watch=Class.create(userSmarts.pub.atom.Entry);$prototype.initialize=function(superClass,properties){superClass.call(this,properties);};$prototype.getEnabled=function(){if(!this.enabled){this.enabled=scrapeText(DOMUtils.getChildren(this.node,"enabled")[0]);}
return this.enabled;};$prototype.getEnvelope=function(){var where=new GeoRSS().parseObject(this.node);if(where){return where.getEnvelope();}
return null;};$prototype.getActions=function(){if(!this.actions){this.actions=[];var actions=DOMUtils.getChildren(this.node,"action");var action;for(var t=0;t<actions.length;t++){action=userSmarts.sx.model.watches.pub.Action.parse(actions[t]);action.id=t;this.actions.push(action);}}
return this.actions;};$prototype.addAction=function(actionNode){if(this.actions){this.actions.push(actionNode);}};$prototype.removeAction=function(actionNode){if(this.actions){var id=actionNode.getId();if(!id)return;var idx=-1;for(var t=0;t<this.actions.length;t++){if(id==this.actions[t].getId()){idx=t;break;}}
if(idx>=0){this.actions.splice(idx,1);}}};$prototype.getConditions=function(){if(!this.conditions){this.conditions=[];this.intersections=[];var condition=DOMUtils.getChild(this.node,"condition");var filters=DOMUtils.getChildren(condition,"Filter");if(filters.length>0){var filter=filters[0];var ands=DOMUtils.getChildren(filter,"And");if(ands.length>0){var and=ands[0];var name;var idx=1;for(var x=0;and.childNodes[x];x++){var node=and.childNodes[x];name=DOMUtils.getName(node);if(!name){continue;}else if(name=='Intersects'||name=='Intersect'){this.intersections.push(node);}else{var c=userSmarts.sx.model.watches.pub.Condition.parse(node);c.id=idx++;this.conditions.push(c);}}}else{var node=DOMUtils.getFirstChildOfType(filter,1);if(node){name=DOMUtils.getName(node);if(name=='Intersects'||name=='Intersect'){this.intersections.push(node);}else{var c=userSmarts.sx.model.watches.pub.Condition.parse(node);c.id="1";this.conditions.push(c);}}}}}
return this.conditions;}
$prototype.getIntersections=function(){if(!this.intersections){this.getConditions();}
return this.intersections;}
$prototype.addIntersection=function(geometry){var id=null;var where=geometry;if(where){try{var type=geometry.getType().toLowerCase();if(type=="circle"||type=="ellipse"){return null;}
var ogcNS="http://www.opengis.net/ogc";var georssNS="http://www.georss.org/georss";var doc=this.node.ownerDocument||document;var intersects=createElementNS(ogcNS,"ogc:Intersects",doc);var property=createElementNS(ogcNS,"ogc:PropertyName",doc);property.appendChild(doc.createTextNode("georss:where"));intersects.appendChild(property);new GeoRSS().format(geometry,intersects);id="intersection_"+Math.random();setNodeAttribute(intersects,"id",id);if(!this.intersections){this.getIntersections();}
this.intersections.push(intersects);}catch(e){getLogger().logError("Error creating intersection from: \n"+
geometry.toString()+"\n\n"+e);}
return id;}};$prototype.removeIntersection=function(arg){var intersection;if(typeof(arg)=="string"){intersection=this.findIntersection(arg);}else{intersection=arg;}
if(!intersection)return;var idx=this.intersections.indexOf(intersection);this.intersections.splice(idx,1);};$prototype.findIntersection=function(id){for(var i=0;i<this.intersections.length;++i){if(getNodeAttribute(this.intersections[i],"id")==id){return this.intersections[i];}}
return null;};$prototype.addCondition=function(condition){this.conditions.push(condition);};$prototype.removeCondition=function(condition){var id=condition.getId();this.conditions.splice(id-1,1);var idx=1;for(var x=0;x<this.conditions.length;x++){this.conditions[x].id=idx++;}};$prototype.toXml=function(doc){var ns="http://www.usersmarts.com/us/sx/core/watch";if(!doc){doc=DOMUtils.newDocument("watch",ns);}
var watch=doc.documentElement;setNodeAttribute(watch,"xmlns:georss","http://www.georss.org/georss");setNodeAttribute(watch,"xmlns:cap","http://www.incident.com/cap/1.0");var title=createElementNS(ns,"title",doc);title.appendChild(doc.createTextNode(this.getTitle()));watch.appendChild(title);var enabled=createElementNS(ns,"enabled",doc);enabled.appendChild(doc.createTextNode(this.enabled));watch.appendChild(enabled);var summary=createElementNS(ns,"summary",doc);summary.appendChild(doc.createTextNode(this.getSummary()));watch.appendChild(summary);var condition=createElementNS(ns,"condition",doc);var filter=createElementNS("http://www.opengis.net/ogc","ogc:Filter",doc);condition.appendChild(filter);watch.appendChild(condition);var and=createElementNS("http://www.opengis.net/ogc","ogc:And",doc);filter.appendChild(and);this.getConditions();for(var x=0;x<this.intersections.length;x++){and.appendChild(this.intersections[x].cloneNode(true));}
for(var x=0;x<this.conditions.length;++x){and.appendChild(this.conditions[x].toXml(doc));}
this.getActions();for(var x=0;x<this.actions.length;x++){watch.appendChild(this.actions[x].toXml(doc));watch.appendChild(doc.createTextNode(" "));}
return watch;}
$prototype.parseEnvelope=function(envelopeElement){var lowerCorner=envelopeElement.getElementsByTagName("lowerCorner")[0];var upperCorner=envelopeElement.getElementsByTagName("upperCorner")[0];var lcText=scrapeText(lowerCorner);var ucText=scrapeText(upperCorner);var minX=Coerce.toDouble(lcText.split(" ")[1],-125.0);var minY=Coerce.toDouble(lcText.split(" ")[0],20.0);var maxX=Coerce.toDouble(ucText.split(" ")[1],-66.0);var maxY=Coerce.toDouble(ucText.split(" ")[0],60.0);var srs=srs='EPSG:4326';var bbox=new userSmarts.maps.context.BoundingBox(srs);bbox.setBoundingBox(minX,minY,maxX,maxY);return bbox;};namespace("userSmarts.sx.model.watches.pub");$namespace.Condition=Class.create(Bean);$prototype.initialize=function(superClass,properties){properties=setdefault(properties,{id:Math.random(),operation:"PropertyIsEqualTo",propertyName:"cap:event",literal:""});superClass.call(this,properties);this.ns="http://www.opengis.net/ogc";};$prototype.getId=function(){return this.id;};$prototype.getPropertyName=function(){return this.propertyName;};$prototype.getOperation=function(){return this.operation;};$prototype.getLiteral=function(){return this.literal;};$prototype.toXml=function(doc){var root;if(!doc){doc=DOMUtils.newDocument("ogc:"+this.getOperation(),this.ns);root=doc.documentElement;}else{root=createElementNS(this.ns,"ogc:"+this.getOperation(),doc);}
setNodeAttribute(root,"id",this.id);var property=createElementNS(this.ns,"ogc:PropertyName",doc);property.appendChild(doc.createTextNode(this.getPropertyName()));root.appendChild(property);var literal=createElementNS(this.ns,"ogc:Literal",doc);literal.appendChild(doc.createTextNode(this.getLiteral()));root.appendChild(literal);return root;};$namespace.Condition.parse=function(node){var id=getNodeAttribute(node,"id");var propertyName=DOMUtils.getChildText(node,"PropertyName");var value=DOMUtils.getChildText(node,"Literal");return new userSmarts.sx.model.watches.pub.Condition({id:id,propertyName:propertyName,literal:value});};namespace("userSmarts.sx.model.watches.pub");$namespace.Action=Class.create(Bean);$prototype.initialize=function(superClass,properties){var date=new Date();var defaultId=(date.getTime()-date.getMilliseconds())/1000;properties=setdefault(properties,{id:defaultId,type:"email",label:"Email Notification",params:[]});superClass.call(this,properties);this.ns="http://www.usersmarts.com/us/sx/core/watch";};$namespace.Action.ACTIONS=[new userSmarts.sx.model.watches.pub.Action({id:0,type:"email",label:"Email Notification",params:[{name:"to",label:"Addresses",value:""},{name:"subject",label:"Subject",value:""},{name:"message",label:"Message",value:""}]}),new userSmarts.sx.model.watches.pub.Action({id:1,type:"sms",label:"Text/SMS Notification",params:[{name:"phone",label:"Phone #s",value:""},{name:"subject",label:"Subject",value:""},{name:"message",label:"Message",value:""}]}),new userSmarts.sx.model.watches.pub.Action({id:2,type:"im",label:"IM Notification",params:[{name:"to",label:"Screen Name(s)",value:""},{name:"service",label:"Service",value:""},{name:"message",label:"Message",value:""}]}),new userSmarts.sx.model.watches.pub.Action({id:3,type:"tag",label:"Alert Tagging",params:[{name:"tags",label:"Tag(s)",value:""}]})];$prototype.getId=function(){return this.id;};$prototype.getType=function(){return this.type;};$prototype.getLabel=function(){return this.label;};$prototype.getParameters=function(){return this.params;};$prototype.clone=function(){var params=[];for(var i=0;i<this.params.length;++i){params.push({name:this.params[i].name,label:this.params[i].label,value:this.params[i].value});}
return new userSmarts.sx.model.watches.pub.Action({id:this.id,type:this.type,label:this.label,params:params});};$prototype.toXml=function(doc){var root;if(!doc){doc=DOMUtils.newDocument("action",this.ns);root=doc.documentElement;}else{root=createElementNS(this.ns,"action",doc);}
setNodeAttribute(root,"id",this.id);setNodeAttribute(root,"label",this.label);setNodeAttribute(root,"type",this.type);var param;for(var p=0;p<this.params.length;p++){param=createElementNS(this.ns,"param",doc);setNodeAttribute(param,"name",this.params[p].name);setNodeAttribute(param,"label",this.params[p].label);param.appendChild(doc.createTextNode(this.params[p].value||""));root.appendChild(param);}
return root;};$namespace.Action.parse=function(node){var id=getNodeAttribute(node,"id");var label=getNodeAttribute(node,"label");var type=getNodeAttribute(node,"type");var params=[];var ps=DOMUtils.getChildren(node,"param");for(var i=0;i<ps.length;++i){params.push({name:getNodeAttribute(ps[i],"name"),label:getNodeAttribute(ps[i],"label"),value:scrapeText(ps[i])});}
return new userSmarts.sx.model.watches.pub.Action({id:id,label:label,type:type,params:params});};namespace("userSmarts.sx.model.watches.editors");namespace("userSmarts.sx.model.watches.editors");namespace("userSmarts.sx.model.watches.editors");$namespace.WatchEditor=Class.create(userSmarts.ui.MultiPageEditorPart);$prototype.initialize=function(superclass,properties){superclass.call(this,properties);};$prototype.init=function(site,input){userSmarts.ui.MultiPageEditorPart.prototype.init.call(this,site,input);this.loadedListener=connect(input,"loaded",this,this.onInputLoaded);this.updatedListener=connect(input,"updated",this,this.onInputUpdated);};$prototype.createPages=function(){this.input.load();};$prototype.createReportPages=function(){if(!this.hasPages()){var page=new userSmarts.sx.model.watches.editors.WatchPageOne();this.addPage(page);this.overviewPage=page;page=new userSmarts.sx.model.watches.editors.WatchPageTwo();this.addPage(page);this.mapPage=page;page=new userSmarts.sx.model.watches.editors.WatchPageThree();this.addPage(page);this.conditionsPage=page;page=new userSmarts.sx.model.watches.editors.WatchPageFour();this.addPage(page);this.actionsPage=page;}};$prototype.doSave=function(){this.input.save();};$prototype.doCancel=function(){};$prototype.onInputLoaded=function(event){var success=event.newValue;if(success){if(!this.outer||!this.tabControl){this.createPartControl();}
this.createReportPages();this.outer.update();userSmarts.runtime.Platform.getPropertyService().setProperty("editor","initialized",this);}else{var page=userSmarts.ui.PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();page.closeEditor(this,false);userSmarts.runtime.Platform.getPropertyService().setProperty("reports","deleted",null);}};$prototype.onInputUpdated=function(event){this.dirty=false;for(var p=0;p<this.pages.length;++p){this.pages[p].dirty=false;}};$prototype.contributeToActionBars=function(){var bars=this.getSite().getActionBars();var tbmgr=bars.getToolbarManager();if(!this.saveEditorAction){this.saveEditorAction=new userSmarts.wt.action.SaveEditorAction({editor:this});if(userSmarts.sx.Plugin.isUserInRole("EDIT_WATCH")){this.editable=true;tbmgr.add(this.saveEditorAction);}else{this.editable=false;}}};$prototype.getMap=function(){return this.mapPage.getMap();};$prototype.getViewContext=function(){return this.mapPage.getViewContext();};$prototype.getViewContextModel=function(){return this.input.getViewContextModel();};$prototype.dispose=function(){if(this.loadedListener){disconnect(this.loadedListener);this.loadedListener=null;}
if(this.updatedListener){disconnect(this.updatedListener);this.updatedListener=null;}
userSmarts.ui.MultiPageEditorPart.prototype.dispose.call(this);};namespace("userSmarts.sx.model.watches.editors");$namespace.WatchEditorInput=Class.create(userSmarts.ui.EditorInput);$prototype.initialize=function(superClass,properties){superClass.call(this,properties);this.resource=new userSmarts.pub.Resource({url:this.url,params:{format:"text/xml"}});this.savedCallback=bind(this.onUpdated,this);this.errback=bind(function(arg){handleResponseError(arg);this.setProperty("loaded",false);},this);}
$prototype.equals=function(other){return this.url==other.url;};$prototype.get=function(){return this.resource.get();};$prototype.put=function(content){return this.resource.put(content);};$prototype.del=function(content){return this.resource.del(content);};$prototype.load=function(){var def=this.get();def.addCallback(bind(this.onWatchLoaded,this));def.addErrback(this.errback);};$prototype.onWatchLoaded=function(xml){this.watch=new userSmarts.sx.model.watches.pub.Watch({node:xml.documentElement});this.id=this.watch.getId();this.watchTitle=this.watch.getTitle();this.watchSummary=this.watch.getSummary();this.enabled=this.watch.getEnabled();var workspace=userSmarts.runtime.Platform.getWorkspace();if(workspace){var link=workspace.getLink("defaultMap");var res=new userSmarts.pub.Resource({url:link.href});var def=res.get();def.addCallback(bind(this.onVCLoaded,this));def.addErrback(this.errback);}else{this.watchMap=this.createDefaultViewContext();this.setProperty("loaded",true);}};$prototype.onVCLoaded=function(xml){if(!isXmlNode(xml)){xml=xml.responseXml;}
var parser=new userSmarts.maps.context.ViewContextParser();this.watchMap=parser.fromXML(xml);var envelope=this.watch.getEnvelope();if(envelope){this.watchMap.setView(envelope);}
this.setProperty("loaded",true);};$prototype.save=function(){this.watch.setTitle(this.watchTitle);this.watch.setSummary(this.watchSummary);var xml=this.watch.toXml();var def=this.put(xml);def.addCallback(this.savedCallback);def.addErrback(handleResponseError);};$prototype.onUpdated=function(){var ps=userSmarts.runtime.Platform.getPropertyService();ps.setProperty("atom:watches","status","updated");this.setProperty("updated",true);};$prototype.getViewContext=function(){return this.watchMap;};$prototype.getMap=function(){return this.map;};$prototype.buildViewContextModel=function(){var context=this.reportMap;if(context){this.vcmodel=new userSmarts.map.ui.ViewContextTableModel({context:context});}};$prototype.getActionModel=function(){if(!this.actionModel){this.actionModel=new userSmarts.sx.model.watches.models.ActionsTableModel({buffer:this.watch.getActions()});}
return this.actionModel;};$prototype.getConditionModel=function(){if(!this.conditionModel){this.conditionModel=new userSmarts.sx.model.watches.models.ConditionsTableModel({buffer:this.watch.getConditions()});}
return this.conditionModel;};$prototype.createDefaultViewContext=function(){var layerObjs=[];var srs=srs='EPSG:4326';var bbox=new userSmarts.maps.context.BoundingBox(srs);bbox.setBoundingBox(-160,20,-66,70);var serverObj=new userSmarts.maps.context.Server({url:"http://www2.demis.nl/wms/wms.asp?wms=WorldMap",title:"DEMIS WMS",service:"WMS",version:"1.1.1"});var layerObjs=[new userSmarts.maps.context.Layer({server:serverObj,name:'Bathymetry',title:'Bathymetry',srs:"EPSG:4326",visible:true,queryable:false,opacity:1.0}),new userSmarts.maps.context.Layer({server:serverObj,name:'Topography',title:'Topography',srs:"EPSG:4326",visible:true,queryable:false,opacity:1.0})];var context=new userSmarts.maps.context.ViewContext({id:"",title:"Map of "+this.title,abstr:"Map regarding "+this.summary,layers:layerObjs,boundingBox:bbox,width:600,height:500});var envelope=this.watch.getEnvelope();if(envelope){context.setView(envelope);}
return context;};namespace("userSmarts.sx.model.watches.editors");$namespace.WatchPageOne=Class.create(userSmarts.ui.EditorPart);$prototype.initialize=function(superclass,properties){superclass.call(this,properties);this.label="Overview";};$prototype.createPartControl=function(){if(!this.control){this.control=new userSmarts.wt.widgets.Control({'class':'multi-editor-page'});}
if(this.input){this.updateControl();}
return this.control;};$prototype.updateControl=function(){if(this.listeners){for(var i=0;i<this.listeners.length;++i){disconnect(this.listeners);}}
this.listeners=[];var node=this.control.getNode();var col1;var col2;var tbody=TBODY({});var table=TABLE({cellpadding:"3",cellPadding:"3",cellspacing:"0",cellSpacing:"0",border:"0",width:"100%"},tbody);node.appendChild(table);col1=TD({width:"100px",'class':'editor-section-title'},"Watch Details");col2=TD({},"");tbody.appendChild(TR({},col1,col2));col1=TD({width:"100px"});col2=TD({});col1.appendChild(SPAN({'class':'editor-section-field-label'},"Title: "));var box=new userSmarts.wt.forms.Field({size:50,parent:null,binding:new BeanPropertyBinding(this.input,'watchTitle')});col2.appendChild(box.paint());this.listeners.push(connect(this.input,"watchTitle",this,this.onInputChange));tbody.appendChild(TR({},col1,col2));col1=TD({width:"100px",valign:"top",vAlign:"top"});col2=TD({});col1.appendChild(SPAN({'class':'editor-section-field-label'},"Executive Summary: "));box=new userSmarts.wt.forms.TextArea({cols:40,rows:3,parent:null,binding:new BeanPropertyBinding(this.input,'watchSummary')});this.listeners.push(connect(this.input,"watchSummary",this,this.onInputChange));col2.appendChild(box.paint());tbody.appendChild(TR({},col1,col2));col1=TD({width:"100px",valign:"top",vAlign:"top"});col2=TD({});col1.appendChild(SPAN({'class':'editor-section-field-label'},"Enabled: "));var checkbox=INPUT({type:"checkbox"});checkbox.defaultChecked=checkbox.checked=eval(this.input.enabled);connect(checkbox,'onclick',this,this.onEnabledChange);col2.appendChild(checkbox);tbody.appendChild(TR({},col1,col2));col1=TD({width:"100px",'class':'editor-section-title'},"Actions");col2=TD({},"");tbody.appendChild(TR({},col1,col2));col1=TD({width:"100%",colspan:"2",colSpan:'2'});var link;var icon;if(userSmarts.sx.Plugin.isUserInRole("EDIT_WATCH")){this.editable=true;icon=userSmarts.runtime.Platform.getTheme().getImage("image.save");this.listeners.push(connect(icon,"onclick",this,this.doSave));col1.appendChild(icon);link=SPAN({'class':'editor-link'},"Save watch");this.listeners.push(connect(link,"onclick",this,this.doSave));col1.appendChild(link);col1.appendChild(BR());}else{this.editable=false;}
tbody.appendChild(TR({},col1));};$prototype.onInputChange=function(event){this.setProperty("dirty",true);};$prototype.onEnabledChange=function(event){this.setProperty("dirty",true);if(event._src.checked){this.input.watch.enabled="true";}else{this.input.watch.enabled="false";}}
$prototype.doSave=function(){this.input.save();this.setProperty("dirty",false);};namespace("userSmarts.sx.model.watches.editors");$namespace.WatchPageTwo=Class.create(userSmarts.ui.EditorPart);$prototype.initialize=function(superclass,properties){superclass.call(this,properties);this.label="Map";};$prototype.createPartControl=function(){if(!this.control){this.control=new userSmarts.sx.model.watches.editors.WatchMap({layoutData:{width:"100%",height:"100%"},center:new OpenLayers.LonLat(-95.0,38.5),zoom:2});this.addedListener=connect(this.control,"featureAdded",this,this.onFeatureAdded);this.removedListener=connect(this.control,"featureRemoved",this,this.onFeatureRemoved);this.enabledListener=connect(this.control,"enabled",this,this.displayGeometries);}
return this.control;};$prototype.dispose=function(){disconnect(this.addedListener);disconnect(this.removedListener);disconnect(this.enabledListener);this.addedListener=null;this.removedListener=null;this.enabledListener=null;userSmarts.ui.EditorPart.prototype.dispose.call(this);};$prototype.onFeatureAdded=function(event){var feature=event.newValue;var fgeom=feature.geometry;var type;var points=[];if(fgeom instanceof OpenLayers.Geometry.Point){points.push(new Point(fgeom.x,fgeom.y));type="Point";}else if(fgeom instanceof OpenLayers.Geometry.Polygon){points=feature.geometry.components[0].components;type="Polygon";}else{points=feature.geometry.components;type="Line";}
var geometry=new Geometry(type);for(var p=0;p<points.length;++p){geometry.addPoint(new Point(points[p].x,points[p].y));}
var intersectionId=this.input.watch.addIntersection(geometry);geometry.intersectionId=intersectionId;feature.intersectionId=intersectionId;this.setProperty("dirty",true);};$prototype.onFeatureRemoved=function(event){var feature=event.newValue;var id=feature.intersectionId;this.input.watch.removeIntersection(id);this.setProperty("dirty",true);};$prototype.contributeToActionBars=function(tbmgr){};$prototype.getMap=function(){return this.control;};$prototype.getViewContext=function(){return this.input.getViewContext();};$prototype.removeDrawnVersion=function(geometry){var id=geometry.intersectionId;var features=this.control.vectorLayer.features;for(var f=0;f<features.length;++f){if(features[f].metadata&&id==features[f].intersectionId){this.control.vectorLayer.removeFeatures(features[f]);break;}}};$prototype.displayGeometries=function(){var input=this.input;var aoi=null;var format=new GeoRSS();var is=input.watch.getIntersections();var isId;var geom;for(var i=0;i<is.length;++i){isId=getNodeAttribute(is[i],"id");if(!isId){isId="intersection_"+Math.random();setNodeAttribute(is[i],"id",isId);}
geom=format.parseObject(is[i]);this.getMap().addGeometry(geom,{intersectionId:isId});if(!aoi){aoi=geom.getEnvelope();}else{var env=geom.getEnvelope();aoi.points[0].x=Math.min(env.getPoints()[0].x,aoi.points[0].x);aoi.points[0].y=Math.min(env.getPoints()[0].y,aoi.points[0].y);aoi.points[1].x=Math.max(env.getPoints()[1].x,aoi.points[1].x);aoi.points[1].y=Math.max(env.getPoints()[1].y,aoi.points[1].y);}}
if(aoi){var map=this.getMap();map.setPreferredExtent(aoi);}};$namespace.WatchMap=Class.create(userSmarts.maps.ol.Map);$prototype.initialize=function(superClass,properties){superClass.call(this,properties);};$prototype.addControls=function(){var fabind=bind(this.onFeatureAdded,this);var controls=[new OpenLayers.Control.DrawFeature(this.vectorLayer,OpenLayers.Handler.Polygon,{'displayClass':'olControlDrawFeaturePolygon'}),new OpenLayers.Control.DrawFeature(this.vectorLayer,OpenLayers.Handler.Path,{'displayClass':'olControlDrawFeaturePath'}),new OpenLayers.Control.DrawFeature(this.vectorLayer,OpenLayers.Handler.Point,{'displayClass':'olControlDrawFeaturePoint'})];for(var c=0;c<controls.length;++c){controls[c].featureAdded=fabind;}
var navTool=new OpenLayers.Control.Navigation();controls.splice(0,0,navTool);var helpTool=new userSmarts.maps.ol.control.Help();controls.push(helpTool);var panel=new OpenLayers.Control.Panel({defaultControl:navTool,CLASS_NAME:"OpenLayers.Control.EditingToolbar"});panel.displayClass="olControlEditingToolbar";panel.addControls(controls);this.map.addControl(panel);this.selectFeatureControl=new userSmarts.maps.ol.control.SelectFeature(this.vectorLayer,{onSelect:bind(this.onFeatureSelect,this),onUnselect:bind(this.onFeatureUnselect,this),onKeyPressed:bind(this.onKeyPressed,this),onDoubleClickFeature:bind(this.onDoubleClickFeature,this)});this.map.addControl(this.selectFeatureControl);this.selectFeatureControl.activate();};$prototype.onFeatureAdded=function(feature){feature.state=OpenLayers.State.INSERT;this.setProperty("featureAdded",feature);};$prototype.selectFeature=function(feature){if(this.selectedFeature&&this.selectedFeature.geometry){this.selectFeatureControl.unselect(this.selectedFeature);}
if(feature){this.selectFeatureControl.select(feature);}};$prototype.onFeatureSelect=function(feature){this.selectedFeature=feature;};$prototype.onFeatureUnselect=function(feature){this.selectedFeature=null;};$prototype.onKeyPressed=function(code){switch(code){case OpenLayers.Event.KEY_DELETE:var features=this.getSelectedVectors();if(features.length>0){var feature=features[0];if(confirm("Delete this AOI?")){this.removeVector(feature);this.setProperty("featureRemoved",feature);}}};};$prototype.onDoubleClickFeature=function(feature){if(confirm("Delete this AOI?")){this.removeVector(feature);this.setProperty("featureRemoved",feature);}}
$prototype.dispose=function(){userSmarts.maps.ol.Map.prototype.dispose.call(this);};namespace("userSmarts.sx.model.watches.editors");$namespace.WatchPageThree=Class.create(userSmarts.ui.EditorPart);$prototype.initialize=function(superclass,properties){superclass.call(this,properties);this.label="Conditions";};$prototype.init=function(site,input){this.site=site;this.input=input;};$prototype.createPartControl=function(){if(!this.composite){this.composite=new userSmarts.wt.widgets.Composite({updateOnBoundsChange:true,layoutData:{width:"100%",height:"100%"},margin:{top:0,bottom:8,left:0,right:0}});this.composite.setLayout(new userSmarts.wt.layout.RowLayout({type:"horizontal"}));this.composite.getNode();this.createLeftSideContainer(this.composite);this.createRightSideContainer(this.composite);var model=this.input.getConditionModel();this.list.setModel(model);}
this.composite.update();return this.composite;};$prototype.createLeftSideContainer=function(parent){var section=new userSmarts.ui.Section({parent:parent,width:"275px",height:"100%",collapseable:false});section.setText("Conditions");section.setDescription("These constraints combined with the geospatial contstraints "+"must be met before the respective actions are performed.");var client=new userSmarts.wt.widgets.Control({'class':'section-body'});var node=client.getNode();this.createActionAction=new userSmarts.sx.model.watches.actions.CreateConditionAction({input:this.input,nodeName:"DIV"});node.appendChild(this.createActionAction.getNode());node.appendChild(BR());this.removeActionAction=new userSmarts.sx.model.watches.actions.RemoveConditionAction({input:this.input,nodeName:"DIV"});node.appendChild(this.removeActionAction.getNode());node.appendChild(BR());this.refreshListAction=new userSmarts.wt.action.RefreshListAction({showText:true,nodeName:"DIV"});node.appendChild(this.refreshListAction.getNode());node.appendChild(BR());this.expandListAction=new userSmarts.wt.action.ExpandListAction({showText:true,nodeName:"DIV"});node.appendChild(this.expandListAction.getNode());node.appendChild(BR());this.collapseListAction=new userSmarts.wt.action.CollapseListAction({showText:true,nodeName:"DIV"});node.appendChild(this.collapseListAction.getNode());node.appendChild(BR());this.saveActionAction=new userSmarts.sx.model.watches.actions.SaveWatchAction({input:this.input,nodeName:"DIV"});node.appendChild(this.saveActionAction.getNode());section.setClient(client);this.leftSide=section;};$prototype.createRightSideContainer=function(parent){this.list=new userSmarts.wt.widgets.List({parent:parent,updateOnBoundsChange:true,useInnerDIVs:true,layoutData:{width:"*"},border:{style:'solid',bottom:1,top:1,left:1,right:1},margin:{left:0,right:2,top:0,bottom:0}});connect(this.list,"selected",this,this.onConditionSelect);this.refreshListAction.list=this.list;this.expandListAction.list=this.list;this.collapseListAction.list=this.list;};$prototype.onConditionSelect=function(obj){var ps=userSmarts.runtime.Platform.getPropertyService();var p=ps.setProperty("conditions","selected",obj.newValue);}
namespace("userSmarts.sx.model.watches.editors");$namespace.WatchPageFour=Class.create(userSmarts.ui.EditorPart);$prototype.initialize=function(superclass,properties){superclass.call(this,properties);this.label="Actions";};$prototype.init=function(site,input){this.site=site;this.input=input;};$prototype.createPartControl=function(){if(!this.composite){this.composite=new userSmarts.wt.widgets.Composite({updateOnBoundsChange:true,layoutData:{width:"100%",height:"100%"},margin:{top:0,bottom:8,left:0,right:0}});this.composite.setLayout(new userSmarts.wt.layout.RowLayout({type:"horizontal"}));this.composite.getNode();this.createLeftSideContainer(this.composite);this.createRightSideContainer(this.composite);var model=this.input.getActionModel();this.list.setModel(model);}
this.composite.update();return this.composite;};$prototype.createLeftSideContainer=function(parent){var section=new userSmarts.ui.Section({parent:parent,width:"275px",height:"100%",collapseable:false});section.setText("Actions");section.setDescription("This list contains a list of actions to perform "+"when the conditions of this watch have been met.");var client=new userSmarts.wt.widgets.Control({'class':'section-body'});var node=client.getNode();this.createActionAction=new userSmarts.sx.model.watches.actions.CreateActionAction({input:this.input,nodeName:"DIV"});node.appendChild(this.createActionAction.getNode());node.appendChild(BR());this.removeActionAction=new userSmarts.sx.model.watches.actions.RemoveActionAction({input:this.input,nodeName:"DIV"});node.appendChild(this.removeActionAction.getNode());node.appendChild(BR());this.refreshListAction=new userSmarts.wt.action.RefreshListAction({showText:true,nodeName:"DIV"});node.appendChild(this.refreshListAction.getNode());node.appendChild(BR());this.expandListAction=new userSmarts.wt.action.ExpandListAction({showText:true,nodeName:"DIV"});node.appendChild(this.expandListAction.getNode());node.appendChild(BR());this.collapseListAction=new userSmarts.wt.action.CollapseListAction({showText:true,nodeName:"DIV"});node.appendChild(this.collapseListAction.getNode());node.appendChild(BR());this.saveActionAction=new userSmarts.sx.model.watches.actions.SaveWatchAction({input:this.input,nodeName:"DIV"});node.appendChild(this.saveActionAction.getNode());section.setClient(client);this.leftSide=section;};$prototype.createRightSideContainer=function(parent){this.list=new userSmarts.wt.widgets.List({parent:parent,updateOnBoundsChange:true,useInnerDIVs:true,layoutData:{width:"*"},border:{style:'solid',bottom:1,top:1,left:1,right:1},margin:{left:0,right:2,top:0,bottom:0}});connect(this.list,"selected",this,this.onActionSelect);this.refreshListAction.list=this.list;this.expandListAction.list=this.list;this.collapseListAction.list=this.list;};$prototype.onActionSelect=function(obj){var ps=userSmarts.runtime.Platform.getPropertyService();var p=ps.setProperty("actions","selected",obj.newValue);}
namespace("userSmarts.sx.model.situations.views");namespace("userSmarts.sx.model.situations.views");namespace("userSmarts.sx.model.situations.views");$namespace.SituationsView=Class.create(userSmarts.ui.views.ListView);$prototype.initialize=function(superClass,desc){superClass.call(this,desc);this.model=new userSmarts.sx.model.situations.models.SituationsModel();connect(this.model,'modified',this,this.onModelUpdated);};$prototype.init=function(site){userSmarts.ui.views.ListView.prototype.init.call(this,site);};$prototype.contributeToActionBars=function(){connect(this.model,'populating',this,this.displayQueryMessage);connect(this.model,'modified',this,this.displayFinishedMessage);var actionbars=this.getSite().getActionBars();var tbmgr=actionbars.getToolbarManager();var mbmgr=actionbars.getMenuBarManager();var action;if(userSmarts.sx.Plugin!=undefined){var filled=false;if(userSmarts.sx.Plugin.isUserInRole("CREATE_SITUATION")){action=new userSmarts.sx.model.situations.actions.NewSituationAction();tbmgr.add(action);mbmgr.add(action);filled=true;}
if(userSmarts.sx.Plugin.isUserInRole("EDIT_SITUATION")){action=new userSmarts.sx.model.situations.actions.EditSituationAction();tbmgr.add(action);mbmgr.add(action);filled=true;}
if(userSmarts.sx.Plugin.isUserInRole("DELETE_SITUATION")){action=new userSmarts.sx.model.situations.actions.DeleteSituationAction();tbmgr.add(action);mbmgr.add(action);filled=true;}
if(filled){mbmgr.add(new userSmarts.wt.action.HorizontalSeparator());}}
var zoomToSituationAction=new userSmarts.wt.action.Action({id:'zoomToSituationAction',text:"Zoom to Situation",toolTipText:'Zoom to selected situation',run:bind(this.zoomToSelectedSituation,this),image:"image.situation.zoom.single"});mbmgr.add(zoomToSituationAction);var zoomToPageAction=new userSmarts.wt.action.Action({id:'zoomToPageAction',text:"Zoom to Group",toolTipText:'Zoom to current page of situation',run:bind(this.zoomToPageOfSituations,this),image:"image.situation.zoom.group"});mbmgr.add(zoomToPageAction);mbmgr.add(new userSmarts.wt.action.HorizontalSeparator());userSmarts.ui.views.ListView.prototype.contributeToActionBars.call(this);};$prototype.displayQueryMessage=function(){var slmgr=this.getSite().getActionBars().getStatusLineManager();slmgr.setMessage("Querying situations...");};$prototype.displayFinishedMessage=function(success){var slmgr=this.getSite().getActionBars().getStatusLineManager();slmgr.setMessage(success?"Listing situations":"Error listing situations");};$prototype.setSelection=function(obj){if(!obj)obj={id:null,label:null,url:null};this.selected=obj.id;var ps=userSmarts.runtime.Platform.getPropertyService();ps.setProperty("situations","selected",obj);};$prototype.onSelectionChange=function(event){var id=null;var url=null;var title=null;var selection=event.newValue;if(selection){var id=selection.getId();var url=selection.getLink();var title=selection.getTitle();var where=selection.getWhere();if(where){var bbox=where.getEnvelope();this.setProperty("selectedSituationAOI",bbox);}}
this.setSelection({id:id,url:url,label:title});};$prototype.onModelUpdated=function(event){this.checkSelected();};$prototype.checkSelected=function(){var present=false;if(this.selected){var rows=this.model.getRows();for(var i=0;i<rows.length;++i){if(rows[i].getId()==this.selected){present=true;this.list.select(rows[i]);}}}
if(!present){this.setSelection(null);this.setProperty("selectedSituationAOI",null);}};$prototype.zoomToSelectedSituation=function(){if(this.selectedSituationAOI){var ps=userSmarts.runtime.Platform.getPropertyService();ps.setProperty("map","aoi",this.selectedSituationAOI);}else{alert("Must select an situation from the list first!");}};$prototype.zoomToPageOfSituations=function(){if(this.model){var ps=userSmarts.runtime.Platform.getPropertyService();ps.setProperty("map","aoi",this.model.getWhere());}};$prototype.setAOI=function(aoi){if(this.model){this.model.setBoundingBox(aoi);}};namespace("userSmarts.sx.model.situations.models");namespace("userSmarts.sx.model.situations.models");namespace("userSmarts.sx.model.situations.models");$namespace.SituationsModel=Class.create(userSmarts.pub.atom.FeedModel);$prototype.initialize=function(superClass,properties){properties=setdefault(properties,{pageSize:50,nodeOffset:0,depth:0,nodeNames:["entry"]});superClass.call(this,properties);this.addColumn(new userSmarts.pub.atom.EntryColumn({label:"Title",name:"title",order:true}));this.addColumn(new userSmarts.pub.atom.EntryColumn({name:"summary",order:true}));this.addColumn(new userSmarts.pub.atom.EntryColumn({label:"Issued",name:"published",order:true}));this.addColumn(new userSmarts.pub.atom.EntryColumn({label:"Updated",name:"updated",order:true}));var workspace=userSmarts.runtime.Platform.getWorkspace();this.setSource(new userSmarts.pub.atom.GeoCollection({url:workspace.getLink("situations").href,factory:new userSmarts.pub.atom.DefaultEntryFactory({entryClass:"userSmarts.pub.atom.GeoEntry"})}));var ps=userSmarts.runtime.Platform.getPropertyService();ps.connect("situations","*",this,this.onSituationsChange);};$prototype.getImage=function(){return userSmarts.runtime.Platform.getTheme().getImage("image.situation");};$prototype.onSituationsChange=function(event){var property=event.propertyName;if(property=="created"||property=="deleted"||property=="updated"){this.populate(this.getOffset());}};namespace("userSmarts.sx.model.situations.actions");namespace("userSmarts.sx.model.situations.actions");namespace("userSmarts.sx.model.situations.actions");$namespace.NewSituationAction=Class.create(userSmarts.wt.action.Action);$prototype.initialize=function(superClass,properties){properties=setdefault(properties,{id:'userSmarts.sx.model.situations.actions.newsituation',text:"New",toolTipText:'Define New Situation',image:"image.situation.new"});superClass.call(this,properties);this.callback=bind(this.onSituationCreated,this);this.errback=handleResponseError;};$prototype.run=function(){var title=prompt("Enter a title:","");if(!title){alert("Must enter a valid title!");return;}
var desc=prompt("Enter a description:","");var url=userSmarts.runtime.Platform.getWorkspace().getLink("situations").href;var aoi=userSmarts.runtime.Platform.getPropertyService().getProperty("map","aoi");var situation=new userSmarts.pub.atom.GeoEntry();situation.setTitle(title);situation.setSummary(desc);situation.setWhere(aoi);var collection=new userSmarts.pub.atom.GeoCollection();collection.setURL(url);var def=collection.add(situation);def.addCallback(this.callback);def.addErrback(this.errback);};$prototype.onSituationCreated=function(situation){var id=situation.getId();situation.getCollection().dispose();var ps=userSmarts.runtime.Platform.getPropertyService();ps.setProperty("situations","created",id);};namespace("userSmarts.sx.model.situations.actions");$namespace.EditSituationAction=Class.create(userSmarts.wt.action.Action);$prototype.initialize=function(superClass,properties){properties=setdefault(properties,{id:'userSmarts.sx.model.situations.actions.editsituation',text:"Edit",toolTipText:'Edit Situation Information',image:"image.situation.edit"});superClass.call(this,properties);this.callback=bind(this.onSituationRetrieved,this);this.updatedCallback=bind(this.onSituationUpdated,this);this.errback=bind(function(arg){handleResponseError(arg);var ps=userSmarts.runtime.Platform.getPropertyService();ps.setProperty("situations","deleted",null);},this);};$prototype.run=function(){var ps=userSmarts.runtime.Platform.getPropertyService();var selection=ps.getProperty("situations","selected");if(selection&&selection.url){var url=selection.url;var situation=new userSmarts.pub.atom.GeoEntry();situation.setURL(url);var def=situation.get();def.addCallback(this.callback);def.addErrback(this.errback);}};$prototype.onSituationRetrieved=function(situation){var title=prompt("Enter new title title:",situation.getTitle());if(!title){alert("Must enter a valid title!");return;}
situation.setTitle(title);var desc=prompt("Enter the new description:",situation.getSummary());situation.setSummary(desc);var def=situation.put();def.addCallback(this.updatedCallback);def.addErrback(this.errback);};$prototype.onSituationUpdated=function(situation){var id=situation.getId();situation.dispose();var ps=userSmarts.runtime.Platform.getPropertyService();ps.setProperty("situations","updated",id);};namespace("userSmarts.sx.model.situations.actions");$namespace.DeleteSituationAction=Class.create(userSmarts.wt.action.Action);$prototype.initialize=function(superClass,properties){properties=setdefault(properties,{id:'deleteSituationAction',text:"Delete",toolTipText:'Delete Selected Situation',image:"image.situation.delete"});superClass.call(this,properties);this.callback=bind(this.onSituationDeleted,this);this.errback=handleResponseError;};$prototype.run=function(){var ps=userSmarts.runtime.Platform.getPropertyService();var selection=ps.getProperty("situations","selected");if(selection&&selection.url){var label=selection.label||selection.id||"[situation]";if(userSmarts.wt.dialogs.MessageDialog.openConfirm("Delete Item","Are you sure you want to delete '"+label+"'?")){var url=selection.url;var situation=new userSmarts.pub.atom.GeoEntry();situation.setURL(url);var def=situation.del();def.addCallback(this.callback);def.addErrback(this.errback);}}};$prototype.onSituationDeleted=function(){var ps=userSmarts.runtime.Platform.getPropertyService();ps.setProperty("situations","deleted",null);ps.setProperty("situations","selected",null);};namespace("userSmarts.sx.model.situations.actions");$namespace.ConstrainAction=Class.create(userSmarts.wt.action.StatefulAction);$prototype.initialize=function(superClass,properties){properties=setdefault(properties,{id:'userSmarts.sx.model.situations.actions.constrainsituations',text:"Constrain Situations",toolTipText:'Constrain Situations using Keywords',image:"image.situation.constrain"});superClass.call(this,properties);};$prototype.run=function(){if(!this.isChecked())return;var keywords;var useAnd=true;var wb=userSmarts.ui.PlatformUI.getWorkbench();var page=wb.getActiveWorkbenchWindow().getActivePage();var view=page.findView("userSmarts.sx.model.situations.views.SituationsView");if(view){keywords=view.model.getKeywords().toString(" ");}else{keywords="";}
var keywords=prompt("Enter keywords, separated by spaces:",keywords);if(!keywords){keywords="";}
view.model.setAndTerms(false);view.model.setKeywords(keywords.split(" "));this.setChecked(false);};namespace("userSmarts.sx.model.situations.pub");namespace("userSmarts.sx.model.situations.pub");namespace("userSmarts.sx.model.situations.pub");$namespace.SituationEntry=Class.create(userSmarts.pub.atom.Entry);$prototype.initialize=function(superClass,properties){if(isPrototype(arguments))return;properties=setdefault(properties,{});superClass.call(this,properties);};$prototype.getUpdated=function(){if(this.node){this.getValue("updated","updated","");}}
$prototype.setPublished=function(published){this.published=published;};$prototype.getPublished=function(){if(this.node){return this.getValue("published","published","");}};$prototype.setBoundingBox=function(bbox){if(bbox instanceof Geometry){this.bbox=bbox;}};$prototype.getBoundingBox=function(){if(!this.bbox&&this.node){var boxStr=this.getValue("boxStr","box","");var coords=boxStr.split(" ");if(coords.length==4){this.bbox=new Geometry("Box");this.bbox.addPoint(new Point({x:coords[0]*1,y:coords[1]*1}));this.bbox.addPoint(new Point({x:coords[2]*1,y:coords[3]*1}));}}
return this.bbox;}
$prototype.toXml=function(doc){var ATOM_NS='http://www.w3.org/2005/Atom';if(!doc||doc.nodeType!=9){doc=createXMLDocument('entry','http://www.w3.org/2005/Atom',null);}
createElementNS('http://www.w3.org/2005/Atom','entry',doc);var entry=doc.documentElement;this.appendElementWithText(entry,ATOM_NS,"id",this.getId());this.appendElementWithText(entry,ATOM_NS,"title",this.getTitle());this.appendElementWithText(entry,ATOM_NS,"summary",this.getSummary());this.appendElementWithText(entry,ATOM_NS,"published",this.getPublished());this.appendElementWithText(entry,ATOM_NS,"updated",this.getUpdated());var box=this.getBoundingBox();if(box){var points=box.getEnvelope().getPoints();var boxStr=points[0].x+" "+points[0].y+" "+points[1].x+" "+points[1].y;this.appendElementWithText(entry,"http://www.georss.org/georss","box",boxStr);}
return entry;};namespace("userSmarts.sx.model.users.actions");namespace("userSmarts.sx.model.users.actions");namespace("userSmarts.sx.model.users.actions");$namespace.CreateUserAction=Class.create(userSmarts.wt.action.Action);$prototype.initialize=function(superClass,properties){properties=setdefault(properties,{id:'userSmarts.sx.model.users.actions.createuser',text:"New",toolTipText:'Create New User',image:"image.user.contact.new"});superClass.call(this,properties);this.callback=bind(this.onUserCreated,this);this.errback=handleResponseError;};$prototype.run=function(){var id=prompt("Enter the new user's username:","");if(id){var user=new userSmarts.sx.model.users.pub.User();user.setUserName(id);user.setFullName("");var coll=new userSmarts.pub.atom.Collection({url:"pub/users.atom",factory:new userSmarts.pub.atom.DefaultEntryFactory({entryClass:"userSmarts.sx.model.users.pub.User"})});var def=coll.add(user);def.addCallback(this.callback);def.addErrback(this.errback);}};$prototype.onUserCreated=function(user){var id=user.getId();user.getCollection().dispose();var ps=userSmarts.runtime.Platform.getPropertyService();ps.setProperty("user","created",id);var input=new userSmarts.sx.model.users.editors.UserEditorInput({name:id,id:id});var wb=userSmarts.ui.PlatformUI.getWorkbench();var page=wb.getActiveWorkbenchWindow().getActivePage();page.openEditor(input,"userSmarts.sx.model.users.editors.UserEditor",true);};namespace("userSmarts.sx.model.users.actions");$namespace.EditUserAction=Class.create(userSmarts.wt.action.Action);$prototype.initialize=function(superClass,properties){properties=setdefault(properties,{id:'userSmarts.sx.model.users.actions.edituser',text:"Edit",toolTipText:'Edit User Information',image:"image.user.contact.edit"});superClass.call(this,properties);};$prototype.run=function(){var ps=userSmarts.runtime.Platform.getPropertyService();var selection=ps.getProperty("user","selected");if(selection&&selection.url){var label=selection.label||selection.id||"[user]";var wb=userSmarts.ui.PlatformUI.getWorkbench();var page=wb.getActiveWorkbenchWindow().getActivePage();var input=new userSmarts.sx.model.users.editors.UserEditorInput({name:label,url:selection.url});page.openEditor(input,"userSmarts.sx.model.users.editors.UserEditor",true);}};namespace("userSmarts.sx.model.users.actions");$namespace.DeleteUserAction=Class.create(userSmarts.wt.action.Action);$prototype.initialize=function(superClass,properties){properties=setdefault(properties,{id:'userSmarts.sx.model.users.actions.deleteuser',text:"Delete",toolTipText:'Delete Selected User',image:"image.user.contact.delete"});superClass.call(this,properties);this.callback=bind(this.onUserDeleted,this);this.errback=handleResponseError;};$prototype.run=function(){var ps=userSmarts.runtime.Platform.getPropertyService();var selection=ps.getProperty("user","selected");if(selection&&selection.url){var label=selection.label||selection.id||"[user]";if(userSmarts.wt.dialogs.MessageDialog.openConfirm("Delete Item","Are you sure you want to delete '"+label+"'?")){var user=new userSmarts.sx.model.users.pub.User();user.setURL(selection.url);var def=user.del();def.addCallback(this.callback);def.addErrback(this.errback);}}};$prototype.onUserDeleted=function(){var ps=userSmarts.runtime.Platform.getPropertyService();ps.setProperty("user","deleted",null);ps.setProperty("user","selected",null);};namespace("userSmarts.sx.model.users.views");namespace("userSmarts.sx.model.users.views");namespace("userSmarts.sx.model.users.views");$namespace.UsersView=Class.create(userSmarts.ui.views.ListView);$prototype.initialize=function(superClass,desc){superClass.call(this,desc);this.model=new userSmarts.sx.model.users.models.UsersTableModel();};$prototype.contributeToActionBars=function(){connect(this.model,'populating',this,this.displayQueryingMessage);connect(this.model,'modified',this,this.displayFinishedMessage);var actionbars=this.getSite().getActionBars();var tbmgr=actionbars.getToolbarManager();var mbmgr=actionbars.getMenuBarManager();var action=new userSmarts.sx.model.users.actions.CreateUserAction();tbmgr.add(action);mbmgr.add(action);action=new userSmarts.sx.model.users.actions.EditUserAction();tbmgr.add(action);mbmgr.add(action);action=new userSmarts.sx.model.users.actions.DeleteUserAction();tbmgr.add(action);mbmgr.add(action);mbmgr.add(new userSmarts.wt.action.HorizontalSeparator());userSmarts.ui.views.ListView.prototype.contributeToActionBars.call(this);};$prototype.displayQueryingMessage=function(){var slmgr=this.getSite().getActionBars().getStatusLineManager();slmgr.setMessage("Querying users");};$prototype.displayFinishedMessage=function(){var slmgr=this.getSite().getActionBars().getStatusLineManager();slmgr.setMessage("Listing users");};$prototype.onSelectionChange=function(event){var id=null;var url=null;var title=null;var selection=event.newValue;if(selection){var id=selection.getUserName();var title=selection.getFullName();var url=selection.getLink();}
this.setProperty("selected",id);var ps=userSmarts.runtime.Platform.getPropertyService();ps.setProperty("user","selected",{id:id,url:url,label:title});};namespace("userSmarts.sx.model.users.models");namespace("userSmarts.sx.model.users.models");namespace("userSmarts.sx.model.users.models");$namespace.UsersTableModel=Class.create(userSmarts.pub.atom.FeedModel);$prototype.initialize=function(superClass,properties){properties=setdefault(properties,{pageSize:50});superClass.call(this,properties);this.addColumn(new userSmarts.pub.atom.EntryColumn({label:"Username",name:"username",order:true}));this.addColumn(new userSmarts.pub.atom.EntryColumn({label:"Full Name",name:"fullname",order:true}));this.addColumn(new userSmarts.pub.atom.EntryColumn({label:"Enabled",name:"enabled",order:true}));this.setSource(new userSmarts.pub.atom.GeoCollection({url:"pub/users.atom",factory:new userSmarts.pub.atom.DefaultEntryFactory({entryClass:"userSmarts.sx.model.users.pub.User"})}));var ps=userSmarts.runtime.Platform.getPropertyService()
ps.connect("user","*",this,this.onUserChange);};$prototype.getImage=function(){return userSmarts.runtime.Platform.getTheme().getImage("image.user");};$prototype.onUserChange=function(event){if(event.propertyName!="selected"){this.populate(this.getOffset());}};namespace("userSmarts.sx.model.users.editors");namespace("userSmarts.sx.model.users.editors");namespace("userSmarts.sx.model.users.editors");$namespace.UserEditor=Class.create(userSmarts.ui.EditorPart);$prototype.initialize=function(superclass,properties){superclass.call(this,properties);this.listeners=[];this.getCallback=bind(this.parseUserInfo,this);this.putCallback=bind(this.updateEntry,this);};$prototype.init=function(site,input){userSmarts.ui.EditorPart.prototype.init.call(this,site,input);var def=input.get();def.addCallback(this.getCallback);def.addErrback(bind(function(arg){handleResponseError(arg);var page=userSmarts.ui.PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();page.closeEditor(this,false);userSmarts.runtime.Platform.getPropertyService().setProperty("users","deleted",null);},this));};$prototype.parseUserInfo=function(xml){this.entry=new userSmarts.sx.model.users.pub.UserEntry({node:xml.documentElement});this.entry.getUserName();this.entry.getFullName();this.entry.getOrganization();this.entry.getEmailAddress();this.entry.getPassword();this.entry.getExpiration();this.entry.getPasswordExpiration();this.entry.getGroups();this.entry.isEnabled();this.entry.isLocked();if(this.control){this.updateControl();};};$prototype.updateEntry=function(){var def=this.input.get();def.addCallback(this.getCallback);};$prototype.createPartControl=function(){var control=this.control=new userSmarts.wt.widgets.Control({'class':'user-editor'});var bars=this.getSite().getActionBars();var tbmgr=bars.getToolbarManager();this.saveEditorAction=new userSmarts.wt.action.SaveEditorAction({editor:this});tbmgr.add(this.saveEditorAction);if(this.entry){this.updateControl();}
return control;};$prototype.findPath=function(path){return userSmarts.sx.Plugin.getURI(path);};$prototype.updateControl=function(){for(var i=0;i<this.listeners.length;++i){disconnect(this.listeners[i]);}
if(!this.entry)return;this.changeListener=connect(this.entry,"*",this,this.onInputChange);var button;var node=this.control.getNode();replaceChildNodes(node,[]);var col1;var col2;var tbody=TBODY({});var table=TABLE({cellpadding:"3",cellPadding:"3",cellspacing:"0",cellSpacing:"0",border:"0",width:"100%"},tbody);node.appendChild(table);col1=TD({width:"100px",'class':'editor-section-title'},"Details");col2=TD({},"");tbody.appendChild(TR({},col1,col2));col1=TD({width:"100px"});col2=TD({});col1.appendChild(SPAN({'class':'editor-section-field-label'},"User Name: "));col2.appendChild(SPAN({'class':'editor-section-text'},this.entry.getUserName()));tbody.appendChild(TR({},col1,col2));col1=TD({width:"100px"});col2=TD({});col1.appendChild(SPAN({'class':'editor-section-field-label'},"Password: "));button=BUTTON({},"Change");this.listeners.push(connect(button,'onclick',this,this.changePassword));col2.appendChild(button);tbody.appendChild(TR({},col1,col2));col1=TD({width:"100px"});col2=TD({});col1.appendChild(SPAN({'class':'editor-section-field-label'},"Full Name: "));var box=new userSmarts.wt.forms.Field({size:40,parent:null,binding:new BeanPropertyBinding(this.entry,'fullname')});col2.appendChild(box.paint());this.listeners.push(connect(this.entry,"fullname",this,this.onInputChange));tbody.appendChild(TR({},col1,col2));col1=TD({width:"100px"});col2=TD({});col1.appendChild(SPAN({'class':'editor-section-field-label'},"Enabled? "));button=BUTTON({},(this.entry.enabled?"Disable":"Enable"));this.listeners.push(connect(button,'onclick',this,this.onEnabledButtonClick));col2.appendChild(button);tbody.appendChild(TR({},col1,col2));col1=TD({width:"100px"});col2=TD({});col1.appendChild(SPAN({'class':'editor-section-field-label'},"Locked? "));button=BUTTON({},(this.entry.locked?"Unlock":"Lock"));this.listeners.push(connect(button,'onclick',this,this.onLockedButtonClick));col2.appendChild(button);tbody.appendChild(TR({},col1,col2));col1=TD({width:"100px"});col2=TD({});col1.appendChild(SPAN({'class':'editor-section-field-label'},"Organization: "));var box=new userSmarts.wt.forms.Field({size:40,parent:null,binding:new BeanPropertyBinding(this.entry,'organization')});col2.appendChild(box.paint());this.listeners.push(connect(this.entry,"organization",this,this.onInputChange));tbody.appendChild(TR({},col1,col2));col1=TD({width:"100px",valign:'top',vAlign:'top'});col2=TD({});col1.appendChild(SPAN({'class':'editor-section-field-label'},"Email: "));var box=new userSmarts.wt.forms.Field({size:40,parent:null,binding:new BeanPropertyBinding(this.entry,'email')});col2.appendChild(box.paint());this.listeners.push(connect(this.entry,"email",this,this.onInputChange));tbody.appendChild(TR({},col1,col2));col1=TD({width:"100px",'class':'editor-section-title'},"Permissions");col2=TD({},"");tbody.appendChild(TR({},col1,col2));col1=TD({width:"100px",valign:'top',vAlign:'top'});col2=TD({});col1.appendChild(SPAN({'class':'editor-section-field-label'},"Roles: "));for(var i=0;i<this.entry.groups.length;++i){var closer=SUP({}," [x] ");closer.style.cursor="pointer";closer.style.color="#ff0000";closer.title="Remove this role";closer.roleIndex=i;this.listeners.push(connect(closer,"onclick",this,this.removeGroup));var span=SPAN({'class':'editor-section-text'},(i>0?", ":"")+this.entry.groups[i],closer);col2.appendChild(span);}
var opener=SUP({},"[+]");opener.style.color="#00ff00";button=SPAN({'class':'editor-section-text'},", New Role...",opener);button.style.cursor="pointer";button.style.fontStyle="italic";button.title="Add new role";this.listeners.push(connect(button,'onclick',this,this.addGroup));col2.appendChild(button);tbody.appendChild(TR({},col1,col2));};$prototype.onInputChange=function(event){this.dirty=true;this.setMessage(" ");if(this.changeListener){disconnect(this.changeListener);this.changeListener=null;}
this.changeListener=null;}
$prototype.doSave=function(){var def=this.getEditorInput().put(this.entry.toXml());def.addErrback(bind(function(arg){handleResponseError(arg);var wb=userSmarts.ui.PlatformUI.getWorkbench();var page=wb.getActiveWorkbenchWindow().getActivePage();page.closeEditor(this,false);var ps=userSmarts.runtime.Platform.getPropertyService();ps.setProperty("users","deleted",null);},this));this.dirty=false;this.setMessage("User info updated.");};$prototype.setMessage=function(message){var actionbars=this.getSite().getActionBars();var slmgr=actionbars.getStatusLineManager();slmgr.setMessage(message);};$prototype.onEnabledButtonClick=function(event){this.entry.enabled=!this.entry.enabled;var button=event.src();var buttonLabel=(this.entry.enabled?"Disable":"Enable");replaceChildNodes(button,buttonLabel);this.onInputChange();};$prototype.onLockedButtonClick=function(event){this.entry.locked=!this.entry.locked;var button=event.src();var buttonLabel=(this.entry.locked?"Unlock":"Lock");replaceChildNodes(button,buttonLabel);this.onInputChange();};$prototype.removeGroup=function(event){var button=event.src();var group=button.roleIndex;this.entry.groups.splice(group,1);this.updateControl();this.onInputChange();};$prototype.addGroup=function(event){var dialog=new userSmarts.sx.model.workspaces.dialogs.SelectRoleDialog();var def=dialog.open();def.addCallback(bind(function(role){if(role){if(!this.entry.groups.contains(role)){this.entry.groups.push(role);this.updateControl();this.onInputChange();}}},this));};$prototype.changePassword=function(event){var dialog=new userSmarts.sx.model.users.dialogs.ChangePasswordDialog({password:this.entry.password});var deferred=dialog.open();deferred.addCallback(bind(function(pass){if(pass){this.entry.password=pass;}},this));};namespace("userSmarts.sx.model.users.editors");$namespace.UserEditorInput=Class.create(userSmarts.ui.EditorInput);$prototype.initialize=function(superClass,properties){superClass.call(this,properties);if(this.id&&!this.url){this.url="pub/users/"+this.id+".atom";}
if(this.url){this.resource=new userSmarts.pub.Resource();this.resource.setURL(this.url);this.resource.setParameter("format","text/xml");}}
$prototype.equals=function(other){return this.url==other.url;};$prototype.get=function(){return this.resource.get();};$prototype.put=function(content){return this.resource.put(content);};namespace("userSmarts.sx.model.users.editors");$namespace.MultiPageUserEditor=Class.create(userSmarts.ui.MultiPageEditorPart);$prototype.initialize=function(superclass,properties){superclass.call(this,properties);};$prototype.init=function(site,input){userSmarts.ui.MultiPageEditorPart.prototype.init.call(this,site,input);connect(input,"loaded",this,this.onInputLoaded);input.load();};$prototype.createPages=function(){if(!this.hasPages()){var page=new userSmarts.sx.model.users.editors.UserPageOne();this.addPage(page);this.infoPage=page;page=new userSmarts.sx.model.users.editors.UserPageTwo();this.addPage(page);this.permissionPage=page;}};$prototype.doSave=function(){this.input.save();};$prototype.onInputLoaded=function(event){var success=event.newValue;if(success){if(!this.outer){this.createPartControl();}
this.createPages();this.outer.update();userSmarts.runtime.Platform.getPropertyService().setProperty("editor","initialized",this);}else{var page=userSmarts.ui.PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();page.closeEditor(this,false);userSmarts.runtime.Platform.getPropertyService().setProperty("users","deleted",null);}};$prototype.createPartControl=function(parent){if(!this.outer){this.outer=new userSmarts.wt.widgets.Composite({'class':'multi-editor',updateOnBoundsChange:true,layoutData:{width:'100%',height:'100%'}});this.outer.setLayout(new userSmarts.wt.layout.RowLayout({type:"vertical"}));this.createPageContainer();this.tabControl=new userSmarts.wt.widgets.Composite({parent:this.outer,"class":"btabs",layoutData:{width:"100%",height:'25px'}});}
return this.outer;};namespace("userSmarts.sx.model.users.editors");$namespace.MultiPageUserEditorInput=Class.create(userSmarts.ui.EditorInput);$prototype.initialize=function(superClass,properties){superClass.call(this,properties);this.resource=new userSmarts.pub.Resource({url:this.url,params:{format:"text/xml"}});this.errback=bind(function(arg){handleResponseError(arg);this.setProperty("loaded",false);},this);}
$prototype.equals=function(other){return this.url==other.url;};$prototype.get=function(){return this.resource.get();};$prototype.put=function(content){return this.resource.put(content);};$prototype.del=function(content){return this.resource.del(content);};$prototype.load=function(){var def=this.get();def.addCallback(bind(this.onInputLoaded,this));def.addErrback(this.errback);};$prototype.onInputLoaded=function(xml){this.entry=new userSmarts.sx.model.users.pub.UserEntry({node:xml.documentElement});this.entry.getUserName();this.entry.getFullName();this.entry.getOrganization();this.entry.getEmailAddress();this.entry.getPassword();this.entry.getExpiration();this.entry.getPasswordExpiration();this.entry.getGroups();this.entry.isEnabled();this.entry.isLocked();this.setProperty("loaded",true);};$prototype.save=function(){var def=this.put(this.entry.toXml());def.addCallback(bind(function(){this.dirty=false;},this));def.addErrback(bind(function(arg){handleResponseError(arg);userSmarts.runtime.Platform.getPropertyService().setProperty("users","deleted",null);},this));};$prototype.getEntry=function(){return this.entry;};namespace("userSmarts.sx.model.users.editors");$namespace.UserPageOne=Class.create(userSmarts.ui.EditorPart);$prototype.initialize=function(superclass,properties){superclass.call(this,properties);this.label="Details";this.listeners=[];};$prototype.createPartControl=function(){if(!this.control){this.control=new userSmarts.wt.widgets.Control({'class':'user-editor',label:this.label});this.entry=this.input.getEntry();}
if(this.entry)this.updateControl();return this.control;};$prototype.findPath=function(path){return userSmarts.sx.Plugin.getURI(path);};$prototype.updateControl=function(){for(var i=0;i<this.listeners.length;++i){disconnect(this.listeners[i]);}
if(!this.entry)return;this.changeListener=connect(this.entry,"*",this,this.onInputChange);var button;var node=this.control.getNode();replaceChildNodes(node,[]);var col1;var col2;var tbody=TBODY({});var table=TABLE({cellpadding:"3",cellPadding:"3",cellspacing:"0",cellSpacing:"0",border:"0",width:"100%"},tbody);node.appendChild(table);col1=TD({width:"150px",'class':'editor-section-title'},"User Details");col2=TD({},"");tbody.appendChild(TR({},col1,col2));col1=TD({width:"150px",valign:'top',vAlign:'top'});col2=TD({});col1.appendChild(userSmarts.runtime.Platform.getTheme().getImage("image.font"));col1.appendChild(SPAN({'class':'editor-section-field-label'},"Username: "));col2.appendChild(SPAN({'class':'editor-section-text'},this.entry.getUserName()));tbody.appendChild(TR({},col1,col2));col1=TD({width:"150px",colspan:'2',colSpan:'2'});button=BUTTON({},"Change Password");this.listeners.push(connect(button,'onclick',this,this.changePassword));col1.appendChild(button);tbody.appendChild(TR({},col1));col1=TD({width:"150px"});col2=TD({});col1.appendChild(userSmarts.runtime.Platform.getTheme().getImage("image.font"));col1.appendChild(SPAN({'class':'editor-section-field-label'},"Full Name: "));box=new userSmarts.wt.forms.Field({size:100,parent:null,binding:new BeanPropertyBinding(this.entry,'fullname')});col2.appendChild(box.paint());tbody.appendChild(TR({},col1,col2));col1=TD({width:"150px"});col2=TD({});col1.appendChild(userSmarts.runtime.Platform.getTheme().getImage("image.home"));col1.appendChild(SPAN({'class':'editor-section-field-label'},"Organization: "));box=new userSmarts.wt.forms.Field({size:100,parent:null,binding:new BeanPropertyBinding(this.entry,'organization')});col2.appendChild(box.paint());tbody.appendChild(TR({},col1,col2));col1=TD({width:"150px"});col2=TD({});col1.appendChild(userSmarts.runtime.Platform.getTheme().getImage("image.email"));col1.appendChild(SPAN({'class':'editor-section-field-label'},"Email: "));box=new userSmarts.wt.forms.Field({size:100,parent:null,binding:new BeanPropertyBinding(this.entry,'email')});col2.appendChild(box.paint());tbody.appendChild(TR({},col1,col2));col1=TD({width:"150px",colspan:'2',colSpan:'2'});var buttonLabel=(this.entry.enabled?"Disable User":"Enable User");button=BUTTON({},buttonLabel);this.listeners.push(connect(button,'onclick',this,this.onEnabledButtonClick));col1.appendChild(button);buttonLabel=(this.entry.locked?"Unlock User":"Lock User");button=BUTTON({},buttonLabel);this.listeners.push(connect(button,'onclick',this,this.onLockedButtonClick));col1.appendChild(button);tbody.appendChild(TR({},col1));col1=TD({width:"150px",'class':'editor-section-title'},"Actions");col2=TD({},"");tbody.appendChild(TR({},col1,col2));col1=TD({width:"100%",colspan:"2",colSpan:'2'});var link;var icon;if(userSmarts.sx.model.workspaces.Plugin!=undefined||userSmarts.sx.model.workspaces.Plugin.isUserInRole("EDIT_USER")){this.editable=true;icon=userSmarts.runtime.Platform.getTheme().getImage("image.save");this.listeners.push(connect(icon,"onclick",this,this.doSave));col1.appendChild(icon);link=SPAN({'class':'editor-link'},"Save user");this.listeners.push(connect(link,"onclick",this,this.doSave));col1.appendChild(link);col1.appendChild(BR());}else{this.editable=false;}};$prototype.onInputChange=function(event){if(this.editable){this.input.dirty=true;}
disconnect(this.changeListener);this.changeListener=null;};$prototype.doSave=function(){if(this.editable){this.input.doSave();}};$prototype.onEnabledButtonClick=function(event){this.entry.enabled=!this.entry.enabled;var button=event.src();var buttonLabel=(this.entry.enabled?"Disable User":"Enable User");replaceChildNodes(button,buttonLabel);};$prototype.onLockedButtonClick=function(event){this.entry.locked=!this.entry.locked;var button=event.src();var buttonLabel=(this.entry.locked?"Unlock User":"Lock User");replaceChildNodes(button,buttonLabel);};$prototype.changePassword=function(event){var dialog=new userSmarts.sx.model.users.dialogs.ChangePasswordDialog({password:this.entry.password});var deferred=dialog.open();deferred.addCallback(bind(function(okPressed){if(okPressed){this.entry.password=dialog.getPassword();}},this));};namespace("userSmarts.sx.model.users.editors");$namespace.UserPageTwo=Class.create(userSmarts.ui.EditorPart);$prototype.initialize=function(superclass,properties){superclass.call(this,properties);this.label="Permissions";this.listeners=[];this.roles=userSmarts.sx.model.workspaces.Plugin.ROLE_DATATYPE;};$prototype.createPartControl=function(){if(!this.control){this.control=new userSmarts.wt.widgets.Control({'class':'user-editor',label:this.label});this.entry=this.input.getEntry();}
if(this.entry)this.updateControl();return this.control;};$prototype.findPath=function(path){return userSmarts.sx.Plugin.getURI(path);};$prototype.updateControl=function(){for(var i=0;i<this.listeners.length;++i){disconnect(this.listeners[i]);}
if(!this.entry)return;var button;var node=this.control.getNode();replaceChildNodes(node,[]);var col1;var col2;var tbody=TBODY({});var table=TABLE({cellpadding:"3",cellPadding:"3",cellspacing:"0",cellSpacing:"0",border:"0",width:"100%"},tbody);node.appendChild(table);col1=TD({width:"150px",'class':'editor-section-title'},"User Permissions");col2=TD({},"");tbody.appendChild(TR({},col1,col2));var input;col1=TD({width:"150px",colspan:'2',colSpan:'2'});col1.appendChild(userSmarts.runtime.Platform.getTheme().getImage("image.tag"));col1.appendChild(SPAN({'class':'editor-section-field-label'},"Groups: "));tbody.appendChild(TR({},col1));var group;for(var i=0;i<this.roles.facets.enumeration.length;++i){group=this.roles.facets.enumeration[i];col1=TD({width:"150px"});col2=TD({});col1.appendChild(SPAN({'class':'editor-section-text'},group.label));button=INPUT({type:'checkbox'});button.groupOption=group;button.checked=button.defaultChecked=(this.entry.groups.indexOf(group.value)>=0);this.listeners.push(connect(button,'onclick',this,this.onGroupModified));col2.appendChild(button);tbody.appendChild(TR({},col1,col2));}};$prototype.onGroupModified=function(event){var checkbox=event.src();var group=checkbox.groupOption.value;if(checkbox.checked){this.entry.groups.push(group);}else{var index=this.entry.groups.indexOf(group);if(index>=0){this.entry.groups.splice(index,1);}else{logWarning("Group not found in existing permissions for user!");}}};$prototype.userHasRole=function(role){return(this.entry.groups.indexOf(role)>=0);};$prototype.getRolesByType=function(type,match){var roles=[];for(var i=0;i<this.roles.facets.enumeration.length;++i){if(this.roles.facets.enumeration[i].value.indexOf(type)>=0){if(match==undefined||match==false){if(this.roles.facets.enumeration[i].value!=type){roles.push(this.roles.facets.enumeration[i]);}}else{roles.push(this.roles.facets.enumeration[i]);}}}
return roles;};$prototype.buildRoleTable=function(type,parent){var icol;var irow1=TR();irow1.style.backgroundColor="#cccccc";var irow2=TR();var itbody=TBODY({},irow2);var ithead=THEAD({},irow1);var itable=TABLE({cellpadding:"0",cellPadding:"0",cellspacing:"0",cellSpacing:"0",border:"1",width:"75%"},ithead,itbody);parent.appendChild(itable);var roles=this.getRolesByType(type);for(var i=0;i<roles.length;++i){icol=TD({'class':'editor-section-label'},roles[i].label);irow1.appendChild(icol);icol=TD({'class':'editor-section-text',textAlign:"center"});irow2.appendChild(icol);button=INPUT({type:'checkbox'});button.groupOption=roles[i];button.checked=button.defaultChecked=this.userHasRole(roles[i].value);this.listeners.push(connect(button,'onclick',this,this.onGroupModified));icol.appendChild(button);}};namespace("userSmarts.sx.model.users.dialogs");namespace("userSmarts.sx.model.users.dialogs");namespace("userSmarts.sx.model.users.dialogs");$namespace.ChangePasswordDialog=Class.create(userSmarts.wt.dialogs.Dialog);$prototype.initialize=function(superClass,properties){setdefault(properties,{modal:false,width:200,height:100,title:"Change Password",description:"Enter the following information."});superClass.call(this,properties);this.oldPasswordErrorMsg=document.createTextNode("Incorrect password!");this.newPasswordErrorMsg=document.createTextNode("Invalid password!");this.confirmPasswordErrorMsg=document.createTextNode("Password not confirmed!");};$prototype.createDialogArea=function(parent){parent.appendChild(SPAN({'class':"dialog-description"},this.description));parent.appendChild(BR());parent.appendChild(DIV({'class':'form-label'},"Enter Old Password:"));var box=INPUT({type:'password',size:20,name:"oldpassword"});if(this.password==""||!this.password){box.disabled=true;}else{connect(box,'onchange',this,this.onInputChange);box.value=this.password;}
parent.appendChild(box);this.oldPasswordBox=box;this.oldPasswordErrorBox=DIV({},"");parent.appendChild(this.oldPasswordErrorBox);parent.appendChild(DIV({'class':'form-label'},"Enter New Password:"));box=INPUT({type:'password',size:20,name:"newpassword"});connect(box,'onchange',this,this.onInputChange);parent.appendChild(box);this.newPasswordBox=box;this.newPasswordErrorBox=DIV({},"");parent.appendChild(this.newPasswordErrorBox);parent.appendChild(DIV({'class':'form-label'},"Confirm New Password:"));box=INPUT({type:'password',size:20,name:"confirmedpassword"});connect(box,'onchange',this,this.onInputChange);parent.appendChild(box);this.confirmedPasswordBox=box;this.confirmedPasswordErrorBox=DIV({},"");parent.appendChild(this.confirmedPasswordErrorBox);parent.appendChild(BR());this.getOKButton().disabled=true;};$prototype.focus=function(){if(this.password==""||!this.password){this.newPasswordBox.focus();}else{this.oldPasswordBox.focus();}};$prototype.onInputChange=function(event){var input=event.src();var value=input.value;if(input.name=="oldpassword"){if(value!=this.password){replaceChildNodes(this.oldPasswordErrorBox,this.oldPasswordErrorMsg);this.getOKButton().disabled=true;}}else if(input.name=="newpassword"){if(!value){replaceChildNodes(this.newPasswordErrorBox,this.newPasswordErrorMsg);this.getOKButton().disabled=true;}}else if(input.name=="confirmedpassword"){if(value!=this.newPasswordBox.value){replaceChildNodes(this.confirmedPasswordErrorBox,this.confirmedPasswordErrorMsg);this.getOKButton().disabled=true;}else{this.getOKButton().disabled=false;}}};$prototype.okPressed=function(){this.password=this.newPasswordBox.value;if(this.deferred){this.deferred.callback(this.password);this.deferred=null;}};$prototype.getPassword=function(){return this.password;};namespace("userSmarts.sx.model.users.pub");namespace("userSmarts.sx.model.users.pub");namespace("userSmarts.sx.model.users.pub");$namespace.UserEntry=Class.create(userSmarts.pub.atom.Entry);$prototype.initialize=function(superClass,properties){superClass.call(this,properties);};$prototype.getUserName=function(){var result=null;if(this.username){result=this.username;}else if(this.node){result=this.getValue("username","username",result);}
return result;};$prototype.setUserName=function(username){this.username=username;};$prototype.getFullName=function(){var result="";if(this.fullname){result=this.fullname;}else if(this.node){result=this.getValue("fullname","fullname",result);}
return result;};$prototype.setFullName=function(fullname){this.fullname=fullname;};$prototype.getOrganization=function(){var result="";if(this.organization){result=this.organization;}else if(this.node){result=this.getValue("organization","organization",result);}
return result;};$prototype.setOrganization=function(org){this.organization=org;}
$prototype.getEmailAddress=function(){var result="";if(this.email){result=this.email;}else if(this.node){result=this.getValue("email","email",result);}
return result;};$prototype.setEmailAddress=function(email){this.email=email;};$prototype.getPassword=function(){var result="";if(this.password){result=this.password;}else if(this.node){result=this.getValue("password","password",result);}
return result;};$prototype.setPassword=function(pass){this.password=pass;};$prototype.getExpiration=function(){var result="";if(this.expires){result=this.expires;}else if(this.node){result=this.getValue("expires","expires",result);}
return result;};$prototype.setExpiration=function(expires){this.expires=expires;};$prototype.getPasswordExpiration=function(){var result="";if(this.passwordExpires){result=this.passwordExpires;}else if(this.node){result=this.getValue("passwordExpires","passwordExpires",result);}
return result;};$prototype.setPasswordExpiration=function(expires){this.passwordExpires=expires;}
$prototype.getGroups=function(){var result=[];if(this.groups){result=this.groups;}else if(this.node){result=this.getValues("groups","group");}
return result;};$prototype.setGroups=function(groups){if(typeof(groups)=="string"){this.groups=groups.split(",");}else if(typeof(groups.push)=="function"){this.groups=groups;}};$prototype.isEnabled=function(){var result=false;if(this.enabled!=undefined){result=(this.enabled==true);}else if(this.node){this.getValue("enabledStr","enabled",result);result=this.enabled=(this.enabledStr==true||this.enabledStr=="true");}
return result;};$prototype.setEnabled=function(enabled){this.enabled=(enabled==true||enabled=="true");};$prototype.isLocked=function(){var result=false;if(this.locked!=undefined){result=this.locked;}else if(this.node){this.getValue("lockedStr","locked",result);result=this.locked=(this.lockedStr==true||this.lockedStr=="true");}
return result;};$prototype.setLocked=function(locked){this.locked=(locked==true||locked=="true");};$prototype.toXml=function(doc){var ATOM_NS='http://www.w3.org/2005/Atom';var USERS_NS='http://www.usersmarts.com/sx/users';if(!doc||doc.nodeType!=9){doc=createXMLDocument('entry','http://www.w3.org/2005/Atom',null);}else{doc.appendChild(createElementNS('http://www.w3.org/2005/Atom','entry',doc));}
var entry=doc.documentElement;this.appendElementWithText(entry,ATOM_NS,"id",this.getId());this.appendElementWithText(entry,ATOM_NS,"title",this.getTitle());this.appendElementWithText(entry,ATOM_NS,"summary",this.getSummary());this.appendElementWithText(entry,USERS_NS,"username",this.getUserName());this.appendElementWithText(entry,USERS_NS,"fullname",this.getFullName());this.appendElementWithText(entry,USERS_NS,"password",this.getPassword());this.appendElementWithText(entry,USERS_NS,"email",this.getEmailAddress());this.appendElementWithText(entry,USERS_NS,"organization",this.getOrganization());this.appendElementWithText(entry,USERS_NS,"enabled",this.isEnabled()+"");this.appendElementWithText(entry,USERS_NS,"locked",this.isLocked()+"");var groups=this.getGroups();for(var i=0;i<groups.length;++i){this.appendElementWithText(entry,USERS_NS,"group",groups[i]);}
return entry;};namespace("userSmarts.sx.model.users.pub");$namespace.User=Class.create(userSmarts.pub.atom.Entry2);$prototype.initialize=function(superClass,properties){superClass.call(this,properties);this.dateFormat=new DateFormat();this.booleanFormat=new BooleanFormat();this.groups=[];this.userNS="http://www.usersmarts.com/sx/users";};$prototype.getUserName=function(){var tnNode=this.getExtension("username");if(tnNode&&tnNode.value){return tnNode.value;}
return null;};$prototype.setUserName=function(userName){this.setExtension("username",userName,this.userNS);};$prototype.getFullName=function(){var tnNode=this.getExtension("fullname");if(tnNode&&tnNode.value){return tnNode.value;}
return null;};$prototype.setUserName=function(fullName){this.setExtension("fullname",fullName,this.userNS);};$prototype.getOrganization=function(){var tnNode=this.getExtension("organization");if(tnNode&&tnNode.value){return tnNode.value;}
return null;};$prototype.setOrganization=function(orgName){this.setExtension("organization",orgName,this.userNS);};$prototype.getEmail=function(){var tnNode=this.getExtension("email");if(tnNode&&tnNode.value){return tnNode.value;}
return null;};$prototype.setEmail=function(email){this.setExtension("email",email,this.userNS);};$prototype.getPassword=function(){var tnNode=this.getExtension("password");if(tnNode&&tnNode.value){return tnNode.value;}
return null;};$prototype.setPassword=function(password){this.setExtension("password",password,this.userNS);};$prototype.getExpiration=function(){var tnNode=this.getExtension("expires");if(tnNode&&tnNode.value){return this.dateFormat.parseObject(tnNode.value);}
return null;};$prototype.setExpiration=function(expiration){this.setExtension("expires",this.dateFormat.format(expiration),this.userNS);};$prototype.getPasswordExpiration=function(){var tnNode=this.getExtension("passwordExpires");if(tnNode&&tnNode.value){return this.dateFormat.parseObject(tnNode.value);}
return null;};$prototype.setPasswordExpiration=function(expiration){this.setExtension("passwordExpires",this.dateFormat.format(expiration),this.userNS);};$prototype.getGroups=function(){return this.groups;};$prototype.setGroups=function(groups){if(typeof(groups.push)!="undefined"){this.groups=groups;}else if(typeof(groups)=="string"){this.groups=groups.split(",");}};$prototype.isEnabled=function(){var tnNode=this.getExtension("enabled");if(tnNode&&tnNode.value){return this.booleanFormat.parseObject(tnNode.value);}
return null;};$prototype.setEnabled=function(enabled){this.setExtension("enabled",this.booleanFormat.format(enabled),this.userNS);};$prototype.isLocked=function(){var tnNode=this.getExtension("locked");if(tnNode&&tnNode.value){return this.booleanFormat.parseObject(tnNode.value);}
return null;};$prototype.setLocked=function(locked){this.setExtension("locked",this.booleanFormat.format(enabled),this.userNS);};$prototype.updateValueFromElement=function(node){var name=DOMUtils.getName(node);if(name=="group"){this.groups.push(scrapeText(node));}else{userSmarts.pub.atom.Entry2.prototype.updateValueFromElement.call(this,node);}};$prototype.toXml=function(doc){var entry=userSmarts.pub.atom.Entry2.prototype.toXml.call(this,doc);for(var i=0;i<this.groups.length;++i){this.appendElement(entry,"group",this.groups[i],this.userNS);}};namespace("userSmarts.sx.model.versions");namespace("userSmarts.sx.model.versions");namespace("userSmarts.sx.model.versions");$namespace.VersionEntry=Class.create(userSmarts.pub.atom.Entry);$prototype.initialize=function(superClass,properties){superClass.call(this,properties);};$prototype.getVersionNumber=function(){if(this.node){this.getValue("versionNumber","versionNumber","");}
return this.versionNumber;};$prototype.setVersionNumber=function(num){this.versionNumber=num;};$prototype.getCollectionId=function(){if(this.node){this.getValue("collectionId","collectionId","");}
return this.collectionId;};$prototype.setCollectionId=function(id){this.collectionId=id;};$prototype.toXml=function(doc){var entry=userSmarts.pub.Entry.prototype.toXml.call(this,doc);if(entry){this.appendElementWithText(entry,'http://www.usersmarts.com/sx/versions','versionNumber',this.getVersionNumber());this.appendElementWithText(entry,'http://www.usersmarts.com/sx/versions','collectionId',this.getCollectionId());}
return entry;}
namespace("userSmarts.sx.model.versions");$namespace.VersionsModel=Class.create(userSmarts.pub.GeoOpenSearchTableModel);$prototype.initialize=function(superClass,properties){properties=setdefault(properties,{pageSize:50,nodeOffset:0,depth:0,nodeNames:["entry"]});superClass.call(this,properties);this.addColumn(new userSmarts.wt.widgets.DOMTableColumn({label:"Id",name:"id",index:0,order:true,visible:false}));this.addColumn(new userSmarts.wt.widgets.DOMTableColumn({label:"Title",name:"title",index:1,order:true}));this.addColumn(new userSmarts.wt.widgets.DOMTableColumn({name:"summary",index:2,order:true}));this.addColumn(new userSmarts.wt.widgets.DOMTableColumn({label:"Author",name:"authorName",index:3,order:true}));this.addColumn(new userSmarts.wt.widgets.DOMTableColumn({label:"Edited",name:"published",index:4,order:false}));this.setSortElement(this.columns[1].name);this.setSortOrder(this.columns[1].order);var collId=this.collectionId;this.setProperty("source","pub/"+collId+"/versions.atom");};$namespace.RevisionTitleColumn=Class.create(userSmarts.wt.widgets.DOMTableColumn);$prototype.initialize=function(superClass,properties){superClass.call(this,properties);};$prototype.getLabel=function(row){var label=userSmarts.wt.widgets.DOMTableColumn.prototype.getLabel.call(this,row);label="Revision "+label;return label;};namespace("userSmarts.sx.model.workspaces.views");namespace("userSmarts.sx.model.workspaces.views");namespace("userSmarts.sx.model.workspaces.views");$namespace.WorkspacesView=Class.create(userSmarts.ui.views.ListView);$prototype.initialize=function(superClass,desc){superClass.call(this,desc);this.model=new userSmarts.sx.model.workspaces.models.WorkspacesModel();connect(this.model,'modified',this,this.onModelUpdated);};$prototype.contributeToActionBars=function(){connect(this.model,'populating',this,this.displayQueryMessage);connect(this.model,'modified',this,this.displayFinishedMessage);var actionbars=this.getSite().getActionBars();var tbmgr=actionbars.getToolbarManager();var mbmgr=actionbars.getMenuBarManager();var action=new userSmarts.sx.model.workspaces.actions.NewWorkspaceAction();tbmgr.add(action);mbmgr.add(action);action=new userSmarts.sx.model.workspaces.actions.EditWorkspaceAction();tbmgr.add(action);mbmgr.add(action);action=new userSmarts.sx.model.workspaces.actions.DeleteWorkspaceAction();tbmgr.add(action);mbmgr.add(action);mbmgr.add(new userSmarts.wt.action.HorizontalSeparator());userSmarts.ui.views.ListView.prototype.contributeToActionBars.call(this);};$prototype.displayQueryMessage=function(){var slmgr=this.getSite().getActionBars().getStatusLineManager();slmgr.setMessage("Querying workspaces...");};$prototype.displayFinishedMessage=function(success){var slmgr=this.getSite().getActionBars().getStatusLineManager();slmgr.setMessage(success?"Listing workspaces":"Error listing workspaces");};$prototype.onSelectionChange=function(event){var id=null;var url=null;var title=null;var selection=event.newValue;if(selection){var id=selection.getId();var url=selection.getLink();var title=selection.getTitle();}
this.setSelection({id:id,url:url,label:title});};$prototype.onModelUpdated=function(event){this.checkSelected();};$prototype.setSelection=function(obj){this.setProperty("selected",obj.id);var ps=userSmarts.runtime.Platform.getPropertyService();ps.setProperty("workspace","selected",obj);};$prototype.checkSelected=function(){var present=false;if(this.selected){var rows=this.model.getRows();for(var i=0;i<rows.length;++i){if(rows[i].getId()==this.selected){present=true;this.list.select(rows[i]);}}}
if(!present){this.setSelection({id:null,url:null});this.selectedSituationAOI=null;}};namespace("userSmarts.sx.model.workspaces.models");namespace("userSmarts.sx.model.workspaces.models");namespace("userSmarts.sx.model.workspaces.models");$namespace.WorkspacesModel=Class.create(userSmarts.pub.atom.FeedModel);$prototype.initialize=function(superClass,properties){properties=setdefault(properties,{pageSize:50});superClass.call(this,properties);this.addColumn(new userSmarts.pub.atom.EntryColumn({label:"Title",name:"title",order:true}));this.addColumn(new userSmarts.pub.atom.EntryColumn({name:"summary",order:true}));this.setSource(new userSmarts.pub.atom.GeoCollection({url:"pub/workspaces.atom",factory:new userSmarts.pub.atom.DefaultEntryFactory({entryClass:"userSmarts.sx.model.workspaces.pub.Workspace"})}));var ps=userSmarts.runtime.Platform.getPropertyService();ps.connect("workspace","*",this,this.onWorkspacesChange);};$prototype.getImage=function(){var theme=userSmarts.runtime.Platform.getTheme();if(theme){return theme.getImage("image.workspace");}else{return null;}};$prototype.onWorkspacesChange=function(event){var property=event.propertyName;if(property=="created"||property=="deleted"||property=="updated"){this.populate(0);}};namespace("userSmarts.sx.model.workspaces.editors");namespace("userSmarts.sx.model.workspaces.editors");namespace("userSmarts.sx.model.workspaces.editors");$namespace.WorkspaceEditor=Class.create(userSmarts.ui.MultiPageEditorPart);$prototype.initialize=function(superclass,properties){superclass.call(this,properties);};$prototype.init=function(site,input){userSmarts.ui.MultiPageEditorPart.prototype.init.call(this,site,input);this.loadedListener=connect(input,"loaded",this,this.onInputLoaded);this.updatedListener=connect(input,"updated",this,this.onInputUpdated);};$prototype.createPages=function(){this.input.load();};$prototype.createEditorPages=function(){if(!this.hasPages()){var page=new userSmarts.sx.model.workspaces.editors.WorkspaceOverviewPage();this.addPage(page);page=new userSmarts.sx.model.workspaces.editors.WorkspaceMapPage();this.addPage(page);}};$prototype.doSave=function(){this.getEditorInput().save();};$prototype.onInputLoaded=function(event){var success=event.newValue;if(success){if(!this.outer||!this.tabControl){this.createPartControl();}
this.createEditorPages();this.outer.update();this.updateTab();var ps=userSmarts.runtime.Platform.getPropertyService();ps.setProperty("editor","initialized",this);}else{var wb=userSmarts.ui.PlatformUI.getWorkbench();var page=wb.getActiveWorkbenchWindow().getActivePage();page.closeEditor(this,false);}};$prototype.onInputUpdated=function(event){for(var p=0;p<this.pages.length;++p){this.pages[p].dirty=false;}
this.setDirty(false);this.updateTab();};$prototype.contributeToActionBars=function(){var bars=this.getSite().getActionBars();var tbmgr=bars.getToolbarManager();if(!this.saveEditorAction){this.saveEditorAction=new userSmarts.wt.action.SaveEditorAction({editor:this});if(userSmarts.sx.Plugin!=undefined){if(userSmarts.sx.Plugin.isUserInRole("EDIT_WORKSPACE")){this.editable=true;tbmgr.add(this.saveEditorAction);}else{this.editable=false;}}else{this.editable=true;tbmgr.add(this.saveEditorAction);}}};$prototype.getMap=function(){return this.getEditorInput().getMap();};$prototype.getViewContext=function(){return this.getEditorInput().getViewContext();};$prototype.getViewContextModel=function(){return this.getEditorInput().getViewContextModel();};$prototype.dispose=function(){if(this.loadedListener){disconnect(this.loadedListener);this.loadedListener=null;}
if(this.updatedListener){disconnect(this.updatedListener);this.updatedListener=null;}
userSmarts.ui.MultiPageEditorPart.prototype.dispose.call(this);};namespace("userSmarts.sx.model.workspaces.editors");$namespace.WorkspaceEditorInput=Class.create(userSmarts.ui.EditorInput);$prototype.initialize=function(superClass,properties){superClass.call(this,properties);if(this.id&&!this.url){this.url="pub/workspaces/"+id+".atom";}
if(!this.workspace&&this.url){this.workspace=new userSmarts.sx.model.workspaces.pub.Workspace({url:this.url});}else if(this.workspace&&!this.name){this.name=this.workspace.getTitle();}
this.createdCallback=bind(this.onCreated,this);this.savedCallback=bind(this.onUpdated,this);this.errback=bind(this.onError,this);}
$prototype.equals=function(other){if(this.url){if(other.url){return this.url==other.url;}else if(other.workspace){return this.url==other.workspace.url;}}else if(this.workspace){if(other.workspace){return this.workspace.equals(other.workspace);}else if(other.url){return this.workspace.url==other.url;}}
return false;};$prototype.get=function(){return this.workspace.get();};$prototype.del=function(){return this.workspace.del();};$prototype.load=function(){if(!this.workspace.url){this.setDirty(true);this.setProperty("loaded",true);}else{var def=this.get();def.addCallback(bind(this.onWorkspaceLoaded,this));def.addErrback(this.errback);}};$prototype.onWorkspaceLoaded=function(workspaceObj){this.loadDefaultMap();};$prototype.save=function(){var ps=userSmarts.runtime.Platform.getPropertyService();var contributorName=ps.getProperty("user","fullName");this.workspace.setContributor(contributorName);var bbox=this.getViewContext().getView();this.workspace.setWhere(bbox);if(!this.workspace.url){var workspace=userSmarts.runtime.Platform.getWorkspace();var collURL=workspace.getLink("workspaces").href;var collection=new userSmarts.pub.atom.GeoCollection({url:collURL});var def=collection.add(this.workspace);def.addCallback(this.createdCallback);def.addErrback(this.errback);}else{var def=this.workspace.put();def.addCallback(this.savedCallback);def.addErrback(handleResponseError);}};$prototype.onUpdated=function(){this.setDirty(false);var ps=userSmarts.runtime.Platform.getPropertyService();ps.setProperty("workspace","updated",this.workspace.getId());this.setProperty("updated",true);};$prototype.onCreated=function(entry){this.workspace.url=entry.getLink();this.workspace.setId(entry.getId());var collection=entry.getCollection();if(collection){collection.dispose();}
this.setDirty(false);var ps=userSmarts.runtime.Platform.getPropertyService();ps.setProperty("workspace","created",this.workspace.getId());this.setProperty("updated",true);};$prototype.onError=function(e){handleResponseError(e);this.setProperty("loaded",false);};$prototype.loadDefaultMap=function(){this.defMapURL=this.workspace.getLink("defaultMap");var res=new userSmarts.pub.Resource({url:this.defMapURL,params:{format:"text/xml"}});var def=res.get();def.addCallback(bind(this.parseDefaultMap,this));def.addErrback(this.errback);};$prototype.parseDefaultMap=function(xml){var parser=new userSmarts.maps.context.ViewContextParser();var context=parser.fromXML(xml);if(!context.id){context.id=id;}
this.defaultMapViewContext=context;this.setProperty("loaded",true);};$prototype.getWorkspace=function(){return this.workspace;};$prototype.getViewContext=function(){return this.defaultMapViewContext;};$prototype.setMap=function(map){if(map instanceof userSmarts.maps.widget.Widget){this.map=map;}};$prototype.getMap=function(){return this.map;};$prototype.getAnnotationModel=function(){var d=new Deferred();d.callback(null);return d;};$prototype.getViewContextModel=function(){if(!this.viewContextModel){this.viewContextModel=new userSmarts.maps.models.ViewContextTableModel();var context=this.defaultMapViewContext;if(context){this.viewContextModel.context=context;this.viewContextModel.populate(0);}}
return this.viewContextModel;};$prototype.getLegendModel=function(){return this.legendModel;};$prototype.getVersionModel=function(){return this.versionModel;};namespace("userSmarts.sx.model.workspaces.editors");$namespace.WorkspaceOverviewPage=Class.create(userSmarts.ui.EditorPart);$prototype.initialize=function(superclass,properties){superclass.call(this,properties);this.label="Overview";this.listeners=[];};$prototype.createPartControl=function(){if(!this.control){this.control=new userSmarts.wt.widgets.Composite({'class':'workspace-editor',label:this.label,updateOnBoundsChange:true,_layout:new userSmarts.wt.layout.RowLayout({type:"vertical"}),padding:{top:0,left:5,right:5,bottom:0}});var workspace=this.getEditorInput().getWorkspace();new userSmarts.wt.forms.Label({parent:this.control,value:"Details:",layoutData:{width:"100%",height:30}});this.titleField=new userSmarts.wt.forms.FieldComposite({parent:this.control,showLabel:true,title:"Title",layoutData:{width:"100%",height:30},labelWidth:80,binding:new BeanPropertyBinding(workspace,"title"),validator:this,validationFunc:"onInputChange"});this.summaryField=new userSmarts.wt.forms.TextAreaComposite({parent:this.control,showLabelOnTop:true,title:"Summary",layoutData:{width:"100%",height:100},binding:new BeanPropertyBinding(workspace,"summary"),validator:this,validationFunc:"onInputChange"});new userSmarts.wt.forms.Label({parent:this.control,value:"Keywords:",layoutData:{width:"100%",height:25}});this.keywordLabel=new userSmarts.wt.widgets.Control({parent:this.control,layoutData:{width:"100%",height:50}});this.updateKeywords();new userSmarts.wt.forms.Label({parent:this.control,value:"Actions:",layoutData:{width:"100%",height:30}});this.editable=true;new userSmarts.wt.action.SaveEditorAction({parent:this.control,editor:this.parent,showText:true,layoutData:{width:"100%",height:20},border:{style:"none",top:0,left:0,right:0,bottom:0}});}
return this.control;};$prototype.findPath=function(path){return userSmarts.sx.Plugin.getURI(path);};$prototype.updateKeywords=function(){for(var i=0;i<this.listeners.length;++i){disconnect(this.listeners[i]);}
var node=this.keywordLabel.getNode();replaceChildNodes(node,[]);var workspace=this.getEditorInput().getWorkspace();var keywords=workspace.getKeywords();for(var i=0;i<keywords.length;++i){var keyword=keywords[i];if(keyword){var closer=SUP({}," [x] ");closer.style.cursor="pointer";closer.style.color="#ff0000";closer.title="Remove this keyword";closer.keywordIndex=i;this.listeners.push(connect(closer,"onclick",this,this.removeKeyword));var span=SPAN({'class':'editor-section-text'},(i>0?", ":"")+keyword,closer);span.style.cursor="pointer";span.title="Edit this keyword";span.keywordIndex=i;this.listeners.push(connect(span,'onclick',this,this.editKeyword));node.appendChild(span);}}
var opener=SUP({},"[+]");opener.style.color="#00ff00";var button=SPAN({'class':'editor-section-text'},((keywords.length>0)?", ":"")+"New Keyword...",opener);button.style.cursor="pointer";button.style.fontStyle="italic";button.title="Add new keyword";this.listeners.push(connect(button,'onclick',this,this.addKeyword));node.appendChild(button);};$prototype.onInputChange=function(event){if(this.editable){this.parent.setDirty(true);}};$prototype.doSave=function(){this.getEditorInput().save();this.parent.setDirty(false);};$prototype.removeKeyword=function(event){var button=event.src();var keyword=button.keywordIndex;var workspace=this.getEditorInput().getWorkspace();var keywords=workspace.getKeywords();keywords.splice(keyword,1);workspace.setKeywords(keywords);this.updateKeywords();this.parent.setDirty(true);};$prototype.editKeyword=function(event){var input=event.src();var index=input.keywordIndex;var workspace=this.getEditorInput().getWorkspace();var keywords=workspace.getKeywords();var value=prompt("Enter the new value:",keywords[index]);if(value){keywords[index]=value;workspace.setKeywords(keywords);this.updateKeywords();this.parent.setDirty(true);}}
$prototype.addKeyword=function(event){var keyword=prompt("Enter the new keyword:","");if(keyword){var workspace=this.getEditorInput().getWorkspace();var keywords=workspace.getKeywords();keywords.push(keyword);workspace.setKeywords(keywords);this.updateKeywords();this.parent.setDirty(true);}};namespace("userSmarts.sx.model.workspaces.editors");$namespace.WorkspaceMapPage=Class.create(userSmarts.ui.EditorPart);$prototype.initialize=function(superclass,properties){superclass.call(this,properties);this.label="Map";};$prototype.createPartControl=function(){if(!this.control){var div=DIV({'class':'map-holder'});div.style.overflow="hidden";this.control=new userSmarts.maps.widget.MapControl({adapter:this,node:div,label:this.label});if(this.input){this.context=this.getViewContext();var map=this.buildMap(600,500);map.setContext(this.context);var toolFactory=new ToolIconFactory();var toolbarModel=new userSmarts.maps.widget.ToolBarModel({factory:toolFactory});toolbarModel.addTool(new userSmarts.maps.tools.DragTool({factory:toolFactory}));toolbarModel.addTool(new userSmarts.maps.tools.ZoomTool({factory:toolFactory}));toolbarModel.addTool(new userSmarts.maps.tools.ZoomToBoxTool({factory:toolFactory}));map.register('toolbar-model',toolbarModel);this.map=map;}}
return this.control;};$prototype.contributeToActionBars=function(tbmgr){if(!this.toolItems){this.toolItems=[];var tools=this.getMap().locate("toolbar-model").getTools();for(var i=0;i<tools.length;++i){this.toolItems.push(new userSmarts.maps.widget.ToolContributionItem({tool:tools[i]}));};}
for(var i=0;i<this.toolItems.length;++i){tbmgr.add(this.toolItems[i]);};tbmgr.add(new userSmarts.wt.action.Action({id:'saveMapAction',text:'Save Map',toolTipText:'Save Map',run:bind(this.saveMap,this),image:"image.save"}));};$prototype.getMap=function(){return this.map;};$prototype.getViewContext=function(){return this.input.getViewContext();};$prototype.saveMap=function(){this.input.saveDefaultMap();};$prototype.resizeMap=function(width,height){if(!this.map)return;var tbmodel=this.map.locate('toolbar-model');if(tbmodel){var tools=tbmodel.getTools();var numTools=tools.length;for(var i=0;i<numTools;i++){tools[i].setProperty("enabled",false);}
this.map.unregister('toolbar-model');}
this.map.dispose();this.map=null;this.map=this.buildMap(width,height);if(tbmodel)this.map.register('toolbar-model',tbmodel);if(typeof(this.context)=='object'){this.map.setContext(this.context);}};$prototype.buildMap=function(width,height){if(width){this.width=width;}
if(height){this.height=height;}
var widget=userSmarts.maps.widget.Manager.createMap({id:"main",showScale:true,debug:false,timeout:3000,width:this.width,height:this.height});widget.locate("canvas").disableRecenter();this.input.setMap(widget);if(this.control){replaceChildNodes(this.control.getNode(),widget.paint());}
return widget;};namespace("userSmarts.sx.model.workspaces.actions");namespace("userSmarts.sx.model.workspaces.actions");namespace("userSmarts.sx.model.workspaces.actions");$namespace.NewWorkspaceAction=Class.create(userSmarts.wt.action.Action);$prototype.initialize=function(superClass,properties){properties=setdefault(properties,{id:'newWorkspaceAction',text:"New",toolTipText:'Create a new Workspace',image:"image.workspace.add"});superClass.call(this,properties);this.callback=bind(this.onWorkspaceCreated,this);this.errback=handleResponseError;};$prototype.run=function(){var title=prompt("Enter the new workspace's title:","New Workspace");if(!title){alert("Invalid title, aborting creation");return;}
var view=null;var map=null;var wb=userSmarts.ui.PlatformUI.getWorkbench();var page=wb.getActiveWorkbenchWindow().getActivePage();var editor=page.getActiveEditor();if(editor&&editor instanceof userSmarts.maps.editors.MapEditor){var context=editor.getProperty("context");if(context){view=context.getView();map=context;}}
if(!view){view=new Geometry("Box");view.addPoint(new Point(-125,20));view.addPoint(new Point(-66,60));}
var workspace=new userSmarts.sx.model.workspaces.pub.Workspace();workspace.setTitle(title);workspace.setSummary("[Enter workspace description]");workspace.setWhere(view);if(map){var xml=map.toXml();setNodeAttribute(xml,"collectionId","");setNodeAttribute(xml,"id","");workspace.setContent(xml);}
workspace.setLink(null,"");workspace.setLink("defaultMap","");workspace.setLink("maps","");workspace.setLink("reports","");workspace.setLink("situations","");workspace.setLink("events","");var collection=new userSmarts.pub.atom.Collection({url:"pub/workspaces.atom"});var def=collection.add(workspace);def.addCallback(this.callback);def.addErrback(this.errback);};$prototype.onWorkspaceCreated=function(workspace){var id=workspace.getId();var title=workspace.getTitle();var url=workspace.getLink();workspace.getCollection().dispose();var wb=userSmarts.ui.PlatformUI.getWorkbench();var page=wb.getActiveWorkbenchWindow().getActivePage();var input=new userSmarts.sx.model.workspaces.editors.WorkspaceEditorInput({name:title,url:url});page.openEditor(input,"userSmarts.sx.model.workspaces.editors.WorkspaceEditor",true);var ps=userSmarts.runtime.Platform.getPropertyService();ps.setProperty("workspace","created",id);};namespace("userSmarts.sx.model.workspaces.actions");$namespace.EditWorkspaceAction=Class.create(userSmarts.wt.action.Action);$prototype.initialize=function(superClass,properties){properties=setdefault(properties,{id:'editWorkspaceAction',text:"Edit",toolTipText:'Edit Selected Workspace',image:"image.workspace.edit"});superClass.call(this,properties);};$prototype.run=function(){var ps=userSmarts.runtime.Platform.getPropertyService();var selection=ps.getProperty("workspace","selected");if(selection&&selection.url){var page=userSmarts.ui.PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();var input=new userSmarts.sx.model.workspaces.editors.WorkspaceEditorInput({name:selection.label,url:selection.url});page.openEditor(input,"userSmarts.sx.model.workspaces.editors.WorkspaceEditor",true);}};namespace("userSmarts.sx.model.workspaces.actions");$namespace.EditCurrentWorkspaceAction=Class.create(userSmarts.wt.action.Action);$prototype.initialize=function(superClass,properties){properties=setdefault(properties,{id:'editCurrentWorkspaceAction',text:"Edit Current",toolTipText:'Edit Current Workspace',image:"image.workspace.edit"});superClass.call(this,properties);};$prototype.run=function(){var ws=userSmarts.runtime.Platform.getWorkspace();var page=userSmarts.ui.PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();var input=new userSmarts.sx.model.workspaces.editors.WorkspaceEditorInput({name:ws.title,url:ws.getLink("alternate").href});page.openEditor(input,"userSmarts.sx.model.workspaces.editors.WorkspaceEditor",true);};namespace("userSmarts.sx.model.workspaces.actions");$namespace.DeleteWorkspaceAction=Class.create(userSmarts.wt.action.Action);$prototype.initialize=function(superClass,properties){properties=setdefault(properties,{id:'deleteWorkspaceAction',text:"Delete",toolTipText:'Delete Selected Workspace',image:"image.workspace.delete"});superClass.call(this,properties);};$prototype.run=function(){var ps=userSmarts.runtime.Platform.getPropertyService();var selection=ps.getProperty("workspace","selected");if(selection&&selection.url){if(userSmarts.wt.dialogs.MessageDialog.openConfirm("Delete Workspace","Are you sure you want to delete '"+selection.label+"'?")){if(selection.id==userSmarts.runtime.Platform.getWorkspace().id){alert("Cannot delete current workspace, change to another workspace first!");return;}
var workspace=new userSmarts.sx.model.workspaces.pub.Workspace();workspace.setURL(selection.url);var def=workspace.del();def.addCallback(bind(this.onWorkspaceDeleted,this));def.addErrback(handleResponseError);}}else{alert("Select a Workspace first!");}};$prototype.onWorkspaceDeleted=function(){var ps=userSmarts.runtime.Platform.getPropertyService();ps.setProperty("workspace","deleted",null);ps.setProperty("workspace","selected",null);};namespace("userSmarts.sx.model.workspaces.dialogs");namespace("userSmarts.sx.model.workspaces.dialogs");namespace("userSmarts.sx.model.workspaces.dialogs");$namespace.SelectRoleDialog=Class.create(userSmarts.wt.dialogs.CDialog);$prototype.initialize=function(superClass,properties){properties=setdefault(properties,{modal:false,width:225,height:150,title:"Add Role",enableDrag:true,enableResize:true,showClose:true,description:"Select the User Role to add to the current user:"});superClass.call(this,properties);};$prototype.createDialogArea=function(composite){composite.setLayout(new userSmarts.wt.layout.RowLayout({type:"vertical"}));new userSmarts.wt.forms.Text({parent:composite,layoutData:{width:"100%",height:"*"},padding:{top:5,left:0,right:0,bottom:0},value:this.description});this.selector=new userSmarts.wt.forms.SelectControl({parent:composite,layoutData:{width:"100%",height:30},datatype:userSmarts.sx.Plugin.ROLE_DATATYPE});};$prototype.focus=function(){this.selector.focus();};$prototype.getRole=function(){return this.selector.getValue();};$prototype.okPressed=function(){if(this.deferred){this.deferred.callback(this.getRole());this.deferred=null;}};namespace("userSmarts.sx.model.workspaces.dialogs");$namespace.WorkspaceChooserDialog=Class.create(userSmarts.wt.dialogs.CDialog);$prototype.initialize=function(superClass,properties){properties=setdefault(properties,{'class':'workspace-dialog',modal:false,width:300,height:250,enableKeys:true,showClose:false,enableDrag:true,enableResize:true,title:"Select Workspace",description:"Select the desired workspace from the list:"});superClass.call(this,properties);};$prototype.createDialogArea=function(composite){composite.setLayout(new userSmarts.wt.layout.RowLayout({type:"vertical"}));new userSmarts.wt.forms.Text({parent:composite,value:this.description,layoutData:{width:"100%",height:30}});this.model=new userSmarts.sx.model.workspaces.models.WorkspacesModel();var list=new userSmarts.wt.widgets.List({model:this.model,showFooter:false,parent:composite,border:{style:"solid",top:1,left:1,right:1,bottom:1},margin:{top:2,left:0,right:0,bottom:2},layoutData:{width:"100%",height:"*"}});connect(list,"selected",this,this.updateSelection);var misc=new userSmarts.wt.widgets.Control({parent:composite,layoutData:{width:"100%",height:25}});var cb=INPUT({type:"checkbox"});cb.disabled=true;this.defaultWSCheckbox=cb;var span=SPAN(null,"Set as my default workspace");span.style.cursor="pointer";misc.getNode().appendChild(cb);misc.getNode().appendChild(span);};$prototype.createButtonBar=function(){userSmarts.wt.dialogs.CDialog.prototype.createButtonBar.call(this);var ok=this.getOKButton();ok.disabled=true;var userRoles=userSmarts.runtime.Platform.getPropertyService().getProperty("user","groups");if(userRoles.contains("ADMIN")||userRoles.contains("CREATE_WORKSPACE")){var node=this.buttonBar.getNode();var cb=BUTTON(null,"Admin");cb.style.width="75px";connect(cb,'onclick',this,this.onCreate);node.appendChild(cb);}};$prototype.okPressed=function(){if(this.deferred){this.deferred.callback(this.workspace);this.deferred=null;}};$prototype.getWorkspace=function(){return this.workspace;};$prototype.onCreate=function(){if(this.deferred){this.deferred.callback("ADMIN");this.deferred=null;}
this.close();};$prototype.updateSelection=function(event){var workspace=event.newValue;if(workspace){this.workspace=workspace.getId();}else{this.workspace=null;this.defaultWSCheckbox.checked=false;}
var ok=this.getOKButton();ok.disabled=!this.workspace;this.defaultWSCheckbox.disabled=ok.disabled;};namespace("userSmarts.sx.model.workspaces.pub");namespace("userSmarts.sx.model.workspaces.pub");namespace("userSmarts.sx.model.workspaces.pub");$namespace.Workspace=Class.create(userSmarts.pub.atom.GeoEntry);$prototype.initialize=function(superClass,properties){properties=setdefault(properties,{});if(!properties.params){properties.params={};}
if(!properties.params.format){properties.params.format="text/xml";}
superClass.call(this,properties);};$prototype.updateValueFromElement=function(node){if(!isXmlNode(node)||node.nodeType!=1)return;var name=DOMUtils.getName(node);if(!name)return;if("keywords"==name){var str=scrapeText(node);if(str&&str.length>0){this[name]=str.split(",");}}else{userSmarts.pub.atom.GeoEntry.prototype.updateValueFromElement.call(this,node);}};$prototype.onKeywordsChanged=function(event){this.setKeywords(this.keywords);};$prototype.getKeywords=function(){return this.keywords||[];};$prototype.setKeywords=function(keys){if(typeof(keys)=='string'){this.keywords=keys.split(",");}else if(typeof(keys.push)=='function'){this.keywords=keys;}};$prototype.getDefaultMapLink=function(){return this.getLink("defaultMap");};$prototype.setDefaultMapLink=function(link){this.setLink("defaultMap",link);}
$prototype.getMapsCollectionLink=function(){return this.getLink("maps");};$prototype.setMapsCollectionLink=function(link){this.setLink("maps",link);};$prototype.getReportsCollectionLink=function(){return this.getLink("reports");};$prototype.setReportsCollectionLink=function(link){this.setLink("reports",link);};$prototype.getSituationsCollectionLink=function(){return this.getLink("situations");};$prototype.setSituationsCollectionLink=function(link){this.setLink("situations",link);};$prototype.getBoundingBox=function(){var where=this.getWhere();if(where){return where.getEnvelope();}
return null;};$prototype.setBoundingBox=function(bbox){if(bbox instanceof Geometry){this.setWhere(bbox);}};$prototype.toXml=function(doc){var entry=userSmarts.pub.atom.GeoEntry.prototype.toXml.call(this,doc);if(entry){var keyE=createElementNS("http://a9.com/-/spec/opensearch/1.1/",'keywords',doc)
entry.appendChild(keyE);keyE.appendChild(doc.createTextNode(this.getKeywords().toString()));}
return entry;};$prototype.appendElement=function(parentNode,tagName,content,uri){if(!parentNode||!tagName||!content)return null;uri=uri||userSmarts.pub.atom.Entry2.ATOM_NS_URI;var doc=parentNode.ownerDocument;if(tagName=="content"){var parent=parentNode;var node=createElementNS(uri,tagName,doc);parent.appendChild(node);if(isXmlNode(content)){node.appendChild(content);}
return node;}else{return userSmarts.pub.atom.GeoEntry.prototype.appendElement.call(this,parentNode,tagName,content,uri);}};