') ),
// ii = GUIUtils.getInputField(
// args['data'][attr]['type'],
// args['data'][attr]['value']);
tr.append( $('').append( GUIUtils.getTextSpan(attr)) );
tr.append( $(' | ').append(ii.input) );
if (ii.input.extra_el) tr.append( $(' | ').append(ii.input.extra_el) );
attrs2ii[attr] = ii;
table.append( tr );
}
GUIUtils.setupAndShowDialog(
[form],
function()
{
var changes = {},
keepAll = (args['keepEverything'] != undefined &&
args['keepEverything']());
for( var attr in attrs2ii )
{
var am = attrs2ii[attr];
var newVal = am['getinput'](am['input']);
if( keepAll ||
utils.jsons(newVal) != utils.jsons(am['oldVal']) )
changes[attr] = newVal;
}
return changes;
},
__TWO_BUTTONS,
args['title'],
callback);
}
else if( type == __SVG_TEXT_EDITOR )
{
if( args.tagName != 'tspan' )
{
console.warn('SVG text editing only works on "Text" VisualObjects');
return;
}
var vobj = args.parentNode,
vobjuri = vobj.getAttribute('__vobjuri'),
iconuri = __vobj2uri(vobj),
lines = [];
for( var i=0; i < vobj.children.length; i++ )
if( vobj.children[i].tagName == 'tspan' )
lines.push(vobj.children[i].textContent);
var input =
GUIUtils.getTextInput(
lines.join('\n'),
undefined,
Math.min(lines.length,__MAX_TEXTAREA_LINES) );
GUIUtils.setupAndShowDialog(
[input],
function() {return input.value;},
__TWO_BUTTONS,
'enter new text',
function(newVal)
{
DataUtils.update(
iconuri+'/'+vobjuri+'.vobject',{'textContent':newVal});
});
}
};
/* spawn a new instance of atompm... if a model is specified (as 'fname'), it is
loaded into the new instance... if a callback url is specified, critical
information about the new instance is POSTed to it
NOTE:: window.open returns a reference to the created window... however, this
reference is not always complete (e.g. body.onload has not necessarily
run its course)... for this reason, before proceeding with handling
'fname' and 'callbackURL', we poll the reference to ensure its
completion */
this.spawnClient = function (fname,callbackURL)
{
var c = window.open(window.location.href, '_blank'),
onspawn =
function()
{
if( (fname || callbackURL) &&
(c.__wid == undefined ||
c.__aswid == undefined ||
c._loadModel == undefined) )
return window.setTimeout(onspawn,250);
c.__user = __user;
if( fname )
c._loadModel(fname);
if( callbackURL )
_httpReq(
'POST',
callbackURL,
{'aswid':c.__aswid,
'cswid':c.__wid,
'fname':fname,
'host':window.location.host});
};
onspawn();
};
/* NOTE:: Automating activities
spawn a new instance of atompm... if a model is specified (as 'fname'), it is
loaded into the new instance, if a toolbar is especified (as 'tbname'), it's loaded
into the new instance, if a message is especified a popup message will show in
the instance*/
this.spawnClientOption = function (fname,tbname,option,trafo,msg)
{
var c = window.open(window.location.href, '_blank'),
onspawn =
function()
{
if( (fname|| tbname) &&
(c.__wid == undefined ||
c.__aswid == undefined ||
c._loadModel == undefined ||
c._loadToolbar == undefined) )
return window.setTimeout(onspawn,250);
c.__user = __user;
c.__name = fname;
c.__option = option;
c.__trafo = trafo;
c.__msg = msg;
if (trafo == undefined){
trafo = option
}
if( tbname ){
toolbars = tbname.split(",");
for ( var n in toolbars){
c._loadToolbar(toolbars[n]);
}
}
if( fname ){
c.__saveas = fname;
if( option.length > 2 ){
c._loadModel(fname);
}
}
};
onspawn();
};
/* initialize a headless client, i.e. a client with a proper backend but whose
socket-message handling code is user-defined
1. setup new backend csworker and subscribe to it
2. call 'onready'
3. from this point on, all incoming socket messages are dispatched to
'onchlog'
NOTE:: this code and the above comments are simplified versions of what's in
initClient() (TBI:: merge this function with initClient()??)
NOTE:: the context object gets populated with the headless client's wids and
with a pointer to a function that closes it (as 'close') */
this.spawnHeadlessClient = function (context,onready,onchlog)
{
var socket = io.connect(
window.location.hostname,
{'port':8124,'reconnect':false,'force new connection':true});
socket.on('message',
function(msg)
{
console.debug(' >>> '+utils.jsons(msg));
if( msg['statusCode'] != undefined )
{
if( msg['statusCode'] == 201 )
{
HttpUtils.httpReq(
'PUT',
'/aswSubscription?wid='+context.__wid,
undefined,
function(statusCode,resp)
{
context.__aswid = utils.jsonp(resp)['data'];
onready();
});
context.close = socket.socket.disconnect;
}
else
console.error('headless client failed to connect to back-end');
}
else
onchlog(
msg['data']['changelog'],
msg['data']['sequence#'],
msg['data']['hitchhiker']);
});
socket.on('disconnect',
function()
{
console.debug('headless client lost connection to back-end');
});
socket.on('connect',
function()
{
HttpUtils.httpReq(
'POST',
'/csworker',
undefined,
function(statusCode,resp)
{
console.debug("Connect!");
console.debug(statusCode);
console.debug(resp);
context.__wid = resp;
socket.emit(
'message',
{'method':'POST','url':'/changeListener?wid='+context.__wid});
});
});
};
/**
* Sets whether to update the window title or not
* @param changed whether or not the title has changed
*/
this.setWindowTitle = function(changed)
{
if( __saveas == undefined )
document.title =
__TITLE +' - '+
(changed ? '+ ' :'')+
'[Unnamed]';
else
document.title =
__TITLE+' - '+
(changed ? '+ ' :'')+
__saveas.match(/(.*\/){0,1}(.*)\.model/)[2]+' - '+
__saveas;
};
/**
* Displays the modal dialog
*/
this.showDialog = function()
{
var dialog = __dialog_stack[__dialog_stack.length-1],
dim_bg = $('#div_dim_bg');
dim_bg.css("display", 'inline');
dialog.css("display", 'block');
dialog.css("left", document.body.scrollLeft +
window.innerWidth/2 -
dialog.width()/2 + "px");
dialog.css("top", document.body.scrollTop +
window.innerHeight/2 -
dialog.height()/2 + "px");
__setCanvasScrolling(false);
};
/**
* Closes the modal dialog if it is currently opened (with arg js event)
* Huseyin Ergin
* HUSEYIN-ENTER
*/
this.closeDialog = function(ev)
{
if(ev!=null && ev.keyCode==13) {
$('#div_dialog_' + (__dialog_stack.length-1).toString() + " .okbutton").click();
}
__dialog_stack.pop()
var dialog = $('#div_dialog_'+__dialog_stack.length);
dialog.remove();
if (!__dialog_stack.length) {
__setCanvasScrolling(true);
$('#div_dim_bg').css("display", 'none');
BehaviorManager.setActiveBehaviourStatechart(__SC_CANVAS);
}
};
return this;
}(); |