src/it/ht/rcs/console/operations/view/targets/TargetsActionBar.mxml
<?xml version="1.0" encoding="utf-8"?>
<actionbar:ActionBar xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
xmlns:actionbar="it.ht.rcs.console.main.actionbar.*"
xmlns:view="it.ht.rcs.console.operations.view.*">
<s:Button label="{R.get('NEW_TARGET')}" click="onNewTargetClick()" enabled="{Console.currentSession.user.is_admin_targets() && section.stateManager.selectedOperation.status=='open'}"
icon="@Embed('/img/NEW/newTarget.png')" visible="{section.currentState == 'singleOperation'}"
includeInLayout="{section.currentState == 'singleOperation'}"/>
<s:Button label="{R.get('NEW_FACTORY')}" click="onNewFactoryClick()"
enabled="{Console.currentSession.user.is_tech_factories() && section.stateManager.selectedOperation.status == 'open' && LicenseManager.instance.archive == 0}"
icon="@Embed('/img/NEW/newFactory.png')"
visible="{section.currentState == 'singleOperation'}"
includeInLayout="{section.currentState == 'singleOperation'}" />
<s:Button label="{R.get('EDIT')}" click="onEditClick()"
enabled="{(Console.currentSession.user.is_admin_targets() && selectedObject != null && selectedObject is Target) || (Console.currentSession.user.is_tech_factories() && selectedObject != null && selectedObject is Agent)}"
icon="@Embed('/img/NEW/edit.png')"/>
<s:Button label="{R.get('DELETE')}" click="onDeleteClick(event)" enabled="{(Console.currentSession.user.is_admin_targets() && selectedObject != null && selectedObject is Target) || (Console.currentSession.user.is_tech_factories() && selectedObject != null && selectedObject is Agent)}"
icon="@Embed('/img/NEW/delete_32.png')"/>
<s:Button label="{R.get('CLOSE')}" click="onClose()"
enabled="{(Console.currentSession.user.is_admin_targets() && selectedObject != null && selectedObject.status == 'open' && selectedObject is Target) || (Console.currentSession.user.is_tech_factories() && selectedObject != null && selectedObject is Agent && selectedObject.status == 'open')}"
icon="@Embed('/img/NEW/lock32.png')"/>
<s:Button label="{R.get('MOVE')}"
icon="@Embed('/img/NEW/move.png')" click="moveItem(event)"
enabled="{Console.currentSession.user.is_admin_targets() && selectedObject != null && selectedObject.status=='open' && section.stateManager.selectedOperation.status=='open' && selectedObject is Target && LicenseManager.instance.archive==0}"/>
<actionbar:Separator/>
<s:Button label="{R.get('ADD_TO_DASHBOARD')}"
icon="@Embed('/img/NEW/newDashboard.png')" click="addToDashboard(event)"
enabled="{Console.currentSession.user.is_view() && selectedObject != null && selectedObject.status == 'open' && selectedObject is Target}" visible="{Console.currentSession.user.is_view()}" includeInLayout="{Console.currentSession.user.is_view()}"/>
<actionbar:Separator visible="{Console.currentSession.user.is_view()}" includeInLayout="{Console.currentSession.user.is_view()}"/>
<s:Button label="{R.get('JUMP_TO_ENTITY')}"
icon="@Embed('/img/NEW/jumpToEntity.png')"
enabled="{Console.currentSession.user.is_view_profiles() && selectedObject != null && selectedObject.status == 'open' && selectedObject is Target}" click="onJump()" />
<s:Spacer width="100%"/>
<s:ButtonBar dataProvider="{viewStack}" requireSelection="true"/>
<s:TextInput id="searchInput" keyUp="onKeyUp(event)" removedFromStage="onRemovedFromStage()"/>
<fx:Script>
<![CDATA[
import flash.utils.setTimeout;
import it.ht.rcs.console.agent.controller.AgentManager;
import it.ht.rcs.console.agent.model.Agent;
import it.ht.rcs.console.alert.model.Alert;
import it.ht.rcs.console.dashboard.controller.DashboardController;
import it.ht.rcs.console.events.SectionEvent;
import it.ht.rcs.console.monitor.controller.LicenseManager;
import it.ht.rcs.console.notifications.NotificationPopup;
import it.ht.rcs.console.operations.view.MoveItemPopup;
import it.ht.rcs.console.operations.view.OperationsSection;
import it.ht.rcs.console.operations.view.agents.FactoriesForm;
import it.ht.rcs.console.search.controller.SearchManager;
import it.ht.rcs.console.target.controller.TargetManager;
import it.ht.rcs.console.target.model.Target;
import it.ht.rcs.console.utils.AlertPopUp;
import locale.R;
import mx.core.FlexGlobals;
import mx.events.CloseEvent;
import mx.managers.PopUpManager;
[Bindable]
public var section:OperationsSection;
private function onNewTargetClick():void
{
var popup:TargetsForm = PopUpManager.createPopUp(FlexGlobals.topLevelApplication as DisplayObject, TargetsForm, true) as TargetsForm;
popup.operation = section.stateManager.selectedOperation;
popup.target = new Target(Target.defaultTarget());
popup.currentState = TargetsForm.CREATE;
popup.addEventListener(CloseEvent.CLOSE, function():void{section.stateManager.setState("singleOperation")})
PopUpManager.centerPopUp(popup);
}
private function onNewFactoryClick():void
{
var popup:FactoriesForm = PopUpManager.createPopUp(root, FactoriesForm, true) as FactoriesForm;
popup.operation = section.stateManager.selectedOperation;
popup.target = null;
popup.factory = new Agent(Agent.defaultAgent());
popup.currentState = FactoriesForm.CREATE;
popup.addEventListener(CloseEvent.CLOSE, function():void{section.stateManager.setState("singleOperation")})
PopUpManager.centerPopUp(popup);
}
private function onEditClick():void
{
if(selectedObject is Target)
{
var popup:TargetsForm = PopUpManager.createPopUp(FlexGlobals.topLevelApplication as DisplayObject, TargetsForm, true) as TargetsForm;
popup.operation = section.stateManager.selectedOperation;
popup.target = selectedObject as Target;
popup.currentState = TargetsForm.EDIT;
PopUpManager.centerPopUp(popup);
}
else if( selectedObject is Agent)
{
var popup2:FactoriesForm = PopUpManager.createPopUp(FlexGlobals.topLevelApplication as DisplayObject, FactoriesForm, true) as FactoriesForm;
popup2.operation = section.stateManager.selectedOperation;
popup2.target = section.stateManager.selectedTarget;
popup2.factory = selectedObject as Agent;
popup2.currentState = FactoriesForm.EDIT;
PopUpManager.centerPopUp(popup2);
}
}
private function onDeleteClick(event:MouseEvent):void
{
if(selectedObject is Target)
{
AlertPopUp.show(R.get('CONFIRM_TARGET_DELETION', [selectedObject.name]), R.get('CONFIRM'),
AlertPopUp.YES|AlertPopUp.NO, null,
function(e:CloseEvent):void {
if (e.detail == AlertPopUp.YES)
{
TargetManager.instance.removeItem(AlertPopUp.getData());
section.stateManager.setState("singleOperation")
}
}, null, AlertPopUp.NO,null,false,selectedObject);
}
else if( selectedObject is Agent)
{
AlertPopUp.show(R.get('CONFIRM_FACTORY_DELETION', [selectedObject.name]), R.get('CONFIRM'),
AlertPopUp.YES|AlertPopUp.NO, null,
function(e:CloseEvent):void {
if (e.detail == AlertPopUp.YES)
AgentManager.instance.delFactory(AlertPopUp.getData(), event.shiftKey);
section.stateManager.setState("singleOperation")
}, null, AlertPopUp.NO,null,false,selectedObject);
}
}
private function onClose():void
{
if(selectedObject is Target)
{
AlertPopUp.show(R.get('CONFIRM_TARGET_CLOSE', [selectedObject.name]), R.get('CONFIRM'),
AlertPopUp.YES|AlertPopUp.NO, null,
function(e:CloseEvent):void {
if (e.detail == AlertPopUp.YES)
{
TargetManager.instance.closeTarget(AlertPopUp.getData()._id);
section.stateManager.setState("singleOperation")
}
}, null, AlertPopUp.NO,null,false,selectedObject);
}
else if( selectedObject is Agent)
{
var message:String = R.get('CONFIRM_FACTORY_CLOSE', [selectedObject.name]);
AlertPopUp.show(message, R.get('CONFIRM'),
AlertPopUp.YES|AlertPopUp.NO, null,
function(e:CloseEvent):void {
if (e.detail == AlertPopUp.YES)
AlertPopUp.getData().status = 'closed';
}, null, AlertPopUp.NO,null,false,selectedObject);
}
}
private function onRemovedFromStage():void
{
searchInput.text = '';
section.stateManager.searchField = searchInput;
section.stateManager.view.refresh();
section.stateManager.tableView.refresh();
}
private function onKeyUp(event:KeyboardEvent):void
{
section.stateManager.searchField = searchInput;
section.stateManager.view.refresh();
section.stateManager.tableView.refresh();
}
private function addToDashboard(event:MouseEvent):void
{
DashboardController.instance.newDashboardItem(selectedObject._id);
NotificationPopup.showNotification(R.get('ADDED_TO_DASHBOARD', [selectedObject.name]), 2)
}
private function moveItem(event:MouseEvent):void
{
var popup:MoveItemPopup = PopUpManager.createPopUp(root, MoveItemPopup, true) as MoveItemPopup;
popup.itemToMove = selectedObject;
PopUpManager.centerPopUp(popup);
}
protected function onJump():void
{
var event:SectionEvent=new SectionEvent(SectionEvent.CHANGE_SECTION);
event.section=SectionEvent.INTELLIGENCE;
event.subsection='entity';
var target:Target=selectedObject as Target;
event.item=SearchManager.instance.getItem(target._id);
FlexGlobals.topLevelApplication.dispatchEvent(event);
}
]]>
</fx:Script>
</actionbar:ActionBar>