- dispatch events when saving notes
This commit is contained in:
parent
5082ab583d
commit
00ea34d0b0
@ -0,0 +1,14 @@
|
||||
package org.bigbluebutton.modules.notes.events
|
||||
{
|
||||
import flash.events.Event;
|
||||
|
||||
public class NotesModuleStartEvent extends Event
|
||||
{
|
||||
public static const NOTES_MODULE_START:String = "notes module start event";
|
||||
|
||||
public function NotesModuleStartEvent(bubbles:Boolean=true, cancelable:Boolean=false)
|
||||
{
|
||||
super(NOTES_MODULE_START, bubbles, cancelable);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
package org.bigbluebutton.modules.notes.events
|
||||
{
|
||||
import flash.events.Event;
|
||||
|
||||
public class NotesModuleStopEvent extends Event
|
||||
{
|
||||
public static const NOTES_MODULE_STOP:String = "notes module stop event";
|
||||
|
||||
public function NotesModuleStopEvent(bubbles:Boolean=true, cancelable:Boolean=false)
|
||||
{
|
||||
super(NOTES_MODULE_STOP, bubbles, cancelable);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package org.bigbluebutton.modules.notes.events
|
||||
{
|
||||
import flash.events.Event;
|
||||
|
||||
public class SaveNoteEvent extends Event
|
||||
{
|
||||
public static const SAVE_NOTE:String = "notes module save note event";
|
||||
|
||||
public var note:String;
|
||||
|
||||
public function SaveNoteEvent(bubbles:Boolean=true, cancelable:Boolean=false)
|
||||
{
|
||||
super(SAVE_NOTE, bubbles, cancelable);
|
||||
}
|
||||
}
|
||||
}
|
@ -26,9 +26,29 @@
|
||||
<![CDATA[
|
||||
import mx.events.FlexEvent;
|
||||
|
||||
import org.bigbluebutton.modules.notes.events.NotesModuleStartEvent;
|
||||
import org.bigbluebutton.modules.notes.events.SaveErrorEvent;
|
||||
import org.bigbluebutton.modules.notes.events.SaveNoteEvent;
|
||||
import org.bigbluebutton.modules.notes.events.SaveSuccessEvent;
|
||||
import org.bigbluebutton.modules.notes.models.NotesModel;
|
||||
import org.bigbluebutton.modules.notes.services.NotesMessageService;
|
||||
|
||||
]]>
|
||||
</mx:Script>
|
||||
|
||||
<EventHandlers type="{NotesModuleStartEvent.NOTES_MODULE_START}">
|
||||
<ObjectBuilder generator="{NotesMessageService}" cache="global" constructorArguments="{scope.dispatcher}"/>
|
||||
</EventHandlers>
|
||||
|
||||
<EventHandlers type="{SaveNoteEvent.SAVE_NOTE}">
|
||||
<MethodInvoker generator="{NotesMessageService}" method="save" arguments="{event.note}" />
|
||||
</EventHandlers>
|
||||
|
||||
<EventHandlers type="{SaveSuccessEvent.NOTE_SAVE_SUCCESS}">
|
||||
<MethodInvoker generator="{NotesMessageService}" method="saveSuccess" arguments="{event.noteID}" />
|
||||
</EventHandlers>
|
||||
|
||||
<EventHandlers type="{SaveErrorEvent.FAILED_TO_SAVE}">
|
||||
<MethodInvoker generator="{NotesMessageService}" method="saveError" arguments="{event}" />
|
||||
</EventHandlers>
|
||||
</EventMap>
|
@ -6,8 +6,5 @@ package org.bigbluebutton.modules.notes.models
|
||||
public var note:String;
|
||||
public var saved:Boolean = false;
|
||||
|
||||
public function Note()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
@ -2,7 +2,7 @@ package org.bigbluebutton.modules.notes.models
|
||||
{
|
||||
import mx.collections.ArrayCollection;
|
||||
|
||||
public class Notes
|
||||
public class NotesModel
|
||||
{
|
||||
private var _notes:ArrayCollection = new ArrayCollection();
|
||||
|
@ -1,7 +1,5 @@
|
||||
package org.bigbluebutton.modules.notes.services
|
||||
{
|
||||
import com.asfusion.mate.events.Dispatcher;
|
||||
|
||||
import flash.events.Event;
|
||||
import flash.events.HTTPStatusEvent;
|
||||
import flash.events.IEventDispatcher;
|
||||
@ -23,19 +21,19 @@ package org.bigbluebutton.modules.notes.services
|
||||
|
||||
public class NoteSaver
|
||||
{
|
||||
public var serverURL:String;
|
||||
public var dispatcher:Dispatcher;
|
||||
private var _serverURL:String;
|
||||
|
||||
private var _request:URLRequest = new URLRequest();
|
||||
private var _vars:URLVariables;
|
||||
private var _uri:String;
|
||||
private var _loader = new URLLoader();
|
||||
private var _loader:URLLoader = new URLLoader();
|
||||
private var _note:Note;
|
||||
private var _dispatcher:Dispatcher;
|
||||
private var _dispatcher:IEventDispatcher;
|
||||
|
||||
public function NoteSaver(note:Note, dispatcher:Dispatcher) {
|
||||
public function NoteSaver(note:Note, serverURL:String, dispatcher:IEventDispatcher) {
|
||||
_note = note;
|
||||
_dispatcher = dispatcher;
|
||||
_serverURL = serverURL;
|
||||
|
||||
_loader.addEventListener(Event.COMPLETE, completeHandler);
|
||||
_loader.addEventListener(Event.OPEN, openHandler);
|
||||
@ -50,12 +48,10 @@ package org.bigbluebutton.modules.notes.services
|
||||
}
|
||||
|
||||
public function save():void {
|
||||
_request.url = serverURL;
|
||||
_request.url = _serverURL;
|
||||
_request.method = URLRequestMethod.GET;
|
||||
|
||||
var date:Date = new Date();
|
||||
|
||||
_vars.noteID = generateRandomString(5) + "-" + date.time;
|
||||
_vars.noteID = _note.noteID;
|
||||
_vars.note = base64Encode(_note.note);
|
||||
_vars.eventName = UsersUtil.getExternalMeetingID();
|
||||
_vars.userId = UsersUtil.internalUserIDToExternalUserID(UsersUtil.getMyUserID());
|
||||
@ -84,8 +80,6 @@ package org.bigbluebutton.modules.notes.services
|
||||
successEvent.noteID = _note.noteID;
|
||||
_dispatcher.dispatchEvent(successEvent);
|
||||
|
||||
// var loader:URLLoader = URLLoader(event.target);
|
||||
// trace("completeHandler: " + loader.data);
|
||||
}
|
||||
|
||||
private function openHandler(event:Event):void {
|
||||
@ -116,15 +110,6 @@ package org.bigbluebutton.modules.notes.services
|
||||
_dispatcher.dispatchEvent(errorEvent);
|
||||
}
|
||||
|
||||
private function generateRandomString(strlen:Number):String{
|
||||
var chars:String = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
||||
var num_chars:Number = chars.length - 1;
|
||||
var randomChar:String = "";
|
||||
|
||||
for (var i:Number = 0; i < strlen; i++){
|
||||
randomChar += chars.charAt(Math.floor(Math.random() * num_chars));
|
||||
}
|
||||
return randomChar;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,25 +1,59 @@
|
||||
package org.bigbluebutton.modules.notes.services
|
||||
{
|
||||
import com.asfusion.mate.events.Dispatcher;
|
||||
import flash.events.IEventDispatcher;
|
||||
|
||||
import mx.collections.ArrayCollection;
|
||||
|
||||
import org.bigbluebutton.modules.notes.events.SaveErrorEvent;
|
||||
import org.bigbluebutton.modules.notes.models.Note;
|
||||
import org.bigbluebutton.modules.notes.models.NotesModel;
|
||||
import org.bigbluebutton.modules.notes.models.NotesOptions;
|
||||
|
||||
public class NotesMessageService
|
||||
{
|
||||
private var _noteSaver:ArrayCollection = new ArrayCollection();
|
||||
private var _notesModel:NotesModel = new NotesModel();
|
||||
|
||||
private var _noteSavers:ArrayCollection = new ArrayCollection();
|
||||
private var _options:NotesOptions;
|
||||
private var _dispatcher:Dispatcher;
|
||||
private var _dispatcher:IEventDispatcher;
|
||||
|
||||
public function NotesMessageService() {
|
||||
_dispatcher = new Dispatcher();
|
||||
public function NotesMessageService(dispatcher:IEventDispatcher) {
|
||||
_dispatcher = dispatcher;
|
||||
}
|
||||
|
||||
public function save(note:Note):void {
|
||||
var noteSaver:NoteSaver = new NoteSaver(note, _dispatcher);
|
||||
_noteSaver.addItem(noteSaver);
|
||||
public function save(note:String):void {
|
||||
var date:Date = new Date();
|
||||
|
||||
var n:Note = new Note();
|
||||
n.noteID = generateRandomString(5) + "-" + date.time;
|
||||
n.note = note;
|
||||
n.saved = false;
|
||||
_notesModel.addNote(n);
|
||||
|
||||
var noteSaver:NoteSaver = new NoteSaver(n, _options.saveURL, _dispatcher);
|
||||
_noteSavers.addItem(noteSaver);
|
||||
|
||||
noteSaver.save();
|
||||
|
||||
}
|
||||
|
||||
public function
|
||||
public function saveError(event:SaveErrorEvent):void {
|
||||
|
||||
}
|
||||
|
||||
public function saveSuccess(noteID:String):void {
|
||||
_notesModel.noteSaved(noteID);
|
||||
}
|
||||
|
||||
private function generateRandomString(strlen:Number):String{
|
||||
var chars:String = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
||||
var num_chars:Number = chars.length - 1;
|
||||
var randomChar:String = "";
|
||||
|
||||
for (var i:Number = 0; i < strlen; i++){
|
||||
randomChar += chars.charAt(Math.floor(Math.random() * num_chars));
|
||||
}
|
||||
return randomChar;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user