Completed JsonYatta. Added IwcConnector
This commit is contained in:
31
dest/browser/Widgets/CollaborationWidget.xml
Normal file
31
dest/browser/Widgets/CollaborationWidget.xml
Normal file
@@ -0,0 +1,31 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Module>
|
||||
<ModulePrefs title="Video upload" description="Upload videos in Sevianno" author="Kevin Jahns, Chair of Computer Science 5, RWTH Aachen University, Germany" author_email="jahns@dbis.rwth-aachen.de" scrolling="true">
|
||||
<Require feature="dynamic-height"/>
|
||||
|
||||
</ModulePrefs>
|
||||
|
||||
<Content type="html"><![CDATA[
|
||||
<script type="application/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
|
||||
<script src="http://open-app.googlecode.com/files/openapp.js"></script>
|
||||
<script src="http://dbis.rwth-aachen.de/gadgets/lib/las/storage.js"></script>
|
||||
<script src="http://dbis.rwth-aachen.de/gadgets/iwc/lib/iwc.js"></script>
|
||||
<script src="http://dbis.rwth-aachen.de/gadgets/lib/las/lasAjaxClient.js"></script>
|
||||
<script src="../Widgets/libs/DUIClient.js"></script>
|
||||
<script src="../Frameworks/JsonIwcYatta.js"></script>
|
||||
<script>
|
||||
function init(){
|
||||
window.createIwcConnector(function(Connector){
|
||||
console.log("initializing..");
|
||||
yatta = new window.JsonYatta(1, Connector);
|
||||
var dui = yatta.getConnector().duiClient
|
||||
dui.getAppState()
|
||||
console.log("initialized!");
|
||||
|
||||
})
|
||||
}
|
||||
$(document).ready(init)
|
||||
</script>
|
||||
<h1> awesomewidget </h1>
|
||||
]]></Content>
|
||||
</Module>
|
||||
32
dest/browser/Widgets/CollaborationWidget2.xml
Normal file
32
dest/browser/Widgets/CollaborationWidget2.xml
Normal file
@@ -0,0 +1,32 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Module>
|
||||
<ModulePrefs title="Video upload" description="Upload videos in Sevianno" author="Kevin Jahns, Chair of Computer Science 5, RWTH Aachen University, Germany" author_email="jahns@dbis.rwth-aachen.de" scrolling="true">
|
||||
<Require feature="dynamic-height"/>
|
||||
|
||||
</ModulePrefs>
|
||||
|
||||
<Content type="html"><![CDATA[
|
||||
<script type="application/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
|
||||
<script src="http://open-app.googlecode.com/files/openapp.js"></script>
|
||||
<script src="http://dbis.rwth-aachen.de/gadgets/lib/las/storage.js"></script>
|
||||
<script src="http://dbis.rwth-aachen.de/gadgets/iwc/lib/iwc.js"></script>
|
||||
<script src="http://dbis.rwth-aachen.de/gadgets/lib/las/lasAjaxClient.js"></script>
|
||||
<script src="../Widgets/libs/DUIClient.js"></script>
|
||||
<script src="../Frameworks/JsonIwcYatta.js"></script>
|
||||
<script>
|
||||
function init(){
|
||||
function f(){
|
||||
console.log("beginning");
|
||||
window.createIwcConnector(function(Connector){
|
||||
console.log("initializing..");
|
||||
yatta = new window.JsonYatta(2, Connector);
|
||||
console.log("initialized!");
|
||||
});
|
||||
}
|
||||
setTimeout(f, 1000)
|
||||
}
|
||||
$(document).ready(init)
|
||||
</script>
|
||||
<h1> awesomewidget </h1>
|
||||
]]></Content>
|
||||
</Module>
|
||||
241
dest/browser/Widgets/iwc-teststub.xml
Normal file
241
dest/browser/Widgets/iwc-teststub.xml
Normal file
@@ -0,0 +1,241 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<Module>
|
||||
<ModulePrefs
|
||||
title="IWC Test Stub"
|
||||
description="A widget for tracing and sending ROLE IWC intents. Recommended for developers of IWC-enabled widgets."
|
||||
author="Dominik Renzel, Chair of Computer Science 5, RWTH Aachen University, Germany"
|
||||
author_email="renzel@dbis.rwth-aachen.de"
|
||||
height="500">
|
||||
<Require feature="dynamic-height"/>
|
||||
</ModulePrefs>
|
||||
<Content type="html">
|
||||
<![CDATA[
|
||||
<style type="text/css">
|
||||
* {
|
||||
font-family: Verdana;
|
||||
font-size: 8pt;
|
||||
}
|
||||
|
||||
#accordion {
|
||||
overflow: auto;
|
||||
height: 310px;
|
||||
}
|
||||
|
||||
#pubform, .entry {
|
||||
border: 1pt solid black
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
tr td.ui-state-default{
|
||||
width: 20%;
|
||||
}
|
||||
|
||||
tr td.input, tr td.ui-widget-content {
|
||||
width: 80%;
|
||||
}
|
||||
|
||||
#pub_form tr td input {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
#pub_form tr td textarea {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
</style>
|
||||
|
||||
<link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css"/>
|
||||
|
||||
<script type="application/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
|
||||
<script type="application/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js"</script>
|
||||
|
||||
<script src="http://open-app.googlecode.com/files/openapp.js"></script>
|
||||
<script src="http://dbis.rwth-aachen.de/gadgets/iwc/lib/iwc.js"></script>
|
||||
<script src="http://dbis.rwth-aachen.de/gadgets/iwc/lib/date.js"></script>
|
||||
|
||||
<script type="text/javascript">
|
||||
|
||||
var counter = 0;
|
||||
var iwcClient = null;
|
||||
|
||||
function renderIntent(intent){
|
||||
var result = "<table class='entry'>";
|
||||
|
||||
|
||||
var sender = intent.sender;
|
||||
var publisher = "me";
|
||||
var source = sender;
|
||||
|
||||
if (sender.indexOf("?sender=") > -1){
|
||||
var ts = sender.split("?sender=");
|
||||
publisher = ts[0].split("/")[0];
|
||||
source = ts[1];
|
||||
} else {
|
||||
publisher = "<b><i>me</i></b>";
|
||||
source = sender;
|
||||
}
|
||||
|
||||
result += "<tr><td class='ui-state-default'>Publisher</td><td class='ui-widget-content'>" + publisher + "</td></tr>";
|
||||
result += "<tr><td class='ui-state-default'>Source</td><td class='ui-widget-content'>" + source + "</td></tr>";
|
||||
|
||||
|
||||
|
||||
var comp = intent.component;
|
||||
if(comp === ""){
|
||||
comp = "*";
|
||||
}
|
||||
|
||||
result += "<tr><td class='ui-state-default'>Component</td><td class='ui-widget-content,value'>" + comp + "</td></tr>";
|
||||
result += "<tr><td class='ui-state-default'>Action</td><td class='ui-widget-content'>" + intent.action + "</td></tr>";
|
||||
result += "<tr><td class='ui-state-default'>Data</td><td class='ui-widget-content'>" + intent.data + "</td></tr>";
|
||||
result += "<tr><td class='ui-state-default'>Datatype</td><td class='ui-widget-content'>" + intent.dataType + "</td></tr>";
|
||||
result += "<tr><td class='ui-state-default'>Categories</td><td class='ui-widget-content'>" + intent.categories + "</td></tr>";
|
||||
result += "<tr><td class='ui-state-default'>Flags</td><td class='ui-widget-content'>" + intent.flags + "</td></tr>";
|
||||
result += "<tr><td class='ui-state-default'>Extras</td><td class='ui-widget-content'> " + JSON.stringify(intent.extras) + "</td></tr>";
|
||||
|
||||
result += "</table>";
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
function collectIntent(){
|
||||
var action = $("#pub_action").val();
|
||||
console.log("Action: " + action);
|
||||
|
||||
var sender = $("#pub_source").val();
|
||||
if(!($("#pub_publisher").val() == 'me')){
|
||||
sender = $("#pub_publisher").val() + "?sender=" + sender;
|
||||
}
|
||||
|
||||
var categories = $("#pub_categories").val().split(",");
|
||||
var flags = $("#pub_flags").val().split(",");
|
||||
|
||||
try{
|
||||
var extras = $.parseJSON($("#pub_extras").val());
|
||||
} catch(error) {
|
||||
alert("Corrupt JSON specified for extras");
|
||||
return;
|
||||
}
|
||||
var intent = {
|
||||
"component": $("#pub_component").val(),
|
||||
"sender": sender,
|
||||
"data": $("#pub_data").val(),
|
||||
"dataType":$("#pub_datatype").val(),
|
||||
"action":$("#pub_action").val(),
|
||||
"categories":categories,
|
||||
"flags": flags,
|
||||
"extras": extras
|
||||
};
|
||||
return intent;
|
||||
}
|
||||
|
||||
function init(){
|
||||
|
||||
iwcClient = new iwc.Client();
|
||||
|
||||
var iwcCallback = function(intent) {
|
||||
var date = new Date();
|
||||
var format = "yyyy-MM-dd kk:mm:ss";
|
||||
var dates = formatDate(date,format)+"."+date.getMilliseconds();
|
||||
$('#accordion').prepend("<h3><a href='#'>#" + counter + " - " + intent.action + " (" + dates + ")</a></h3><div>" + renderIntent(intent) + "</div>").accordion('destroy').accordion();
|
||||
counter += 1;
|
||||
}
|
||||
|
||||
iwcClient.connect(iwcCallback);
|
||||
|
||||
}
|
||||
|
||||
$(function() {
|
||||
$( "#accordion" ).accordion({
|
||||
collapsible: true
|
||||
});
|
||||
|
||||
$( "#clearb" ).button().click(function() {
|
||||
counter = 0;
|
||||
$( "#accordion" ).accordion('destroy').empty().accordion();
|
||||
});
|
||||
|
||||
$( "#sendb" ).button().click(function() {
|
||||
$("#sendintent").dialog('open');
|
||||
});
|
||||
|
||||
$("#exint").dialog({
|
||||
autoOpen: false,
|
||||
heigth: 340,
|
||||
width: 350,
|
||||
modal: true
|
||||
});
|
||||
|
||||
$("#sendintent").dialog({
|
||||
autoOpen: false,
|
||||
height: 340,
|
||||
width: 350,
|
||||
modal: true,
|
||||
buttons: {
|
||||
"Send": function() {
|
||||
var intent = collectIntent();
|
||||
|
||||
console.log(intent);
|
||||
|
||||
if(iwc.util.validateIntent(intent)) {
|
||||
iwcClient.publish(intent);
|
||||
}
|
||||
else {
|
||||
alert("Intent not valid! ");
|
||||
}
|
||||
|
||||
},
|
||||
Export: function() {
|
||||
var intent = collectIntent();
|
||||
var istr = JSON.stringify(intent);
|
||||
console.log(istr);
|
||||
$("#intsnip").html(istr);
|
||||
$("#exint").dialog("open");
|
||||
},
|
||||
Cancel: function() {
|
||||
$(this).dialog('close');
|
||||
}
|
||||
},
|
||||
close: function(){
|
||||
//$(this).dialog('close');
|
||||
}
|
||||
});
|
||||
|
||||
gadgets.window.adjustHeight();
|
||||
});
|
||||
|
||||
$(document).ready(init());
|
||||
|
||||
|
||||
</script>
|
||||
<button id="sendb">Send Intent</button> <button id="clearb">Clear List</button>
|
||||
<h1>Received Intents</h1>
|
||||
<div id="accordion">
|
||||
</div>
|
||||
|
||||
<div id='sendintent' title='Send Intent'>
|
||||
<table id='pub_form'>
|
||||
<tr><td class='ui-state-default'>Publisher</td><td class='input'><input id='pub_publisher' type='text' value='me'/></td></tr>
|
||||
<tr><td class='ui-state-default'>Source</td><td class='input'><input id='pub_source' type='text' value='http://widget.org/sender.xml'/></td></tr>
|
||||
<tr><td class='ui-state-default'>Component</td><td class='input'><input id='pub_component' type='text'/></td></tr>
|
||||
<tr><td class='ui-state-default'>Action</td><td class='input'><input id='pub_action' type='text' value='ACTION_UPDATE'/></td></tr>
|
||||
<tr><td class='ui-state-default'>Data</td><td class='input'><input id='pub_data' type='text' value='http://example.org/some/data'/></td></tr>
|
||||
<tr><td class='ui-state-default'>Data Type</td><td class='input'><input id='pub_datatype' type='text' value='text/plain'/></td></tr>
|
||||
<tr><td class='ui-state-default'>Flags</td><td class='input'><input id='pub_flags' type='text' value='PUBLISH_GLOBAL'/></td></tr>
|
||||
<tr><td class='ui-state-default'>Categories</td><td class='input'><input id='pub_categories' type='text' value='cat1,cat2'/></td></tr>
|
||||
<!-- <tr><td class='ui-state-default'>Extras</td><td class='input'><input id='pub_extras' type='text' value='{"key":"value"}'/></td></tr> -->
|
||||
<tr><td class='ui-state-default'>Extras</td><td class='input'><textarea id='pub_extras' value='{"key":"value"}'/></td></tr>
|
||||
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div id="exint" title="Exported Intent JSON">
|
||||
Copy the snippet below to your code to specify a respective intent message.
|
||||
<p id="intsnip"></p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
]]>
|
||||
</Content>
|
||||
</Module>
|
||||
368
dest/browser/Widgets/libs/DUIClient.js
Normal file
368
dest/browser/Widgets/libs/DUIClient.js
Normal file
@@ -0,0 +1,368 @@
|
||||
//get the iwc.Client class def.
|
||||
/*
|
||||
iwc = iwc || {};
|
||||
iwc.Client = iwc.Client || {};
|
||||
|
||||
/**
|
||||
* Add a function to set the compnent name of the iwc.Client class.<br/>
|
||||
* This component name is for filtering incoming intent at the iwc.Client. The intent can be further processed
|
||||
* only when the intent.component attribute matches the component name of the iwc.Client or the intent.component is an empty string(pseudo broadcast).
|
||||
* @param componentName The component name
|
||||
*/
|
||||
/*
|
||||
iwc.Client.prototype.setComponentName = function(componentName){
|
||||
this._componentName = componentName;
|
||||
};
|
||||
*/
|
||||
|
||||
DUIClient = function(){
|
||||
//in role framework the parent div of the widget ifr is IDed as "widget-{widgetId}-body" sth. like this
|
||||
var _widgetId = parent.document.getElementById(self.frameElement.id).parentNode.id.split("-")[1];
|
||||
var that = this;
|
||||
var _iwcClient = new iwc.Client(["*"]);
|
||||
_iwcClient._componentName = "duiclient-"+_widgetId;
|
||||
|
||||
this.externalCallback = function(intent){};
|
||||
|
||||
/**
|
||||
* The target function when the intent is for updating widget state request
|
||||
*/
|
||||
this._onUpdateState = function(intent){
|
||||
var isForMigration = intent.extras.isForMigration;
|
||||
if (isForMigration)
|
||||
this.finishMigration(intent);
|
||||
else
|
||||
this.updateState(intent);
|
||||
};
|
||||
|
||||
/**
|
||||
* The target function when the intent is for getting the current widget state.<br/>
|
||||
* The intent.extras object here is always a Json object.
|
||||
*/
|
||||
this._onGetWidgetState = function(intent){
|
||||
var target = null;
|
||||
var forMigration = false;
|
||||
if (intent.extras.target != null){
|
||||
target = intent.extras.target;
|
||||
forMigration = true;
|
||||
}
|
||||
var states = this.getWidgetState(forMigration);
|
||||
|
||||
var resIntent = {};
|
||||
if (forMigration)
|
||||
resIntent = {
|
||||
"action": "DUI_WS_MIG",
|
||||
"categories": ["DUI"],
|
||||
"component": "duimanager",
|
||||
"data":"",
|
||||
"dataType":"",
|
||||
"extras":{"target": target, "widgetId": _widgetId, "widgetStates": states}
|
||||
};
|
||||
else
|
||||
resIntent = {
|
||||
"action": "DUI_WS",
|
||||
"categories": ["DUI"],
|
||||
"component": intent.sender,
|
||||
"data":"",
|
||||
"dataType":"",
|
||||
"extras":{"widgetId": _widgetId, "widgetStates": states}
|
||||
};
|
||||
|
||||
_iwcClient.publish(resIntent);
|
||||
};
|
||||
|
||||
/**
|
||||
* The target function when the intent is to inform a change in the scope of the application
|
||||
*/
|
||||
this._onAppStateChange = function(intent){
|
||||
this.changeWithApp(intent);
|
||||
};
|
||||
|
||||
/**
|
||||
* The target function when the intent is to inform a migration of this widget is waiting to be taken place
|
||||
*/
|
||||
this._prepareMigration = function(intent){
|
||||
console.log("do sth before the widget is removed");
|
||||
this.prepareMigration();
|
||||
};
|
||||
|
||||
this._logOff = function(intent){
|
||||
var states = this.getWidgetState(false);
|
||||
resIntent = {
|
||||
"action": "DUI_WS_LOGOFF",
|
||||
"categories": ["DUI"],
|
||||
"component": "duimanager",
|
||||
"data":"",
|
||||
"dataType":"",
|
||||
"extras":{"widgetId": _widgetId, "widgetStates": states}
|
||||
};
|
||||
|
||||
_iwcClient.publish(resIntent);
|
||||
};
|
||||
|
||||
/**
|
||||
* The intent dispatcher and the callback function connected to the private field of iwc.Client.onIntent.<br/>
|
||||
* This function is called once an intent is received by the iwc.Client and passed the first level filter of the iwc.Client.<br/>
|
||||
* @param intent The incoming intent. Technically all intents will come, the filter of the iwc.Client class is weak...
|
||||
*/
|
||||
var _iwcCallback = function(intent){
|
||||
that.externalCallback(intent);
|
||||
//does not accept global intents(global intents are processed by normal iwc.Client, normal iwc.Proxy and DUI manager)
|
||||
//does not accept intents that are not categorized as "DUI"
|
||||
if ((typeof intent.flags != "undefined" && intent.flags.indexOf("PUBLISH_GLOBAL")!=-1)
|
||||
|| typeof intent.categories == "undefined" || intent.categories.indexOf("DUI") == -1)
|
||||
return;
|
||||
//then does not accept intents for other widgets
|
||||
//if the widget id is undefined here, this is an DUI intent from the DUI manager for all involved widget, e.g. application state changed
|
||||
var action = intent.action;
|
||||
if (typeof intent.extras.widgetId != "undefined" && intent.extras.widgetId == _widgetId){
|
||||
if (action == "DUI_UPDATE_STATE"){
|
||||
that._onUpdateState(intent);
|
||||
return;
|
||||
}
|
||||
if (action == "DUI_GET_WS"){
|
||||
that._onGetWidgetState(intent);
|
||||
return;
|
||||
}
|
||||
if (action == "DUI_PRE_MIG"){
|
||||
that._prepareMigration(intent);
|
||||
return;
|
||||
}
|
||||
}else if (typeof intent.extras.widgetId == "undefined"){
|
||||
if (action == "DUI_LOG_OFF"){
|
||||
that._logOff(intent);
|
||||
return;
|
||||
}
|
||||
if (action == "DUI_APP_CHANGE"){
|
||||
that._onAppStateChange(intent);
|
||||
return;
|
||||
}
|
||||
if (action == "DUI_REG_CLIENT"){
|
||||
that.initOK();
|
||||
return;
|
||||
}
|
||||
if (action == "DUI_AS"){
|
||||
that.onAppState(intent.extras.appStates);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
_iwcClient.connect(_iwcCallback);
|
||||
|
||||
//remember to bind(this) the function when override
|
||||
|
||||
/**
|
||||
* The function is called when the dui manager wants the widget states.<br/>
|
||||
* <strong>Notice</strong>: avoid putting complex data and data structure to the state value, the browser and Java JSON encoder and parser might cause inconsistent input and output.
|
||||
* @param isForMigration A boolean. True if special state for migration is needed otherwise not.
|
||||
* @returns an object containing the widget states, e.g. {"selectIndex":1, "phaseNum":2, "textinput":"iamatextvalueinatextinput"}
|
||||
*/
|
||||
this.getWidgetState = function(isForMigration){
|
||||
console.log("the widget collects it is state and return, overwrite it");
|
||||
var states = {};
|
||||
return states;
|
||||
};
|
||||
|
||||
/**
|
||||
* The function is called when there detected a application state change at the dui manager and the manager informs the widget about the change.<br/>
|
||||
* Override this function to apply changes to the widget according to the valuable application state changes.<br/>
|
||||
* @param intent intent The infos are in intent.extras object e.g. intent.extras = {"oldStates":{}, "newStates":{"statename":value, "state2":value2}}. the property 'oldStates' can be null if the space has not set app state ever before.
|
||||
*/
|
||||
this.changeWithApp = function(intent){
|
||||
//sample
|
||||
var oldStates = intent.extras.oldStates;
|
||||
var newStates = intent.extras.newStates;
|
||||
console.log(oldStates);
|
||||
console.log(newStates);
|
||||
console.log("the widget may need to change something following the whole app");
|
||||
};
|
||||
|
||||
/**
|
||||
* The function is called right before a migration for this widget and the widget state is already saved to the server in previous migration phases.<br/>
|
||||
* And it is the last chance to perform any moves before the widget is removed from current web page.<br/>
|
||||
* Override this method to perform state update for each different widget.<br/>
|
||||
* <strong>AND DO REMEMBER TO CALL {@link DUIClient#prepareMigDone} AT THE END OF THIS FUNCTION!</strong>
|
||||
*/
|
||||
this.prepareMigration = function(){
|
||||
//e.g. ..... just a joke....
|
||||
/*
|
||||
if (confirm("you sure to sign out?..."))
|
||||
parent.location = parent.location.protocol + "//" + parent.location.host + "/:authentication?return=&action=signout";
|
||||
console.log("the migration is at hand, the widget may need to do sth special before it is removed from the role widget container e.g. disconnect from the lasServer etc.");
|
||||
*/
|
||||
this.prepareMigDone();
|
||||
};
|
||||
|
||||
/**
|
||||
* The function is called when the dui manager asks the widget to update its states.<br/>
|
||||
* Compared to the function DUIClient.finishMigration(), this is a typical normal state update for active widget on presence.<br/>
|
||||
* This method will be called as a callback for DUIClient#requireWidgetState(); or DUIClient#initOK() when it is not a migration.
|
||||
* Override this method to perform state update for each different widget.
|
||||
* @param intent The Intent object that contains infos of required widget states, the infos are in intent.extras.widgetStates e.g. {"state1":value1,"state2":value2}.
|
||||
* The object might contain appStates as well if there is any application state, get it in intent.extras.appStates e.g. {"appstate1":value1,"appstate2":value2}.
|
||||
*/
|
||||
this.updateState = function(intent){
|
||||
var states = {};
|
||||
states = intent.extras.widgetStates;
|
||||
var appStates = intent.extras.appStates;
|
||||
console.log(states);
|
||||
if (typeof appStates != "undefined")
|
||||
console.log(appStates);
|
||||
console.log("update the widget state, widget need to overwrite it");
|
||||
};
|
||||
|
||||
/**
|
||||
* The function is called to finish the Migration and update the widget state.<br/>
|
||||
* Compared to the method DUIClient.updateState(), this method is a special widget state update for the widget that has just migrated.<br/>
|
||||
* Override this method to perform finishing moves for each different widget.
|
||||
* @param intent The Intent object that contains infos to complete the migration, the infos are in intent.extras.states e.g. {"state1":value1, "state2":value2}.
|
||||
* The object might contain appStates as well if there is any application state, get it in intent.extras.appStates e.g. {"appstate1":value1,"appstate2":value2}.
|
||||
*/
|
||||
this.finishMigration = function(intent){
|
||||
var states = {};
|
||||
states = intent.extras.widgetStates;
|
||||
var appStates = intent.extras.appStates;
|
||||
console.log(states);
|
||||
if (typeof appStates != "undefined")
|
||||
console.log(appStates);
|
||||
console.log("the migration is done, the widget may need to perform special inits before update the widget state e.g. login to the lasServer again.");
|
||||
};
|
||||
|
||||
/**
|
||||
* The function to signal the dui manager that the preparation for the migration is ready on this widget.<br/>
|
||||
* This function should be called at the end of the overwritten function {@link DUIClient#prepareMigration}<br/>
|
||||
* Do not override this method unless there is really an unstoppable reason.
|
||||
*/
|
||||
this.prepareMigDone = function(){
|
||||
//prepared and send OK response to DUIMgr
|
||||
var intent = {
|
||||
"component": "duimanager",
|
||||
"categories": ["DUI"],
|
||||
"action": "DUI_PRE_MIG_OK",
|
||||
"data": "",
|
||||
"dataType": "",
|
||||
"extras": {"widgetId": _widgetId}
|
||||
};
|
||||
_iwcClient.publish(intent);
|
||||
};
|
||||
|
||||
/**
|
||||
* The function to call the DUI manager to save the widget state on the server.<br/>
|
||||
* Do not override this method unless there is really an unstoppable reason.
|
||||
* @param states An array of widget state object {"stateName": stateValue}
|
||||
*/
|
||||
this.saveWidgetState = function(){
|
||||
var states = this.getWidgetState(false);
|
||||
var intent = {
|
||||
"action": "DUI_SAVE_WS",
|
||||
"categories": ["DUI"],
|
||||
"component": "duimanager",// the overwritten dui manager from the iwc.Proxy should have the _componentName set to "duimanager"
|
||||
"data":"",
|
||||
"dataType":"",
|
||||
"extras":{"widgetStates":states, "widgetId": _widgetId}
|
||||
};
|
||||
_iwcClient.publish(intent);
|
||||
};
|
||||
|
||||
/**
|
||||
* An open interface to send any intent
|
||||
*/
|
||||
this.sendIntent = function(intent){
|
||||
//or to send the intent to "duimanager"
|
||||
_iwcClient.publish(intent);
|
||||
};
|
||||
|
||||
/**
|
||||
* This function asks the framework for the states stored on the server.
|
||||
* Do not override it.
|
||||
*/
|
||||
this.requireWidgetState = function(){
|
||||
var intent = {
|
||||
"action": "DUI_REQ_WS",
|
||||
"categories": ["DUI"],
|
||||
"component": "duimanager",// the overwritten dui manager from the iwc.Proxy should have the _componentName set to "duimanager"
|
||||
"data":"",
|
||||
"dataType":"",
|
||||
"extras":{"widgetId": _widgetId}
|
||||
};
|
||||
_iwcClient.publish(intent);
|
||||
};
|
||||
|
||||
/**
|
||||
* Store the global app state
|
||||
* @param states the app state to be stored e.g. {"state1":value1, "state2":value2}
|
||||
*/
|
||||
this.setAppState = function(states){
|
||||
var intent = {
|
||||
"action": "DUI_SET_AS",
|
||||
"categories": ["DUI"],
|
||||
"component": "duimanager",// the overwritten dui manager from the iwc.Proxy should have the _componentName set to "duimanager"
|
||||
"data":"",
|
||||
"dataType":"",
|
||||
"extras":{"states": states}
|
||||
};
|
||||
_iwcClient.publish(intent);
|
||||
};
|
||||
|
||||
/**
|
||||
* Ask the dui manager for the app state.
|
||||
*/
|
||||
this.getAppState = function(){
|
||||
var intent = {
|
||||
"action": "DUI_GET_AS",
|
||||
"categories": ["DUI"],
|
||||
"component": "duimanager",// the overwritten dui manager from the iwc.Proxy should have the _componentName set to "duimanager"
|
||||
"data":"",
|
||||
"dataType":"",
|
||||
};
|
||||
_iwcClient.publish(intent);
|
||||
};
|
||||
|
||||
/**
|
||||
* Override this function to do something when the requested app state comes.
|
||||
* @param appStates the json format of the app state:{"name1": value1, "name2": value2};
|
||||
*/
|
||||
this.onAppState = function(appStates){};
|
||||
|
||||
/**
|
||||
* call this function to register the duiclient to duimanager after all things are OK
|
||||
*/
|
||||
this.initOK = function(){
|
||||
var okIntent = {
|
||||
"action": "DUI_CLIENT_OK",
|
||||
"categories": ["DUI"],
|
||||
"component": "duimanager",// the overwritten dui manager from the iwc.Proxy should have the _componentName set to "duimanager"
|
||||
"data":"",
|
||||
"dataType":"",
|
||||
"extras":{"widgetId": _widgetId}
|
||||
};
|
||||
|
||||
_iwcClient.publish(okIntent);
|
||||
};
|
||||
|
||||
/**
|
||||
* publish the intent in the domain of the user only
|
||||
*/
|
||||
this.publishToUser = function(intent){
|
||||
var wrap = {
|
||||
"action": "DUI_PUB_USER",
|
||||
"categories": ["DUI"],
|
||||
"component": "duimanager",
|
||||
"data": JSON.stringify(intent),
|
||||
"dataType": "application/json",
|
||||
"extras": {}
|
||||
};
|
||||
_iwcClient.publish(intent);
|
||||
_iwcClient.publish(wrap);
|
||||
};
|
||||
|
||||
/**
|
||||
* register the call back function of the widget to the DUI client.
|
||||
*/
|
||||
this.connect = function(callback){
|
||||
this.externalCallback = callback;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
// reminder to myself:.... the callback funcs injected into this DUIClient need to bind()
|
||||
Reference in New Issue
Block a user