src/it/ht/rcs/console/operations/view/operations/OperationsActionBar.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_OPERATION')}" click="onNewClick()" enabled="{Console.currentSession.user.is_admin_operations()}"
icon="@Embed('/img/NEW/newOperation.png')"/>
<s:Button label="{R.get('EDIT')}" click="onEditClick()"
enabled="{Console.currentSession.user.is_admin_operations() && selectedObject != null}" icon="@Embed('/img/NEW/edit.png')"/>
<s:Button label="{R.get('DELETE')}" click="onDeleteClick()"
enabled="{Console.currentSession.user.is_admin_operations() && selectedObject != null}" icon="@Embed('/img/NEW/delete_32.png')"/>
<s:Button label="{R.get('CLOSE')}" click="onClose()"
enabled="{Console.currentSession.user.is_admin_operations() && selectedObject != null && selectedObject.status == 'open'}"
icon="@Embed('/img/NEW/lock32.png')"/>
<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'}" />
<s:Spacer width="100%"/>
<s:ButtonBar dataProvider="{viewStack}" requireSelection="true"/>
<s:TextInput id="searchInput" keyUp="onKeyUp(event)" removedFromStage="onRemovedFromStage()"/>
<fx:Script>
<![CDATA[
import it.ht.rcs.console.dashboard.controller.DashboardController;
import it.ht.rcs.console.notifications.NotificationPopup;
import it.ht.rcs.console.operation.controller.OperationManager;
import it.ht.rcs.console.operation.model.Operation;
import it.ht.rcs.console.operations.view.OperationsSection;
import it.ht.rcs.console.utils.AlertPopUp;
import locale.R;
import mx.controls.Alert;
import mx.core.FlexGlobals;
import mx.events.CloseEvent;
import mx.managers.PopUpManager;
[Bindable]
public var section:OperationsSection;
private function onNewClick():void
{
var popup:OperationsForm = PopUpManager.createPopUp(FlexGlobals.topLevelApplication as DisplayObject, OperationsForm, true) as OperationsForm;
popup.operation = new Operation(Operation.defaultOperation());
popup.currentState = OperationsForm.CREATE;
PopUpManager.centerPopUp(popup);
}
private function onEditClick():void
{
var popup:OperationsForm = PopUpManager.createPopUp(FlexGlobals.topLevelApplication as DisplayObject, OperationsForm, true) as OperationsForm;
popup.operation = selectedObject as Operation;
popup.currentState = OperationsForm.EDIT;
PopUpManager.centerPopUp(popup);
}
private function onDeleteClick():void
{
AlertPopUp.show(R.get('CONFIRM_OPERATION_DELETION', [selectedObject.name]), R.get('CONFIRM'),
AlertPopUp.YES|AlertPopUp.NO, null,
function(e:CloseEvent):void {
if (e.detail == AlertPopUp.YES)
OperationManager.instance.removeItem(AlertPopUp.getData());
}, null, AlertPopUp.NO,null,false,selectedObject);
}
private function onClose():void
{
AlertPopUp.show(R.get('CONFIRM_OPERATION_CLOSE', [selectedObject.name]), R.get('CONFIRM'),
AlertPopUp.YES|AlertPopUp.NO, null,
function(e:CloseEvent):void {
if (e.detail == AlertPopUp.YES)
OperationManager.instance.closeOperation(AlertPopUp.getData()._id);
}, 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)
}
]]>
</fx:Script>
</actionbar:ActionBar>