diff --git a/baguajie-admin/libs/Cairngorm.swc b/baguajie-admin/libs/Cairngorm.swc new file mode 100644 index 0000000..9a06b63 Binary files /dev/null and b/baguajie-admin/libs/Cairngorm.swc differ diff --git a/baguajie-admin/src/Admin.mxml b/baguajie-admin/src/Admin.mxml new file mode 100644 index 0000000..1419916 --- /dev/null +++ b/baguajie-admin/src/Admin.mxml @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/baguajie-admin/src/assets/menuBar_blankSkin.png b/baguajie-admin/src/assets/menuBar_blankSkin.png new file mode 100644 index 0000000..da611f3 Binary files /dev/null and b/baguajie-admin/src/assets/menuBar_blankSkin.png differ diff --git a/baguajie-admin/src/assets/menuBar_selectedSkin.gif b/baguajie-admin/src/assets/menuBar_selectedSkin.gif new file mode 100644 index 0000000..f396a7f Binary files /dev/null and b/baguajie-admin/src/assets/menuBar_selectedSkin.gif differ diff --git a/baguajie-admin/src/net/baguajie/admin/command/BaseCommand.as b/baguajie-admin/src/net/baguajie/admin/command/BaseCommand.as new file mode 100644 index 0000000..bcde065 --- /dev/null +++ b/baguajie-admin/src/net/baguajie/admin/command/BaseCommand.as @@ -0,0 +1,97 @@ +package net.baguajie.admin.command +{ + import com.adobe.cairngorm.business.ServiceLocator; + import com.adobe.cairngorm.commands.ICommand; + import com.adobe.cairngorm.control.CairngormEvent; + import mx.rpc.AsyncToken; + import mx.rpc.IResponder; + import mx.rpc.events.FaultEvent; + import net.baguajie.admin.util.ErrorHandleUtil; + + public class BaseCommand implements ICommand, IResponder + { + private static const TRACE_EXCUTING_TIME:Boolean=true; + + public function BaseCommand() + { + + } + + protected var serviceId:String="adminRO"; + + private var executingStartTime:Number; + private var methodName:String; + + public function execute(event:CairngormEvent):void + { +// to be overridden by subclasses +// prepare necessary arguments for the remote call +// and then use the method "sendRemoteCall" to do the actual remote calling + } + + public function fault(event:Object):void + { +// to be overridden by subclasses + } + + public function finallyExecute(event:Object):void + { +// to be overridden by subclasses + } + + public function result(event:Object):void + { +// to be overridden by subclasses + } + + protected function faultHandler(event:Object):void + { + if (!event || !event.fault) + return; + + trace("Command \"" + methodName + "\" failed."); + trace(FaultEvent(event).message); + trace(FaultEvent(event).fault); + + fault(event); + + finallyExecute(event); + } + + protected function resultHandler(event:Object):void + { + if (TRACE_EXCUTING_TIME) + trace("Method \"" + methodName + "\" cost", ((new Date()).getTime() - executingStartTime) / 1000, "seconds."); + + var containError:Boolean=false; + + if (!event || !event.result || !ErrorHandleUtil.checkErrorForRemoteObject(event.result)) + { + containError=true; + } + + if (!containError) + { + result(event); + } + + finallyExecute(event); + } + + /* + * This method is to call a remote function on service + */ + protected function sendRemoteCall(methodName:String, ... args):void + { + if (TRACE_EXCUTING_TIME) + this.executingStartTime=(new Date()).getTime(); + + this.methodName=methodName; + + var service:Object=ServiceLocator.getInstance().getRemoteObject(serviceId); + var token:AsyncToken=service.getOperation(methodName).send.apply(null, args); + token.resultHandler=resultHandler; + token.faultHandler=faultHandler; + } + } +} diff --git a/baguajie-admin/src/net/baguajie/admin/command/MultipleROCommand.as b/baguajie-admin/src/net/baguajie/admin/command/MultipleROCommand.as new file mode 100644 index 0000000..c3dd5a3 --- /dev/null +++ b/baguajie-admin/src/net/baguajie/admin/command/MultipleROCommand.as @@ -0,0 +1,32 @@ +package net.baguajie.admin.command +{ + import com.adobe.cairngorm.control.CairngormEvent; + import net.baguajie.admin.controller.MultipleROToken; + import net.baguajie.admin.event.MultipleROEvent; + + public class MultipleROCommand extends SimpleROCommand + { + + public function MultipleROCommand() + { + super(); + } + + private var multipleROToken:MultipleROToken; + + override public function execute(event:CairngormEvent):void + { + super.execute(event); + + multipleROToken=MultipleROToken(MultipleROEvent(event).token); + } + + override public function result(event:Object):void + { + super.result(event); + + if (multipleROToken.defaultResultHandler != null) + multipleROToken.defaultResultHandler(); + } + } +} diff --git a/baguajie-admin/src/net/baguajie/admin/command/SimpleROCommand.as b/baguajie-admin/src/net/baguajie/admin/command/SimpleROCommand.as new file mode 100644 index 0000000..d52e800 --- /dev/null +++ b/baguajie-admin/src/net/baguajie/admin/command/SimpleROCommand.as @@ -0,0 +1,57 @@ +package net.baguajie.admin.command +{ + import com.adobe.cairngorm.control.CairngormEvent; + import mx.rpc.events.ResultEvent; + import net.baguajie.admin.controller.ROResult; + import net.baguajie.admin.controller.SimpleROToken; + import net.baguajie.admin.event.SimpleROEvent; + + public class SimpleROCommand extends BaseCommand + { + + public function SimpleROCommand() + { + super(); + } + + private var simpleROToken:SimpleROToken; + + override public function execute(event:CairngormEvent):void + { + var simpleROEvent:SimpleROEvent=SimpleROEvent(event); + var newArgs:Array=[simpleROEvent.methodName]; + if (simpleROEvent.args && simpleROEvent.args.length > 0) + { + newArgs=newArgs.concat(simpleROEvent.args); + } + + sendRemoteCall.apply(null, newArgs); + + simpleROToken=simpleROEvent.token; + } + + override public function fault(event:Object):void + { + if (simpleROToken.faultHandler != null) + { + simpleROToken.faultHandler(); + } + } + + override public function finallyExecute(event:Object):void + { + if (simpleROToken.finalHandler != null) + { + simpleROToken.finalHandler(); + } + } + + override public function result(event:Object):void + { + if (simpleROToken.resultHandler != null) + { + simpleROToken.resultHandler(ROResult(ResultEvent(event).result).result); + } + } + } +} diff --git a/baguajie-admin/src/net/baguajie/admin/controller/AppController.as b/baguajie-admin/src/net/baguajie/admin/controller/AppController.as new file mode 100644 index 0000000..eb7e07c --- /dev/null +++ b/baguajie-admin/src/net/baguajie/admin/controller/AppController.as @@ -0,0 +1,18 @@ +package net.baguajie.admin.controller +{ + import com.adobe.cairngorm.control.FrontController; + import net.baguajie.admin.command.MultipleROCommand; + import net.baguajie.admin.command.SimpleROCommand; + import net.baguajie.admin.event.MultipleROEvent; + import net.baguajie.admin.event.SimpleROEvent; + + public class AppController extends FrontController + { + public function AppController() + { + super(); + addCommand(SimpleROEvent.SIMPLE_RO_EVENT, SimpleROCommand); + addCommand(MultipleROEvent.MULTIPLE_RO_EVENT, MultipleROCommand); + } + } +} diff --git a/baguajie-admin/src/net/baguajie/admin/controller/MultipleROInvoker.as b/baguajie-admin/src/net/baguajie/admin/controller/MultipleROInvoker.as new file mode 100644 index 0000000..f72d6a0 --- /dev/null +++ b/baguajie-admin/src/net/baguajie/admin/controller/MultipleROInvoker.as @@ -0,0 +1,26 @@ +package net.baguajie.admin.controller +{ + import mx.collections.ArrayCollection; + + public class MultipleROInvoker extends MultipleROInvokerBase + { + + private static const SAVE_OR_UPDATE_PROXY_LIMITS:String = "saveOrUpdateProxyLimits"; + private static const DELETE_PORXY_LIMITS:String="deleteProxyLimits"; + + public function MultipleROInvoker() + { + super(); + } + + public function saveOrUpdateProxyLimits(proxyLimits:ArrayCollection):SimpleROToken + { + return newInitialRO(SAVE_OR_UPDATE_PROXY_LIMITS, arguments); + } + + public function deleteProxyLimits(proxyLimits:ArrayCollection):SimpleROToken + { + return newInitialRO(DELETE_PORXY_LIMITS, arguments); + } + } +} \ No newline at end of file diff --git a/baguajie-admin/src/net/baguajie/admin/controller/MultipleROInvokerBase.as b/baguajie-admin/src/net/baguajie/admin/controller/MultipleROInvokerBase.as new file mode 100644 index 0000000..0ca1aef --- /dev/null +++ b/baguajie-admin/src/net/baguajie/admin/controller/MultipleROInvokerBase.as @@ -0,0 +1,34 @@ +package net.baguajie.admin.controller +{ + import com.adobe.cairngorm.control.CairngormEventDispatcher; + + import flash.events.EventDispatcher; + + import net.baguajie.admin.controller.MultipleROToken; + import net.baguajie.admin.event.MultipleROEvent; + + [Event(name="multipleROComplete", type="com.statestr.gmrm.event.MultipleROEvent")] + + public class MultipleROInvokerBase extends EventDispatcher + { + protected var counter:int = 0; + + protected function newInitialRO(methodName:String, arguments:Array):SimpleROToken + { + counter--; + var token:MultipleROToken = new MultipleROToken(); + token._defaultResultHandler = multipleRODefaultResultHandler; + var event:MultipleROToken = MultipleROEvent.newInitialROEvent(methodName, arguments, token); + CairngormEventDispatcher.getInstance().dispatchEvent(event); + return token; + } + + protected function multipleRODefaultResultHandler():void + { + counter++; + if (counter == 0){ + dispatchEvent(new MultipleROEvent(MultipleROEvent.MULTIPLE_RO_COMPLETE)); + } + } + } +} \ No newline at end of file diff --git a/baguajie-admin/src/net/baguajie/admin/controller/MultipleROToken.as b/baguajie-admin/src/net/baguajie/admin/controller/MultipleROToken.as new file mode 100644 index 0000000..e3187c5 --- /dev/null +++ b/baguajie-admin/src/net/baguajie/admin/controller/MultipleROToken.as @@ -0,0 +1,12 @@ +package net.baguajie.admin.controller +{ + public class MultipleROToken extends SimpleROToken + { + internal var _defaultResultHandler:Function; + + public function get defaultResultHandler():Function + { + return _defaultResultHandler; + } + } +} \ No newline at end of file diff --git a/baguajie-admin/src/net/baguajie/admin/controller/ROResult.as b/baguajie-admin/src/net/baguajie/admin/controller/ROResult.as new file mode 100644 index 0000000..3b2ee3a --- /dev/null +++ b/baguajie-admin/src/net/baguajie/admin/controller/ROResult.as @@ -0,0 +1,16 @@ +package net.baguajie.admin.controller +{ + import mx.collections.ArrayCollection; + + import net.baguajie.admin.vo.ErrorCodeVo; + + [RemoteClass(alias="net.baguajie.web.ros.ROResult")] + public class ROResult + { + public var errors:ArrayCollection; + + public var result:Object; + + public var errorCode:ErrorCodeVo; + } +} \ No newline at end of file diff --git a/baguajie-admin/src/net/baguajie/admin/controller/SimpleROInvoker.as b/baguajie-admin/src/net/baguajie/admin/controller/SimpleROInvoker.as new file mode 100644 index 0000000..3b96ebc --- /dev/null +++ b/baguajie-admin/src/net/baguajie/admin/controller/SimpleROInvoker.as @@ -0,0 +1,49 @@ +package net.baguajie.admin.controller +{ + import com.adobe.cairngorm.control.CairngormEventDispatcher; + + import mx.collections.ArrayCollection; + + import net.baguajie.admin.event.SimpleROEvent; + + public class SimpleROInvoker + { + private static const GET_SPOTS_AT_PAGE:String="getSpotsAtPage"; + private static const GET_USERS_AT_PAGE:String="getUsersAtPage"; + private static const GET_SPOST_BY_ID:String="getSpotById"; + private static const UPDATE_SPOT_STATUS:String = "updateSpotStatus"; + private static const UPDATE_USER_STATUS:String = "updateUserStatus"; + + public static function getSpotsAtPage(page:int):SimpleROToken + { + return newSimpleRO(GET_SPOTS_AT_PAGE, arguments); + } + + public static function updateSpotStatus(id:String, status:String):SimpleROToken + { + return newSimpleRO(UPDATE_SPOT_STATUS, arguments); + } + + public static function getUsersAtPage(page:int):SimpleROToken + { + return newSimpleRO(GET_USERS_AT_PAGE, arguments); + } + + public static function updateUserStatus(id:String, status:String):SimpleROToken + { + return newSimpleRO(UPDATE_USER_STATUS, arguments); + } + + private static function newSimpleRO(methodName:String, arguments:Array):SimpleROToken + { + var token:SimpleROToken=new SimpleROToken(); + var event:SimpleROEvent=SimpleROEvent.newSimpleROEvent(methodName, arguments, token); + CairngormEventDispatcher.getInstance().dispatchEvent(event); + return token; + } + + public function SimpleROInvoker() + { + } + } +} diff --git a/baguajie-admin/src/net/baguajie/admin/controller/SimpleROToken.as b/baguajie-admin/src/net/baguajie/admin/controller/SimpleROToken.as new file mode 100644 index 0000000..9e21025 --- /dev/null +++ b/baguajie-admin/src/net/baguajie/admin/controller/SimpleROToken.as @@ -0,0 +1,13 @@ +package net.baguajie.admin.controller +{ + import mx.rpc.AsyncToken; + + public class SimpleROToken + { + public var resultHandler:Function; + + public var faultHandler:Function; + + public var finalHandler:Function; + } +} \ No newline at end of file diff --git a/baguajie-admin/src/net/baguajie/admin/event/MultipleROEvent.as b/baguajie-admin/src/net/baguajie/admin/event/MultipleROEvent.as new file mode 100644 index 0000000..197db05 --- /dev/null +++ b/baguajie-admin/src/net/baguajie/admin/event/MultipleROEvent.as @@ -0,0 +1,37 @@ +package net.baguajie.admin.event +{ + import flash.events.Event; + + import net.baguajie.admin.controller.MultipleROToken; + + public class MultipleROEvent extends SimpleROEvent + { + public static const MULTIPLE_RO_EVENT:String = "multipleROEvent"; + + public static const MULTIPLE_RO_COMPLETE:String = "multipleROComplete"; + + public static function newInitialROEvent(methodName:String, args:Array, + token:MultipleROToken):MultipleROEvent + { + var event:MultipleROEvent = new MultipleROEvent(MULTIPLE_RO_EVENT); + event._methodName = methodName; + event._args = args; + event._token = token; + return event; + } + + public function MultipleROEvent(type:String, bubbles:Boolean = false, cancelable:Boolean = false) + { + super(type, bubbles, cancelable); + } + + override public function clone():Event + { + var newEvent:MultipleROEvent = new MultipleROEvent(type, bubbles, cancelable); + newEvent._methodName = methodName; + newEvent._args = args; + newEvent._token = token; + return newEvent; + } + } +} \ No newline at end of file diff --git a/baguajie-admin/src/net/baguajie/admin/event/SimpleROEvent.as b/baguajie-admin/src/net/baguajie/admin/event/SimpleROEvent.as new file mode 100644 index 0000000..653430d --- /dev/null +++ b/baguajie-admin/src/net/baguajie/admin/event/SimpleROEvent.as @@ -0,0 +1,58 @@ +package net.baguajie.admin.event +{ + import com.adobe.cairngorm.control.CairngormEvent; + + import flash.events.Event; + + import net.baguajie.admin.controller.SimpleROToken; + + public class SimpleROEvent extends CairngormEvent + { + public static const SIMPLE_RO_EVENT:String = "simpleROEvent"; + + public static function newSimpleROEvent(methodName:String, args:Array, + token:SimpleROToken):SimpleROEvent + { + var event:SimpleROEvent = new SimpleROEvent(SIMPLE_RO_EVENT); + event._methodName = methodName; + event._args = args; + event._token = token; + return event; + } + + protected var _methodName:String; + + public function get methodName():String + { + return _methodName; + } + + protected var _args:Array; + + public function get args():Array + { + return _args; + } + + protected var _token:SimpleROToken; + + public function get token():SimpleROToken + { + return _token; + } + + public function SimpleROEvent(type:String, bubbles:Boolean=false, cancelable:Boolean=false) + { + super(type, bubbles, cancelable); + } + + override public function clone():Event + { + var newEvent:SimpleROEvent = new SimpleROEvent(type, bubbles, cancelable); + newEvent._methodName = methodName; + newEvent._args = args; + newEvent._token = token; + return newEvent; + } + } +} \ No newline at end of file diff --git a/baguajie-admin/src/net/baguajie/admin/model/AdminModel.as b/baguajie-admin/src/net/baguajie/admin/model/AdminModel.as new file mode 100644 index 0000000..3042532 --- /dev/null +++ b/baguajie-admin/src/net/baguajie/admin/model/AdminModel.as @@ -0,0 +1,31 @@ +package net.baguajie.admin.model +{ + import com.adobe.cairngorm.model.ModelLocator; + import mx.collections.ArrayCollection; + import mx.containers.ViewStack; + import mx.controls.LinkBar; + + [Bindable] + public class AdminModel implements ModelLocator + { + private static var model:AdminModel; + + public static function getInstance():AdminModel + { + if (model == null) + { + model = new AdminModel(); + } + return model; + } + + public function AdminModel() + { + if (AdminModel.model != null) + throw new Error("Only one ModelLocator instance should be instantiated"); + } + + public var bodyStack:ViewStack; + public var menuBar:LinkBar; + } +} diff --git a/baguajie-admin/src/net/baguajie/admin/model/SpotDetailModel.as b/baguajie-admin/src/net/baguajie/admin/model/SpotDetailModel.as new file mode 100644 index 0000000..f91e81b --- /dev/null +++ b/baguajie-admin/src/net/baguajie/admin/model/SpotDetailModel.as @@ -0,0 +1,106 @@ +package net.baguajie.admin.model +{ + import com.adobe.cairngorm.model.ModelLocator; + + import flash.display.DisplayObject; + + import mx.collections.ArrayCollection; + import mx.containers.ViewStack; + import mx.controls.LinkBar; + import mx.core.INavigatorContent; + import mx.core.UIComponent; + import mx.events.CloseEvent; + import mx.managers.PopUpManager; + import mx.utils.ObjectUtil; + + import net.baguajie.admin.controller.SimpleROInvoker; + import net.baguajie.admin.controller.SimpleROToken; + import net.baguajie.admin.event.SimpleROEvent; + import net.baguajie.admin.util.ObjectCopyUtil; + import net.baguajie.admin.view.SpotDetailPopup; + import net.baguajie.admin.view.UserDetailPopup; + import net.baguajie.admin.vo.SpotVo; + + import spark.components.Application; + + [Bindable] + public class SpotDetailModel implements ModelLocator + { + private static var model:SpotDetailModel; + + public static function getInstance():SpotDetailModel + { + if (model == null) + { + model=new SpotDetailModel(); + } + return model; + } + + public function SpotDetailModel() + { + if (SpotDetailModel.model != null) + throw new Error("Only one ModelLocator instance should be instantiated"); + } + + public var imageHeight:int; + public var imageUrl:String; + public var imageWidth:int=190; + private var _orgSpot:SpotVo; + private var _spot:SpotVo; + private var _urlBase:String="http://localhost:8080/baguajie-web"; + + private var view:SpotDetailPopup; + + public function showPopup(spot:SpotVo, parentView:UIComponent):void + { + this.spot=spot; + if (!view) + { + view=new SpotDetailPopup(); + } + if (!view.parent) + { + PopUpManager.addPopUp(view, parentView.parentApplication.systemManager, true); + PopUpManager.centerPopUp(view); + } + } + + public function get spot():SpotVo + { + return _spot; + } + + public function set spot(value:SpotVo):void + { + _spot=ObjectUtil.copy(value) as SpotVo; + _orgSpot=ObjectUtil.copy(_spot) as SpotVo; + if (_spot.image && spot.image.orgSize && spot.image.orgSize.length == 2) + { + var w:int=_spot.image.orgSize[1]; + var h:int=_spot.image.orgSize[0]; + imageHeight=h * 190 / w; + imageUrl=_urlBase + "/images/spots/" + _spot.image.resId; + } + } + + public function update():void + { + if (_orgSpot.status != spot.status) + { + var token:SimpleROToken=SimpleROInvoker.updateSpotStatus(spot.id, spot.status); + token.resultHandler=updateSpotStatusCompleteHandler; + } + else + { + view.dispatchEvent(new CloseEvent(CloseEvent.CLOSE)); + } + } + + private function updateSpotStatusCompleteHandler(spot:SpotVo):void + { + ObjectCopyUtil.mergeUpdateList(new ArrayCollection([spot]), SpotModel.getInstance().spots, "id"); + view.dispatchEvent(new CloseEvent(CloseEvent.CLOSE)); + } + } +} diff --git a/baguajie-admin/src/net/baguajie/admin/model/SpotModel.as b/baguajie-admin/src/net/baguajie/admin/model/SpotModel.as new file mode 100644 index 0000000..722e92e --- /dev/null +++ b/baguajie-admin/src/net/baguajie/admin/model/SpotModel.as @@ -0,0 +1,67 @@ +package net.baguajie.admin.model +{ + import com.adobe.cairngorm.model.ModelLocator; + + import mx.collections.ArrayCollection; + import mx.containers.ViewStack; + import mx.controls.LinkBar; + + import net.baguajie.admin.controller.SimpleROInvoker; + import net.baguajie.admin.controller.SimpleROToken; + import net.baguajie.admin.event.SimpleROEvent; + import net.baguajie.admin.vo.ErrorCodeVo; + import net.baguajie.admin.vo.ResourceVo; + import net.baguajie.admin.vo.SpotVo; + import net.baguajie.admin.vo.UserVo; + + [Bindable] + public class SpotModel implements ModelLocator + { + private static var model:SpotModel; + private var user:UserVo; + private var res:ResourceVo; + private var spot:SpotVo; + private var errorCode:ErrorCodeVo; + + public static function getInstance():SpotModel + { + if (model == null) + { + model=new SpotModel(); + } + return model; + } + + public function SpotModel() + { + if (SpotModel.model != null) + throw new Error("Only one ModelLocator instance should be instantiated"); + } + + public var current:int=1; + public var spots:ArrayCollection=new ArrayCollection(); + public var total:int=1; + + + public function getSpots():void + { + var token:SimpleROToken=SimpleROInvoker.getSpotsAtPage(current-1); + token.resultHandler=getSpotsAtPageCompleteHandler; + } + + private function getSpotsAtPageCompleteHandler(spots:ArrayCollection):void + { + if (spots && spots.length != 0) + { + this.spots.source = spots.source; + } + else + { + this.spots.source = []; + current = 1; + total = 1; + } + this.spots.refresh(); + } + } +} diff --git a/baguajie-admin/src/net/baguajie/admin/model/UserDetailModel.as b/baguajie-admin/src/net/baguajie/admin/model/UserDetailModel.as new file mode 100644 index 0000000..2e38e3e --- /dev/null +++ b/baguajie-admin/src/net/baguajie/admin/model/UserDetailModel.as @@ -0,0 +1,87 @@ +package net.baguajie.admin.model +{ + import com.adobe.cairngorm.model.ModelLocator; + + import flash.display.DisplayObject; + + import mx.collections.ArrayCollection; + import mx.containers.ViewStack; + import mx.controls.LinkBar; + import mx.core.UIComponent; + import mx.events.CloseEvent; + import mx.managers.PopUpManager; + import mx.utils.ObjectUtil; + + import net.baguajie.admin.controller.SimpleROInvoker; + import net.baguajie.admin.controller.SimpleROToken; + import net.baguajie.admin.event.SimpleROEvent; + import net.baguajie.admin.util.ObjectCopyUtil; + import net.baguajie.admin.view.UserDetailPopup; + import net.baguajie.admin.vo.UserVo; + + import spark.components.Application; + + [Bindable] + public class UserDetailModel implements ModelLocator + { + private static var model:UserDetailModel; + + public static function getInstance():UserDetailModel + { + if (model == null) + { + model=new UserDetailModel(); + } + return model; + } + + public function UserDetailModel() + { + if (UserDetailModel.model != null) + throw new Error("Only one ModelLocator instance should be instantiated"); + } + + private var view:UserDetailPopup; + private var _user:UserVo; + private var _orgUser:UserVo; + + public function get user():UserVo{ + return _user; + } + + public function set user(value:UserVo):void{ + _user = ObjectUtil.copy(value) as UserVo; + _orgUser = ObjectUtil.copy(value) as UserVo; + } + + public function showPopup(user:UserVo, parentView:UIComponent):void{ + this.user = user; + if(!view){ + view = new UserDetailPopup(); + } + if(!view.parent){ + PopUpManager.addPopUp(view, parentView.parentApplication.systemManager, true); + PopUpManager.centerPopUp(view); + } + } + + public function update():void + { + if (_orgUser.status != user.status) + { + var token:SimpleROToken=SimpleROInvoker.updateUserStatus(user.id, user.status); + token.resultHandler=updateUserStatusCompleteHandler; + } + else + { + view.dispatchEvent(new CloseEvent(CloseEvent.CLOSE)); + } + } + + private function updateUserStatusCompleteHandler(user:UserVo):void + { + ObjectCopyUtil.mergeUpdateList(new ArrayCollection([user]), UserModel.getInstance().users, "id"); + view.dispatchEvent(new CloseEvent(CloseEvent.CLOSE)); + } + } +} \ No newline at end of file diff --git a/baguajie-admin/src/net/baguajie/admin/model/UserModel.as b/baguajie-admin/src/net/baguajie/admin/model/UserModel.as new file mode 100644 index 0000000..e5e38a7 --- /dev/null +++ b/baguajie-admin/src/net/baguajie/admin/model/UserModel.as @@ -0,0 +1,62 @@ +package net.baguajie.admin.model +{ + import com.adobe.cairngorm.model.ModelLocator; + + import mx.collections.ArrayCollection; + import mx.containers.ViewStack; + import mx.controls.LinkBar; + + import net.baguajie.admin.controller.SimpleROInvoker; + import net.baguajie.admin.controller.SimpleROToken; + import net.baguajie.admin.event.SimpleROEvent; + import net.baguajie.admin.vo.ErrorCodeVo; + import net.baguajie.admin.vo.ResourceVo; + import net.baguajie.admin.vo.SpotVo; + import net.baguajie.admin.vo.UserVo; + + [Bindable] + public class UserModel implements ModelLocator + { + private static var model:UserModel; + + public static function getInstance():UserModel + { + if (model == null) + { + model=new UserModel(); + } + return model; + } + + public function UserModel() + { + if (UserModel.model != null) + throw new Error("Only one ModelLocator instance should be instantiated"); + } + + public var current:int=1; + public var users:ArrayCollection=new ArrayCollection(); + public var total:int=1; + + public function getUsers():void + { + var token:SimpleROToken=SimpleROInvoker.getUsersAtPage(current-1); + token.resultHandler=getUsersAtPageCompleteHandler; + } + + private function getUsersAtPageCompleteHandler(users:ArrayCollection):void + { + if (users && users.length != 0) + { + this.users.source = users.source; + } + else + { + this.users.source = []; + current = 1; + total = 1; + } + this.users.refresh(); + } + } +} \ No newline at end of file diff --git a/baguajie-admin/src/net/baguajie/admin/service/Services.mxml b/baguajie-admin/src/net/baguajie/admin/service/Services.mxml new file mode 100644 index 0000000..2bf9f1f --- /dev/null +++ b/baguajie-admin/src/net/baguajie/admin/service/Services.mxml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + diff --git a/baguajie-admin/src/net/baguajie/admin/service/Services2.as b/baguajie-admin/src/net/baguajie/admin/service/Services2.as new file mode 100644 index 0000000..f084959 --- /dev/null +++ b/baguajie-admin/src/net/baguajie/admin/service/Services2.as @@ -0,0 +1,38 @@ +package net.baguajie.admin.service +{ + import com.adobe.cairngorm.business.ServiceLocator; + + import mx.messaging.ChannelSet; + import mx.messaging.channels.AMFChannel; + import mx.rpc.events.FaultEvent; + import mx.rpc.events.ResultEvent; + import mx.rpc.remoting.RemoteObject; + + public class Services2 extends ServiceLocator + { + public var adminRO:RemoteObject; + + public function Services2() + { + super(); + adminRO = new RemoteObject(); + adminRO.destination = "adminRO"; + adminRO.showBusyCursor = true; + adminRO.addEventListener( ResultEvent.RESULT, resultHandler); + adminRO.addEventListener( FaultEvent.FAULT, faultHandler); + var cs:ChannelSet = new ChannelSet(); + var amfChannel:AMFChannel = new AMFChannel("my-amf", + "http://localhost:8080/baguajie-web/messagebroker/amf"); + cs.addChannel(amfChannel); + adminRO.channelSet = cs; + } + + private function resultHandler(event:ResultEvent):void{ + event.token.resultHandler(event); + } + + private function faultHandler(event:FaultEvent):void{ + event.token.faultHandler(event); + } + } +} \ No newline at end of file diff --git a/baguajie-admin/src/net/baguajie/admin/util/ErrorHandleUtil.as b/baguajie-admin/src/net/baguajie/admin/util/ErrorHandleUtil.as new file mode 100644 index 0000000..80f68d3 --- /dev/null +++ b/baguajie-admin/src/net/baguajie/admin/util/ErrorHandleUtil.as @@ -0,0 +1,41 @@ +package net.baguajie.admin.util +{ + import mx.collections.ArrayCollection; + import mx.controls.Alert; + import mx.utils.ObjectUtil; + + import net.baguajie.admin.controller.ROResult; + + public class ErrorHandleUtil { + public static const FATAL_INT_ERROR:String = "FATAL_INT_ERROR"; + + public static function checkErrorForRemoteObject(result:Object) : Boolean { + var value:Object = {}; + if (result == null) { + return false; + } + var resultRO:ROResult; + try { + if (result is ROResult) { + resultRO = ROResult(result); + return checkROResult(resultRO); + } + else { + return false; + } + } catch (error:Error) { + Alert.show(error.message, error.name); + return false; + } + return true; + } + + public static function checkROResult(resultRO:ROResult) : Boolean { + if(resultRO.errorCode) { + return false; + } + return true; + } + + } +} \ No newline at end of file diff --git a/baguajie-admin/src/net/baguajie/admin/util/ObjectCopyUtil.as b/baguajie-admin/src/net/baguajie/admin/util/ObjectCopyUtil.as new file mode 100644 index 0000000..3e2aef7 --- /dev/null +++ b/baguajie-admin/src/net/baguajie/admin/util/ObjectCopyUtil.as @@ -0,0 +1,270 @@ +package net.baguajie.admin.util +{ + import mx.collections.IList; + import mx.utils.ObjectUtil; + + public class ObjectCopyUtil + { + /** + * Copy the values from the source obj into the destination obj. They must be the save type! + */ + private static const copyPropsOption:Object = {includeReadOnly: false, includeTransient: false}; + private static var classProperties:Array; + private static var classField:Object; + public static function copyProperties(source:Object, destination:Object):void + { + classProperties = ObjectUtil.getClassInfo(source, null, copyPropsOption).properties; + for each (classField in classProperties) + { + destination[classField] = source[classField]; + } + } + + public static function mergeUpdateArray(updateList:IList, baseArray:Array, keyProperty:Object):void + { + if(!updateList) + return; + updateList = IList(ObjectUtil.copy(updateList)); + for (var i:int = baseArray.length - 1; i >= 0; i--) + { + var baseItem:Object = baseArray[i]; + for (var j:int = updateList.length - 1; j >= 0; j--) + { + var updateItem:Object = updateList.getItemAt(j); + if (baseItem[keyProperty] === updateItem[keyProperty]) + { + // baseList.setItemAt(updateItem, i); + copyProperties(updateItem, baseItem); + updateList.removeItemAt(j); + break; + } + } + } + + if (updateList.length > 0) + { + var n:int = updateList.length; + for (var k:int = 0; k < n; k++) + { + baseArray.push(updateList.getItemAt(k)); + } + } + } + + public static function mergeUpdateList(updateList:IList, baseList:IList, keyProperty:Object):void + { + if(!updateList) + return; + updateList = IList(ObjectUtil.copy(updateList)); + for (var i:int = baseList.length - 1; i >= 0; i--) + { + var baseItem:Object = baseList.getItemAt(i); + for (var j:int = updateList.length - 1; j >= 0; j--) + { + var updateItem:Object = updateList.getItemAt(j); + if (baseItem[keyProperty] === updateItem[keyProperty]) + { + copyProperties(updateItem, baseItem); + updateList.removeItemAt(j); + break; + } + } + } + + if (updateList.length > 0) + { + var n:int = updateList.length; + for (var k:int = 0; k < n; k++) + { + baseList.addItem(updateList.getItemAt(k)); + } + } + } + + public static function mergeRemoveList(toBeRemovedList:IList, baseList:IList, keyProperty:Object):void + { + if(!toBeRemovedList) + return; + toBeRemovedList = IList(ObjectUtil.copy(toBeRemovedList)); + for(var i:int = baseList.length - 1; i>=0; i--) + { + var baseItem:Object = baseList.getItemAt(i); + for (var j:int = toBeRemovedList.length - 1; j >= 0; j--) + { + var toBeRemovedItem:Object = toBeRemovedList.getItemAt(j); + if (baseItem[keyProperty] === toBeRemovedItem[keyProperty]) + { + baseList.removeItemAt(i); + toBeRemovedList.removeItemAt(j); + break; + } + } + } + } + + public static function buildAvailableList(existedList:IList, baseList:IList, keyProperty:Object):void + { + existedList = IList(ObjectUtil.copy(existedList)); + for(var i:int = baseList.length -1; i>=0; i--) + { + var baseItem:Object = baseList.getItemAt(i); + for(var j:int = existedList.length - 1; j >=0; j--) + { + var existedItem:Object = existedList.getItemAt(j); + if (baseItem[keyProperty] === existedItem[keyProperty]) + { + baseList.removeItemAt(i); + existedList.removeItemAt(j); + break; + } + } + } + + } + + public static function buildAvailableListWithDiffKey(existedList:IList, baseList:IList, + leftKeyProperty:Object, rightKeyProperty:Object):void + { + existedList = IList(ObjectUtil.copy(existedList)); + for(var i:int = baseList.length -1; i>=0; i--) + { + var baseItem:Object = baseList.getItemAt(i); + for(var j:int = existedList.length - 1; j >=0; j--) + { + var existedItem:Object = existedList.getItemAt(j); + if (baseItem[rightKeyProperty] === existedItem[leftKeyProperty]) + { + baseList.removeItemAt(i); + existedList.removeItemAt(j); + break; + } + } + } + + } + + public static function getItemByProperty(list:IList, propertyName:String, propertyValue:Object):Object + { + var item:Object = null; + if(!propertyName && !propertyValue){ + return item; + } + for (var i:int = list.length -1; i>=0; i--) + { + var tempItem:Object = list.getItemAt(i); + if(tempItem[propertyName] == propertyValue) + { + item = tempItem; + break; + } + } + + return item; + } + + public static function getItemIndexByProperty(list:IList, item:Object, propertyName:Object=null, propertyOwning:String="all"):int + { + var index:int = -1; + if ( item == null ){ + return index; + } + for (var i:int = list.length -1; i>=0; i--){ + var tempItem:Object = list.getItemAt(i); + if(propertyName && propertyOwning=="all"){ + if(tempItem[propertyName] == item[propertyName]){ + index = i; + break; + } + }else if (propertyName && propertyOwning=="left"){ + if(tempItem[propertyName] == item){ + index = i; + break; + } + }else if (propertyName && propertyOwning=="right"){ + if(tempItem == item[propertyName]){ + index = i; + break; + } + }else if (!propertyName){ + if(tempItem == item){ + index = i; + break; + } + } + } + + return index; + } + + public static function getStrItemIndexByProperty(list:IList, item:Object, propertyName:Object=null, caseSensitive:Boolean=true, propertyOwning:String="all"):int + { + var index:int = -1; + if(!item || !(item is String)){ + return index; + } + for (var i:int = list.length -1; i>=0; i--){ + var tempItem:Object = list.getItemAt(i); + if(!propertyName && !(tempItem is String)){ + continue; + }else if (propertyName && !(tempItem[propertyName] is String)){ + continue; + } + if(propertyName && propertyOwning=="all"){ + if(caseSensitive){ + if(tempItem[propertyName] == item[propertyName]){ + index = i; + break; + } + }else{ + if(String(tempItem[propertyName]).toUpperCase() == + String(item[propertyName]).toUpperCase()){ + index = i; + break; + } + } + }else if (propertyName && propertyOwning=="left"){ + if(caseSensitive){ + if(tempItem[propertyName] == item){ + index = i; + break; + } + }else{ + if(String(tempItem[propertyName]).toUpperCase() == + String(item).toUpperCase()){ + index = i; + break; + } + } + }else if (propertyName && propertyOwning=="right"){ + if(caseSensitive){ + if(tempItem == item[propertyName]){ + index = i; + break; + } + }else{ + if(String(tempItem).toUpperCase() == + String(item[propertyName]).toUpperCase()){ + index = i; + break; + } + } + }else if (!propertyName){ + if(caseSensitive){ + if(tempItem == item){ + index = i; + break; + } + }else{ + if(String(tempItem).toUpperCase() == + String(item).toUpperCase()){ + index = i; + break; + } + } + } + } + + return index; + } + } +} \ No newline at end of file diff --git a/baguajie-admin/src/net/baguajie/admin/view/Body.mxml b/baguajie-admin/src/net/baguajie/admin/view/Body.mxml new file mode 100644 index 0000000..bb8640e --- /dev/null +++ b/baguajie-admin/src/net/baguajie/admin/view/Body.mxml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + diff --git a/baguajie-admin/src/net/baguajie/admin/view/Header.mxml b/baguajie-admin/src/net/baguajie/admin/view/Header.mxml new file mode 100644 index 0000000..19f5afb --- /dev/null +++ b/baguajie-admin/src/net/baguajie/admin/view/Header.mxml @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + diff --git a/baguajie-admin/src/net/baguajie/admin/view/LoginPanel.mxml b/baguajie-admin/src/net/baguajie/admin/view/LoginPanel.mxml new file mode 100644 index 0000000..192b4f0 --- /dev/null +++ b/baguajie-admin/src/net/baguajie/admin/view/LoginPanel.mxml @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/baguajie-admin/src/net/baguajie/admin/view/Menu.mxml b/baguajie-admin/src/net/baguajie/admin/view/Menu.mxml new file mode 100644 index 0000000..1965d1c --- /dev/null +++ b/baguajie-admin/src/net/baguajie/admin/view/Menu.mxml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + diff --git a/baguajie-admin/src/net/baguajie/admin/view/SpotDetailPopup.mxml b/baguajie-admin/src/net/baguajie/admin/view/SpotDetailPopup.mxml new file mode 100644 index 0000000..0f4ee64 --- /dev/null +++ b/baguajie-admin/src/net/baguajie/admin/view/SpotDetailPopup.mxml @@ -0,0 +1,113 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/baguajie-admin/src/net/baguajie/admin/view/SpotView.mxml b/baguajie-admin/src/net/baguajie/admin/view/SpotView.mxml new file mode 100644 index 0000000..4e6f4a1 --- /dev/null +++ b/baguajie-admin/src/net/baguajie/admin/view/SpotView.mxml @@ -0,0 +1,88 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/baguajie-admin/src/net/baguajie/admin/view/UserDetailPopup.mxml b/baguajie-admin/src/net/baguajie/admin/view/UserDetailPopup.mxml new file mode 100644 index 0000000..46356c9 --- /dev/null +++ b/baguajie-admin/src/net/baguajie/admin/view/UserDetailPopup.mxml @@ -0,0 +1,90 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/baguajie-admin/src/net/baguajie/admin/view/UserView.mxml b/baguajie-admin/src/net/baguajie/admin/view/UserView.mxml new file mode 100644 index 0000000..acdb577 --- /dev/null +++ b/baguajie-admin/src/net/baguajie/admin/view/UserView.mxml @@ -0,0 +1,81 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/baguajie-admin/src/net/baguajie/admin/viewhelper/AdminHelper.as b/baguajie-admin/src/net/baguajie/admin/viewhelper/AdminHelper.as new file mode 100644 index 0000000..76b4918 --- /dev/null +++ b/baguajie-admin/src/net/baguajie/admin/viewhelper/AdminHelper.as @@ -0,0 +1,22 @@ +package net.baguajie.admin.viewhelper +{ + import com.adobe.cairngorm.view.ViewHelper; + + public class AdminHelper extends ViewHelper + { + public function AdminHelper() + { + super(); + } + + public function toLoginState():void + { + view.currentState="login"; + } + + public function toDefaultState():void + { + view.currentState="default"; + } + } +} diff --git a/baguajie-admin/src/net/baguajie/admin/viewhelper/ViewHelperDelegator.as b/baguajie-admin/src/net/baguajie/admin/viewhelper/ViewHelperDelegator.as new file mode 100644 index 0000000..dcf9ae2 --- /dev/null +++ b/baguajie-admin/src/net/baguajie/admin/viewhelper/ViewHelperDelegator.as @@ -0,0 +1,13 @@ +package net.baguajie.admin.viewhelper +{ + import com.adobe.cairngorm.view.ViewLocator; + + public class ViewHelperDelegator + { + public static function getAdminHelper():AdminHelper + { + var adminHelper:AdminHelper=ViewLocator.getInstance().getViewHelper("adminHelper") as AdminHelper; + return adminHelper; + } + } +} diff --git a/baguajie-admin/src/net/baguajie/admin/vo/ErrorCodeVo.as b/baguajie-admin/src/net/baguajie/admin/vo/ErrorCodeVo.as new file mode 100644 index 0000000..ca07937 --- /dev/null +++ b/baguajie-admin/src/net/baguajie/admin/vo/ErrorCodeVo.as @@ -0,0 +1,15 @@ +package net.baguajie.admin.vo +{ + [Bindable] + [RemoteClass(alias="net.baguajie.web.ros.ErrorCode")] + public class ErrorCodeVo + { + public var code:String; + + public var severity:int; + + public var message:String; + + public var description:String; + } +} \ No newline at end of file diff --git a/baguajie-admin/src/net/baguajie/admin/vo/ResourceVo.as b/baguajie-admin/src/net/baguajie/admin/vo/ResourceVo.as new file mode 100644 index 0000000..e378e51 --- /dev/null +++ b/baguajie-admin/src/net/baguajie/admin/vo/ResourceVo.as @@ -0,0 +1,12 @@ +package net.baguajie.admin.vo +{ + [Bindable] + [RemoteClass(alias="net.baguajie.domains.Resource")] + public class ResourceVo + { + public var id:String; + public var resId:String; + public var ext:String; + public var orgSize:Array; + } +} \ No newline at end of file diff --git a/baguajie-admin/src/net/baguajie/admin/vo/SpotVo.as b/baguajie-admin/src/net/baguajie/admin/vo/SpotVo.as new file mode 100644 index 0000000..e716205 --- /dev/null +++ b/baguajie-admin/src/net/baguajie/admin/vo/SpotVo.as @@ -0,0 +1,26 @@ +package net.baguajie.admin.vo +{ + [Bindable] + [RemoteClass(alias="net.baguajie.domains.Spot")] + public class SpotVo + { + public static const VALID:String = "VALID"; + public static const INVALID:String = "INVALID"; + + public var id:String; + public var image:ResourceVo; + public var name:String; + public var summary:String; + public var lngLat:Array; + public var createdAt:Date; + public var createdBy:UserVo; + public var updatedAt:UserVo; + public var city:String; + public var category:String; + public var trackedCount:int; + public var forwardedCount:int; + public var commentedCount:int; + public var sharedCount:int; + public var status:String; + } +} \ No newline at end of file diff --git a/baguajie-admin/src/net/baguajie/admin/vo/UserVo.as b/baguajie-admin/src/net/baguajie/admin/vo/UserVo.as new file mode 100644 index 0000000..b1cc629 --- /dev/null +++ b/baguajie-admin/src/net/baguajie/admin/vo/UserVo.as @@ -0,0 +1,17 @@ +package net.baguajie.admin.vo +{ + [Bindable] + [RemoteClass(alias="net.baguajie.domains.User")] + public class UserVo + { + public static const VALID:String = "VALID"; + public static const INVALID:String = "INVALID"; + + public var id:String; + public var name:String; + public var email:String; + public var gender:String; + public var status:String; + public var createdAt:Date; + } +} \ No newline at end of file diff --git a/baguajie-admin/src/styles.css b/baguajie-admin/src/styles.css new file mode 100644 index 0000000..fea47e7 --- /dev/null +++ b/baguajie-admin/src/styles.css @@ -0,0 +1,21 @@ +/* CSS file */ +.menuBarStyle { + fontFamily: "Verdana, Arial, Helvetica, sans-serif"; + fontSize: 12; + fontWeight: bold; + color: #FFFFFF; + textRollOverColor: #003589; + disabledColor: #003589; + fontStyle: normal; + textAlign: left; + cornerRadius: 0; + paddingTop: 0; + paddingLeft: 5; + paddingRight: 5; + paddingBottom: 0; + kerning: true; + upSkin: Embed(source="assets/menuBar_selectedSkin.gif"); + overSkin: Embed(source="assets/menuBar_blankSkin.png"); + downSkin: Embed(source="assets/menuBar_selectedSkin.gif"); + disabledSkin: Embed(source="assets/menuBar_blankSkin.png"); +} \ No newline at end of file diff --git a/baguajie-web/pom.xml b/baguajie-web/pom.xml index 7526149..9390bd9 100644 --- a/baguajie-web/pom.xml +++ b/baguajie-web/pom.xml @@ -105,6 +105,11 @@ jcl-over-slf4j ${slf4j.verison} + + org.springframework.flex + spring-flex-core + 1.5.0.RELEASE + @@ -120,6 +125,11 @@ false + + Spring Flex + Spring Flex Source Repo + https://src.springsource.org/svn/spring-flex/tags/spring-flex-1.5.0.RELEASE/local-repo/ + baguajie-web diff --git a/baguajie-web/src/main/java/net/baguajie/constants/SpotStatus.java b/baguajie-web/src/main/java/net/baguajie/constants/SpotStatus.java new file mode 100644 index 0000000..053c98f --- /dev/null +++ b/baguajie-web/src/main/java/net/baguajie/constants/SpotStatus.java @@ -0,0 +1,5 @@ +package net.baguajie.constants; + +public enum SpotStatus { + VALID, INVALID +} diff --git a/baguajie-web/src/main/java/net/baguajie/constants/UserStatus.java b/baguajie-web/src/main/java/net/baguajie/constants/UserStatus.java new file mode 100644 index 0000000..c064d90 --- /dev/null +++ b/baguajie-web/src/main/java/net/baguajie/constants/UserStatus.java @@ -0,0 +1,5 @@ +package net.baguajie.constants; + +public enum UserStatus { + VALID, INVALID +} diff --git a/baguajie-web/src/main/java/net/baguajie/domains/Spot.java b/baguajie-web/src/main/java/net/baguajie/domains/Spot.java index c1a8d3f..6fba21b 100644 --- a/baguajie-web/src/main/java/net/baguajie/domains/Spot.java +++ b/baguajie-web/src/main/java/net/baguajie/domains/Spot.java @@ -5,6 +5,7 @@ import javax.validation.constraints.NotNull; +import net.baguajie.constants.SpotStatus; import net.baguajie.vo.SpotCreationVo; import org.apache.commons.lang.builder.EqualsBuilder; @@ -46,6 +47,7 @@ public class Spot implements Serializable { private int forwardedCount; private int commentedCount; private int sharedCount; + private SpotStatus status; public String getId() { return id; @@ -137,6 +139,12 @@ public int getSharedCount() { public void setSharedCount(int sharedCount) { this.sharedCount = sharedCount; } + public SpotStatus getStatus() { + return status; + } + public void setStatus(SpotStatus status) { + this.status = status; + } @Override public int hashCode() { @@ -172,6 +180,7 @@ public static Spot from(SpotCreationVo vo, User signInUser){ spot.setCreatedBy(signInUser); spot.setCategory(vo.getCategory()); spot.setCity(vo.getCity()); + spot.setStatus(SpotStatus.VALID); return spot; } } diff --git a/baguajie-web/src/main/java/net/baguajie/domains/User.java b/baguajie-web/src/main/java/net/baguajie/domains/User.java index 7702173..1d1d8f8 100644 --- a/baguajie-web/src/main/java/net/baguajie/domains/User.java +++ b/baguajie-web/src/main/java/net/baguajie/domains/User.java @@ -7,6 +7,7 @@ import net.baguajie.constants.ApplicationConfig; import net.baguajie.constants.Gender; +import net.baguajie.constants.UserStatus; import net.baguajie.vo.SignUpUserVo; import org.apache.commons.lang.builder.EqualsBuilder; @@ -48,6 +49,7 @@ public class User implements Serializable { @NotNull private Date createdAt; private Date updatedAt; + private UserStatus status; public String getId() { return id; @@ -157,6 +159,12 @@ public Date getUpdatedAt() { public void setUpdatedAt(Date updatedAt) { this.updatedAt = updatedAt; } + public UserStatus getStatus() { + return status; + } + public void setStatus(UserStatus status) { + this.status = status; + } @Override public int hashCode() { @@ -189,6 +197,7 @@ public static User from(SignUpUserVo vo){ user.setPassword(vo.getPassword()); user.setCreatedAt(new Date()); user.setGender(Gender.UNKNOWN); + user.setStatus(UserStatus.VALID); user.setCity(ApplicationConfig.defaultCityPinyin); return user; } diff --git a/baguajie-web/src/main/java/net/baguajie/repositories/SpotRepository.java b/baguajie-web/src/main/java/net/baguajie/repositories/SpotRepository.java index 6b642ae..692de89 100644 --- a/baguajie-web/src/main/java/net/baguajie/repositories/SpotRepository.java +++ b/baguajie-web/src/main/java/net/baguajie/repositories/SpotRepository.java @@ -11,34 +11,16 @@ public interface SpotRepository extends //search api...................................................... - @Query("{ '$where': 'function() { return (?0 ? this.city== ?0 : true) && " + + @Query("{ '$where': 'function() { return this.status != \"INVALID\" && (?0 ? this.city== ?0 : true) && " + " (?1 ? this.category== ?1 : true) && (?2 ? (this.summary? this.summary.indexOf(?2)!=-1 : false) : true); } ' }") Page search(String city, String category, String summaryLike, Pageable pageable); - @Query("{ '$where': 'function() { return this.lngLat && (?0 ? this.city== ?0 : true) && " + + @Query("{ '$where': 'function() { return this.status != \"INVALID\" && this.lngLat && (?0 ? this.city== ?0 : true) && " + " (?1 ? this.category== ?1 : true) && (?2 ? (this.summary? this.summary.indexOf(?2)!=-1 : false) : true); } ' }") Page searchMarker(String city, String category, String summaryLike, Pageable pageable); - Page findByCityAndCategoryAndSummaryLike(String city, String category, - String summaryLike, Pageable pageable); - - Page findByCityAndCategory(String city, String category, - Pageable pageable); - - Page findByCityAndSummaryLike(String city, String summaryLike, - Pageable pageable); - - Page findByCategoryAndSummaryLike(String category, String summaryLike, - Pageable pageable); - - Page findByCity(String city, Pageable pageable); - - Page findByCategory(String category, Pageable pageable); - - Page findBySummaryLike(String summaryLike, Pageable pageable); - //.............................................................. @Query("{ 'createdBy': {'$ref': 'user', '$id': { '$oid': ?0 } } , 'category' : ?1 }") @@ -51,4 +33,6 @@ Page findByCreatedByAndCategory(String id, String category, @Query("{'lngLat' : { '$nearSphere' : [ ?0 , ?1] , '$maxDistance' : ?2 } }") Page findByLngLatNear(Double lng, Double lat, Double distance, Pageable pageable); + + Page findByCity(String city, Pageable pageable); } diff --git a/baguajie-web/src/main/java/net/baguajie/repositories/UserRepository.java b/baguajie-web/src/main/java/net/baguajie/repositories/UserRepository.java index af1c0d4..bdcbfc5 100644 --- a/baguajie-web/src/main/java/net/baguajie/repositories/UserRepository.java +++ b/baguajie-web/src/main/java/net/baguajie/repositories/UserRepository.java @@ -16,7 +16,7 @@ public interface UserRepository extends //search api...................................................... - @Query("{ '$where': 'function() { return (?0 ? this.city== ?0 : true) && " + + @Query("{ '$where': 'function() { return this.status != \"INVALID\" && (?0 ? this.city== ?0 : true) && " + " (?1 ? this.gender== ?1 : true) && (?2 ? (this.name? this.name.indexOf(?2)!=-1 : false) : true); } ' }") Page search(String city, String gender, String nameLike, Pageable pageable); diff --git a/baguajie-web/src/main/java/net/baguajie/web/mvc/controllers/SearchSpotsController.java b/baguajie-web/src/main/java/net/baguajie/web/mvc/controllers/SearchSpotsController.java index fd8bde4..f3dab0c 100644 --- a/baguajie-web/src/main/java/net/baguajie/web/mvc/controllers/SearchSpotsController.java +++ b/baguajie-web/src/main/java/net/baguajie/web/mvc/controllers/SearchSpotsController.java @@ -111,23 +111,6 @@ private Iterable doSearch(HttpServletRequest request, boolean isMarker){ } Iterable spots = null; -// if(StringUtils.hasText(city) && StringUtils.hasText(category) && StringUtils.hasText(summaryLike) ){ -// spots = spotRepository.findByCityAndCategoryAndSummaryLike(city, category, summaryLike, pageable); -// }else if(StringUtils.hasText(city) && StringUtils.hasText(category) && !StringUtils.hasText(summaryLike)){ -// spots = spotRepository.findByCityAndCategory(city, category, pageable); -// }else if(StringUtils.hasText(city) && !StringUtils.hasText(category) && StringUtils.hasText(summaryLike)){ -// spots = spotRepository.findByCityAndSummaryLike(city, summaryLike, pageable); -// }else if(!StringUtils.hasText(city) && StringUtils.hasText(category) && StringUtils.hasText(summaryLike)){ -// spots = spotRepository.findByCategoryAndSummaryLike(category, summaryLike, pageable); -// }else if(!StringUtils.hasText(city) && !StringUtils.hasText(category) && StringUtils.hasText(summaryLike)){ -// spots = spotRepository.findBySummaryLike(summaryLike, pageable); -// }else if(!StringUtils.hasText(city) && StringUtils.hasText(category) && !StringUtils.hasText(summaryLike)){ -// spots = spotRepository.findByCategory(category, pageable); -// }else if(StringUtils.hasText(city) && !StringUtils.hasText(category) && !StringUtils.hasText(summaryLike)){ -// spots = spotRepository.findByCity(city, pageable); -// }else{ -// spots = spotRepository.findAll(pageable); -// } if(!isMarker){ spots = spotRepository.search(StringUtils.trimWhitespace(city), StringUtils.trimWhitespace(category), diff --git a/baguajie-web/src/main/java/net/baguajie/web/mvc/controllers/SignInController.java b/baguajie-web/src/main/java/net/baguajie/web/mvc/controllers/SignInController.java index 421a35c..950e218 100644 --- a/baguajie-web/src/main/java/net/baguajie/web/mvc/controllers/SignInController.java +++ b/baguajie-web/src/main/java/net/baguajie/web/mvc/controllers/SignInController.java @@ -9,6 +9,7 @@ import net.baguajie.constants.AjaxResultCode; import net.baguajie.constants.ApplicationConstants; +import net.baguajie.constants.UserStatus; import net.baguajie.domains.User; import net.baguajie.domains.UserPreference; import net.baguajie.exceptions.ResourceNotFoundException; @@ -83,6 +84,10 @@ Object[] validateSignIn(@Valid SignInCredentialVo signInCredentialVo, result.addError(new FieldError("signInCredentialVo", "signInPassword", "密码不正确")); } + if(existed.getStatus() == UserStatus.INVALID){ + result.addError(new FieldError("signInCredentialVo", + "signInName", "账号暂时不能登陆")); + } } } if (result.hasErrors()) { @@ -117,6 +122,10 @@ public String signIn(@Valid SignInCredentialVo signInCredentialVo, result.addError(new FieldError("signInCredentialVo", "signInPassword", "密码不正确")); } + if(existed.getStatus() == UserStatus.INVALID){ + result.addError(new FieldError("signInCredentialVo", + "signInName", "账号暂时不能登陆")); + } } } @@ -135,5 +144,4 @@ public String signIn(@Valid SignInCredentialVo signInCredentialVo, return "redirect:/"; } - } diff --git a/baguajie-web/src/main/java/net/baguajie/web/mvc/interceptors/PreferenceInterceptor.java b/baguajie-web/src/main/java/net/baguajie/web/mvc/interceptors/PreferenceInterceptor.java index fd5bc80..94eec6b 100644 --- a/baguajie-web/src/main/java/net/baguajie/web/mvc/interceptors/PreferenceInterceptor.java +++ b/baguajie-web/src/main/java/net/baguajie/web/mvc/interceptors/PreferenceInterceptor.java @@ -4,6 +4,8 @@ import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; +import net.baguajie.constants.ApplicationConstants; +import net.baguajie.constants.UserStatus; import net.baguajie.domains.User; import net.baguajie.domains.UserPreference; import net.baguajie.repositories.UserPreferenceRepository; @@ -13,26 +15,29 @@ import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; public class PreferenceInterceptor extends HandlerInterceptorAdapter { - + @Autowired UserPreferenceRepository userPreferenceRepository; @Autowired private SessionUtil sessionUtil; - - public boolean preHandle(HttpServletRequest request, - HttpServletResponse response, Object handler) - throws Exception { + + public boolean preHandle(HttpServletRequest request, + HttpServletResponse response, Object handler) throws Exception { HttpSession session = request.getSession(true); User signInUser = sessionUtil.getSignInUser(session); UserPreference up = sessionUtil.getSignInUserPrefer(session); - if(signInUser!= null && up == null){ - up = userPreferenceRepository.getByUser(signInUser); - sessionUtil.setSignInUserPrefer(up, session); - }else if(signInUser == null && up == null){ - up = sessionUtil.getDefaultPrefer(); - sessionUtil.setSignInUserPrefer(up, session); - }else{ - ;//nothing + if (signInUser != null && signInUser.getStatus() == UserStatus.INVALID) { + session.removeAttribute(ApplicationConstants.SESSION_SIGNIN_USER); + } else { + if (signInUser != null && up == null) { + up = userPreferenceRepository.getByUser(signInUser); + sessionUtil.setSignInUserPrefer(up, session); + } else if (signInUser == null && up == null) { + up = sessionUtil.getDefaultPrefer(); + sessionUtil.setSignInUserPrefer(up, session); + } else { + ;// nothing + } } return true; } diff --git a/baguajie-web/src/main/java/net/baguajie/web/ros/AdminRemoteObject.java b/baguajie-web/src/main/java/net/baguajie/web/ros/AdminRemoteObject.java new file mode 100644 index 0000000..9f2cae6 --- /dev/null +++ b/baguajie-web/src/main/java/net/baguajie/web/ros/AdminRemoteObject.java @@ -0,0 +1,112 @@ +package net.baguajie.web.ros; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +import net.baguajie.constants.ApplicationConfig; +import net.baguajie.constants.SpotStatus; +import net.baguajie.constants.UserStatus; +import net.baguajie.domains.Spot; +import net.baguajie.domains.User; +import net.baguajie.repositories.SpotRepository; +import net.baguajie.repositories.UserRepository; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Sort; +import org.springframework.data.domain.Sort.Direction; +import org.springframework.data.domain.Sort.Order; +import org.springframework.flex.remoting.RemotingDestination; +import org.springframework.flex.remoting.RemotingInclude; +import org.springframework.stereotype.Component; + +@Component +@RemotingDestination("adminRO") +public class AdminRemoteObject { + + @Autowired + private SpotRepository spotRepository; + @Autowired + private UserRepository userRepository; + + @RemotingInclude + public ROResult getSpotsAtPage(int no) { + ROResult result = new ROResult(); + try { + Pageable pageable = new PageRequest(Math.max(no, 0), + ApplicationConfig.masonryPageSize, new Sort(new Order( + Direction.DESC, "createdAt"))); + Page page = spotRepository.findAll(pageable); + result.setResult(page.getContent()); + } catch (Exception e) { + result.setErrorCode(new ErrorCode(ErrorCode.BUSINESS_ERROR, + ErrorCode.ERROR, e.getMessage())); + result.addErrorMsg(e.getMessage()); + } + return result; + } + + @RemotingInclude + public ROResult getUsersAtPage(int no) { + ROResult result = new ROResult(); + try { + Pageable pageable = new PageRequest(Math.max(no, 0), + ApplicationConfig.masonryPageSize, new Sort(new Order( + Direction.DESC, "createdAt"))); + Page page = userRepository.findAll(pageable); + result.setResult(page.getContent()); + } catch (Exception e) { + result.setErrorCode(new ErrorCode(ErrorCode.BUSINESS_ERROR, + ErrorCode.ERROR, e.getMessage())); + result.addErrorMsg(e.getMessage()); + } + return result; + } + + @RemotingInclude + public ROResult updateSpotStatus(String id, SpotStatus status) + { + ROResult result = new ROResult(); + try { + Spot spot = spotRepository.findOne(id); + if(spot != null){ + spot.setStatus(status); + spot.setUpdatedAt(new Date()); + spotRepository.save(spot); + result.setResult(spot); + }else{ + throw new RuntimeException("Could not find spot with id \"" + id + "\""); + } + } catch (Exception e) { + result.setErrorCode(new ErrorCode(ErrorCode.BUSINESS_ERROR, + ErrorCode.ERROR, e.getMessage())); + result.addErrorMsg(e.getMessage()); + } + return result; + } + + @RemotingInclude + public ROResult updateUserStatus(String id, UserStatus status) + { + ROResult result = new ROResult(); + try { + User user = userRepository.findOne(id); + if(user != null){ + user.setStatus(status); + user.setUpdatedAt(new Date()); + userRepository.save(user); + result.setResult(user); + }else{ + throw new RuntimeException("Could not find user with id \"" + id + "\""); + } + } catch (Exception e) { + result.setErrorCode(new ErrorCode(ErrorCode.BUSINESS_ERROR, + ErrorCode.ERROR, e.getMessage())); + result.addErrorMsg(e.getMessage()); + } + return result; + } +} diff --git a/baguajie-web/src/main/java/net/baguajie/web/ros/ErrorCode.java b/baguajie-web/src/main/java/net/baguajie/web/ros/ErrorCode.java new file mode 100644 index 0000000..c3d7a6a --- /dev/null +++ b/baguajie-web/src/main/java/net/baguajie/web/ros/ErrorCode.java @@ -0,0 +1,55 @@ +package net.baguajie.web.ros; + +import java.io.Serializable; + +@SuppressWarnings("serial") +public class ErrorCode implements Serializable{ + + public static final String PERSISTENCE_ERROR = "001"; + public static final String BUSINESS_ERROR = "002"; + + public static final int ERROR = 1; + public static final int WARN = 2; + + private String code; + private int severity; + private String message; + private String description; + + public ErrorCode(){} + + public ErrorCode(String msg, int severity, String code) + { + this.message = msg; + this.severity = severity; + this.code = code; + } + + public String getCode() { + return code; + } + public void setCode(String code) { + this.code = code; + } + + public int getSeverity() { + return severity; + } + public void setSeverity(int severity) { + this.severity = severity; + } + + public String getMessage() { + return message; + } + public void setMessage(String message) { + this.message = message; + } + + public String getDescription() { + return description; + } + public void setDescription(String description) { + this.description = description; + } +} diff --git a/baguajie-web/src/main/java/net/baguajie/web/ros/ROResult.java b/baguajie-web/src/main/java/net/baguajie/web/ros/ROResult.java new file mode 100644 index 0000000..e7c73dc --- /dev/null +++ b/baguajie-web/src/main/java/net/baguajie/web/ros/ROResult.java @@ -0,0 +1,54 @@ +package net.baguajie.web.ros; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +@SuppressWarnings("serial") +public class ROResult implements Serializable { + + private List errors; + + private Object result; + + private ErrorCode errorCode; + + public ROResult() { + } + + public ROResult(Object res) { + result = res; + } + + public List getErrors() { + return errors; + } + + public void setErrors(List errors) { + this.errors = errors; + } + + public Object getResult() { + return result; + } + + public void setResult(Object result) { + this.result = result; + } + + public void addErrorMsg(String msg) { + if (errors == null){ + errors = new ArrayList(); + } + errors.add(msg); + } + + public ErrorCode getErrorCode() { + return errorCode; + } + + public void setErrorCode(ErrorCode errorCode) { + this.errorCode = errorCode; + } + +} diff --git a/baguajie-web/src/main/resources/applicationContext-flex.xml b/baguajie-web/src/main/resources/applicationContext-flex.xml new file mode 100644 index 0000000..7ee17fc --- /dev/null +++ b/baguajie-web/src/main/resources/applicationContext-flex.xml @@ -0,0 +1,17 @@ + + + + + + + + + \ No newline at end of file diff --git a/baguajie-web/src/main/resources/applicationContext-mvc.xml b/baguajie-web/src/main/resources/applicationContext-mvc.xml index 4154b9b..9869c42 100644 --- a/baguajie-web/src/main/resources/applicationContext-mvc.xml +++ b/baguajie-web/src/main/resources/applicationContext-mvc.xml @@ -23,6 +23,7 @@ + diff --git a/baguajie-web/src/main/resources/applicationContext.xml b/baguajie-web/src/main/resources/applicationContext.xml index 1dce0d8..6157914 100644 --- a/baguajie-web/src/main/resources/applicationContext.xml +++ b/baguajie-web/src/main/resources/applicationContext.xml @@ -61,6 +61,7 @@ + \ No newline at end of file diff --git a/baguajie-web/src/main/resources/remoting-config.xml b/baguajie-web/src/main/resources/remoting-config.xml new file mode 100644 index 0000000..6315447 --- /dev/null +++ b/baguajie-web/src/main/resources/remoting-config.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/baguajie-web/src/main/resources/services-config.xml b/baguajie-web/src/main/resources/services-config.xml new file mode 100644 index 0000000..6885204 --- /dev/null +++ b/baguajie-web/src/main/resources/services-config.xml @@ -0,0 +1,140 @@ + + + + + + + + + + + + + + + + false + + + + + + + true + 4 + + + + + + + + 5 + 1440 + 50 + 10000 + + + + + + + + + + + + true + 0 + 40000 + 125 + 5 + true + + + + + + + + + + + + false + true + 0 + 30000 + 125 + 5 + true + + + + + + + + + + + false + + + + + + + + + + [BlazeDS] + false + false + false + false + + + Endpoint.* + Service.* + Configuration + + + + + + + false + + + + + diff --git a/baguajie-web/src/main/webapp/WEB-INF/views/modal/sign.in.jsp b/baguajie-web/src/main/webapp/WEB-INF/views/modal/sign.in.jsp index 5bc0f05..d7ad87f 100644 --- a/baguajie-web/src/main/webapp/WEB-INF/views/modal/sign.in.jsp +++ b/baguajie-web/src/main/webapp/WEB-INF/views/modal/sign.in.jsp @@ -1,7 +1,7 @@ <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>