");
}
} //}}}
function monitor_instance_pos_change(notification) {// {{{
var parts = JSON.parse(notification);
if (parts['unmark']) {
$.each(parts['unmark'],function(a,b){
format_visual_remove(b,"passive")
});
}
if (parts['at']) {
$.each(parts['at'],function(a,b){
format_visual_add(b,"passive")
});
}
} // }}}
function monitor_instance_vote_add(notification) {// {{{
var parts = JSON.parse(notification);
var ctv = $("#votes");
var astr = "
Activity:
" + parts.activity + "
⇒
";
if ($("input[name=votecontinue]").is(':checked'))
astr += "
";
if ($("input[name=votestop]").is(':checked'))
astr += "
";
astr += "
";
ctv.append(astr);
format_visual_add(parts.activity,"vote")
}// }}}
function monitor_instance_vote_remove(activity,callback,value) {//{{{
var url = $("input[name=current-instance]").val();
$.ajax({
type: "PUT",
url: url + "/callbacks/" + callback,
data: ({'continue': value}),
error: report_failure
});
format_visual_remove(activity,"vote");
$('#vote_to_continue-' + activity + '-' + callback).remove();
}//}}}
function start_instance() {// {{{
var url = $("input[name=current-instance]").val();
$.ajax({
type: "PUT",
url: url + "/properties/values/state",
data: ({value: "running"}),
error: report_failure
});
}// }}}
function stop_instance() {// {{{
var url = $("input[name=current-instance]").val();
$.ajax({
type: "PUT",
url: url + "/properties/values/state",
data: ({value: "stopping"}),
error: report_failure
});
}// }}}
function get_testset() {// {{{
var url = $("input[name=current-instance]").val();
var testset = $X('');
$.ajax({
type: "GET",
url: url + "/properties/values/dataelements/",
success: function(res){
var pars = $X('');
pars.append($(res.documentElement).children());
testset.append(pars);
$.ajax({
type: "GET",
url: url + "/properties/values/handlerwrapper/",
success: function(res){
var pars = $X('' + res + '');
testset.append(pars);
$.ajax({
type: "GET",
url: url + "/properties/values/endpoints/",
success: function(res){
var pars = $X('');
pars.append($(res.documentElement).children());
testset.append(pars);
$.ajax({
type: "GET",
url: url + "/properties/values/positions/",
success: function(res){
var pars = $X('');
pars.append($(res.documentElement).children());
testset.append(pars);
$.ajax({
type: "GET",
url: url + "/properties/values/description/",
success: function(res){
testset.append($(res.documentElement));
$.ajax({
type: "GET",
url: url + "/properties/values/transformation/",
success: function(res){
var pars = $X('');
pars.append($(res.documentElement));
testset.append(pars);
var base = $("input[name=current-instance]").val().replace(/[^\/]+\/?$/,'');
var params = { mimetype: 'text/xml' };
$('#saveform').attr('action',base + 'downloadify/testset.xml?' + $.param(params));
$('#saveform input').val(testset.serializeXML());
$('#saveform').submit();
},
error: report_failure
});
},
error: report_failure
});
},
error: report_failure
});
},
error: report_failure
});
},
error: report_failure
});
},
error: report_failure
});
}// }}}
function get_svg() {// {{{
var base = $("input[name=current-instance]").val().replace(/[^\/]+\/?$/,'');
var params = { mimetype: 'image/svg+xml' };
$('#saveform').attr('action',base + 'downloadify/graph.svg?' + $.param(params));
var gc = $('#graphcanvas').clone();
$.ajax({
type: "GET",
url: "lib/wfadaptor.css",
success: function(res){
gc.prepend($X(''));
$('#saveform input').val(gc.serializeXML());
$('#saveform').submit();
}
});
}// }}}
function set_testset (testset) {// {{{
var url = $("input[name=current-instance]").val();
$.ajax({
type: "GET",
url: url + "/notifications/subscriptions/",
success: function(res){
var rcount = 0;
var values = $("subscriptions > subscription[url]",res);
var vals = [];
values.each(function(){
vals.push($(this).attr('url'));
});
load_testset_handlers(url,testset,vals);
},
error: report_failure
});
$.ajax({
type: "GET",
url: url + "/properties/values/dataelements/",
success: function(res){
var rcount = 0;
var values = $("value > *",res);
var length = values.length;
values.each(function(){
var name = this.nodeName;
$.ajax({
type: "DELETE",
url: url + "/properties/values/dataelements/" + name,
success: function(){
rcount += 1;
if (rcount == length)
load_testset_dataelements(url,testset);
},
error: report_failure
});
});
if (length == 0)
load_testset_dataelements(url,testset);
},
error: report_failure
});
$.ajax({
type: "GET",
url: url + "/properties/values/endpoints/",
success: function(res){
var rcount = 0;
var values = $("value > *",res);
var length = values.length;
values.each(function(){
var name = this.nodeName;
$.ajax({
type: "DELETE",
url: url + "/properties/values/endpoints/" + name,
success: function(){
rcount += 1;
if (rcount == length)
load_testset_endpoints(url,testset);
},
error: report_failure
});
});
if (length == 0)
load_testset_endpoints(url,testset);
},
error: report_failure
});
$.ajax({
type: "GET",
url: url + "/properties/values/positions/",
success: function(res){
var rcount = 0;
var values = $("value > *",res);
var length = values.length;
values.each(function(){
var name = this.nodeName;
$.ajax({
type: "DELETE",
url: url + "/properties/values/positions/" + name,
success: function(){
rcount += 1;
if (rcount == length)
load_testset_pos(url,testset);
},
error: report_failure
});
});
if (length == 0)
load_testset_pos(url,testset);
},
error: report_failure
});
$.ajax({
type: "GET",
url: url + "/properties/values/transformation/",
success: function(res){
var values = $("not-existing",res);
$("testset > transformation > *",testset).each(function(){
var val = "" + $(this).serializeXML() + "";
if (values.length > 0) {
$.ajax({
type: "POST",
url: url + "/properties/values/",
data: ({property: "transformation"}),
success: function() {
$.ajax({
type: "PUT",
data: ({content: val}),
url: url + "/properties/values/transformation",
success: function() {
load_testset_des(url,testset);
},
});
},
error: report_failure
});
} else {
$.ajax({
type: "PUT",
url: url + "/properties/values/transformation",
data: ({content: val}),
success: function() { load_testset_des(url,testset); },
error: report_failure
});
}
});
},
error: report_failure
});
$.ajax({
type: "PUT",
url: url + "/properties/values/handlerwrapper",
success: function() { load_testset_hw(url,testset); },
error: report_failure
});
}// }}}
function load_testsetfile() { //{{{
if (running) return;
if (typeof window.FileReader !== 'function') {
alert('FileReader not yet supportet');
return;
}
var files = $('#testsetfile').get(0).files;
var reader = new FileReader();
reader.onload = function(){
set_testset(reader.result.parseXML());
running = false;
}
reader.onerror = function(){ running = false; }
reader.onabort = function(){ running = false; }
reader.readAsText(files[0]);
} //}}}
function load_testset() {// {{{
if (running) return;
running = true;
save['dsl'] = null; // reload dsl and position under all circumstances
$('#main .tabbehind button').hide();
$('#dat_details').empty();
var name = load ? load : $("select[name=testset-names]").val();
$.ajax({
cache: false,
dataType: 'xml',
url: "testsets/" + name + ".xml",
success: function(res){
document.title = name;
set_testset(res);
}
});
running = false;
}// }}}
function load_testset_des(url,testset) {// {{{
$("testset > description",testset).each(function(){
var val = "" + $(this).serializeXML() + "";
$.ajax({
type: "PUT",
url: url + "/properties/values/description",
data: ({content: val}),
error: report_failure
});
});
} // }}}
function load_testset_hw(url,testset) {// {{{
$("testset > handlerwrapper",testset).each(function(){
var val = $(this).text();
$.ajax({
type: "PUT",
url: url + "/properties/values/handlerwrapper",
data: ({value: val}),
error: report_failure
});
});
} // }}}
function load_testset_dataelements(url,testset) {// {{{
$("testset > dataelements > *",testset).each(function(){
var val = $(this).serializeXML();
$.ajax({
type: "POST",
url: url + "/properties/values/dataelements/",
data: ({value: val}),
error: report_failure
});
});
}// }}}
function load_testset_endpoints(url,testset) {// {{{
$("testset > endpoints > *",testset).each(function(){
var val = $(this).serializeXML();
$.ajax({
type: "POST",
url: url + "/properties/values/endpoints/",
data: ({value: val}),
error: report_failure
});
});
}// }}}
function load_testset_pos(url,testset) {// {{{
$("testset > positions > *",testset).each(function(){
var val = $(this).serializeXML();
$.ajax({
type: "POST",
url: url + "/properties/values/positions/",
data: ({value: val}),
error: report_failure
});
});
}// }}}
function load_testset_handlers(url,testset,vals) {// {{{
$("testset > handlers > *",testset).each(function(){
var han = this;
var suburl = $(han).attr('url');
if ($.inArray(suburl,vals) == -1) {
var inp = "url="+encodeURIComponent(suburl);
$("*",han).each(function(){
inp += "&topic=" + $(this).attr('topic');
inp += "&" + this.nodeName + "=" + $(this).text();
});
$.ajax({
type: "POST",
url: url + "/notifications/subscriptions/",
data: inp
});
}
});
}// }}}
function format_visual_add(what,cls) {//{{{
if (node_state[what] == undefined)
node_state[what] = {};
if (node_state[what][cls] == undefined)
node_state[what][cls] = 0;
node_state[what][cls] += 1;
format_visual_set(what);
}//}}}
function format_visual_remove(what,cls) {//{{{
if (node_state[what] == undefined)
node_state[what] = {};
if (node_state[what][cls] == undefined)
node_state[what][cls] = 0;
node_state[what][cls] -= 1;
format_visual_set(what);
}//}}}
function format_visual_set(what) {//{{{
if (node_state[what] != undefined) {
if (node_state[what]['vote'] == undefined) node_state[what]['vote'] = 0;
if (node_state[what]['active'] == undefined) node_state[what]['active'] = 0;
if (node_state[what]['passive'] == undefined) node_state[what]['passive'] = 0;
var votes = node_state[what]['vote'];
var actives = node_state[what]['active'];
var passives = node_state[what]['passive'];
if (actives > 0 && votes > 0)
$('g[element-id="' + what + '"] .super .colon').each(function(a,b){
b.setAttribute('class','colon necessary');
});
else
$('g[element-id="' + what + '"] .super .colon').each(function(a,b){
b.setAttribute('class','colon');
});
if (actives > 0)
$('g[element-id="' + what + '"] .super .active').each(function(a,b){
b.setAttribute('class','active necessary');
var txt = b.childNodes[0];
txt.nodeValue = actives;
});
else
$('g[element-id="' + what + '"] .super .active').each(function(a,b){
b.setAttribute('class','active');
});
if (votes > 0)
$('g[element-id="' + what + '"] .super .vote').each(function(a,b){
b.setAttribute('class','vote necessary');
var txt = b.childNodes[0];
txt.nodeValue = votes;
});
else
$('g[element-id="' + what + '"] .super .vote').each(function(a,b){
b.setAttribute('class','vote');
});
$.each(['#activity-' + what, 'g[element-id="' + what + '"] g'],function(i,t){
$(t).each(function(a,b){
if (actives > 0) vs = 'active';
else if (votes > 0) vs = 'vote';
else if (passives > 0) vs = 'passive';
else vs = '';
b.setAttribute("class",'activities ' + vs);
});
});
}
}//}}}
function format_visual_clear() {//{{{
node_state = {};
$('.super .active').each(function(a,b){b.setAttribute("class","active");});
$('.super .passive').each(function(a,b){b.setAttribute("class","passive");});
$('.super .vote').each(function(a,b){b.setAttribute("class","vote");});
$('.super .colon').each(function(a,b){b.setAttribute("class","colon");});
$('.activities').each(function(a,b){b.setAttribute("class","activities");});
$("#votes").empty();
}//}}}
function format_visual_vote_clear() {//{{{
node_state = {};
$('.super .vote').each(function(a,b){b.setAttribute("class","vote");});
$("#votes").empty();
}//}}}
function format_code(res,skim,lnums) {// {{{
try {
res = res.replace(/&/g,'&');
res = res.replace(//g,'>');
res = res.replace(/\t/g,' ');
res = res.replace(/\t/g,' ');
res = res.replace(/\r/g,'');
res = res.replace(/\s*$/gm,'');
res = res.replace(/^(\s*\n)*/m,'');
if (res.match(/\S/)) {
if (skim) format_text_skim(res);
var m;
var l = 1;
while (m = res.match(/^ +|^(?!
" + ln + " ".repeat(m.length));
l++;
}
res = res.replace(/ /g," ");
res = res.replace(/\n$/g,"\n
");
res = res.replace(/\n|$/g,"
\n");
}
} catch(e) {
alert(e.toString());
}
return res;
}// }}}
function format_text(res) {// {{{
res = res.replace(/&/g,'&');
res = res.replace(//g,'>');
return res;
}// }}}
function format_text_skim(res) {// {{{
var l = res.match(/^ */);
l = l[0].length;
res = res.replace(new RegExp("^ {" + l + "}",'mg'),'');
return res;
}// }}}
function serialize_hash(ary) { //{{{
var xml = $X('');
$.each(ary,function(k,v) {
if (k.match(/^[a-zA-Z][a-zA-Z0-9_]*$/)) {
xml.append($X('<' + k + '>' + v + '' + k + '>'));
}
});
return xml.serializeXML();
} //}}}
function append_to_log(what,type,message) {//{{{
var d = new Date();
message = message.replace(/,\"/g,', "');
message = message.replace(/,\{/g,', {');
message = message.replace(/,\[/g,', [');
message = message.replace(/:\"/g,': "');
message = message.replace(/:\{/g,': {');
message = message.replace(/:\[/g,': [');
$("#dat_log").append("