Name: cockpit/js/details.js 
1:
$(document).ready(function() {
2:
  $('#main .tabbehind button').hide();
3:
 
4:
  // save buttons shown or not //{{{
5:
  $('#main table.tabbar td.tab:not(.switch):not(.tabbehind)').click(function(event){
6:
    var me = $(event.target).parents('td.tab');
7:
    if ($('#state').text() != 'finished')
8:
      if (me.attr('id') == 'tabdetails') {
9:
        $('#main .tabbehind button').show();
10:
      } else {
11:
        $('#main .tabbehind button').hide();
12:
      }  
13:
  }); //}}}
14:
 
15:
  // New entry //{{{
16:
  $('#main .header button').live('click',function(){
17:
    var node = new_entry($(this).parents('div.tabbed'));
18:
    node.addClass('indent');
19:
  }); //}}}
20:
  
21:
  // Delete entries //{{{
22:
  $('#main td.del a').live('click',function(event){
23:
    var top = $(event.target).parents('div.tabbed');
24:
    remove_entry($("input",$(event.target).parents('tr')).get(0),false);
25:
    mark_main_save(top);
26:
    return false;
27:
  }); //}}}
28:
 
29:
  // Save entries //{{{
30:
  $('#main .tabbehind button').click(function(event){
31:
    save_main($(event.target).parents('div.tabbed'));
32:
  }); //}}}
33:
 
34:
  $('#dat_details input.pair_name, #dat_details input.prop_value, #dat_details textarea.prop_value, #dat_details select.prop_value, #dat_details input.pair_value').live('keyup',function(e){ mark_main_save($(e.target).parents('div.tabbed')); });
35:
  $('#dat_details select.prop_value').live('change',function(e){ mark_main_save($(e.target).parents('div.tabbed')); });
36:
});
37:
 
38:
function mark_main_save(top) { //{{{
39:
  var visid = $('table.tabbar td.tab',top).not('.switch').not('.inactive').attr('id').replace(/tab/,'');
40:
  var tab  = $('#dat_' + visid);
41:
  var details = serialize_details(tab).serializeXML();
42:
 
43:
  if (details != save[visid]) {
44:
    $('table.tabbar .tabbehind button',top).addClass('highlight');
45:
  } else {  
46:
    $('table.tabbar .tabbehind button',top).removeClass('highlight');
47:
  }
48:
} //}}}
49:
function save_main(top) { //{{{
50:
  var visid   = $('table.tabbar td.tab',top).not('.switch').not('.inactive').attr('id').replace(/tab/,'');
51:
  var tab     = $('#dat_' + visid);
52:
  var node    = graphrealization.description.get_node_by_svg_id($('input.pname_svgid').val());
53:
  var details = serialize_details(tab).serializeXML();
54:
  if (details != save[visid]) {
55:
    save[visid] = details;
56:
    $('table.tabbar .tabbehind button',top).removeClass('highlight');
57:
 
58:
    var newn = serialize_details(tab).attr('svg-id',$('input.pname_svgid').val());
59:
    if (newn.children().length == 0) {
60:
      newn.append(node.children());
61:
    }  
62:
    node.replaceWith(newn);
63:
    $('table.tabbar .tabbehind button:nth-child(2)',top).removeClass('highlight');
64:
 
65:
    save_description();
66:
  }  
67:
} //}}}
68:
 
69:
function save_description() {
70:
  var serxml = graphrealization.description.get_description();
71:
  var url = $("input[name=current-instance]").val();
72:
  $.ajax({
73:
    type: "PUT",
74:
    url: url + "/properties/values/description/",
75:
    data: ({'content': '<content>' + serxml + '</content>'}),
76:
  });
77:
}
78:
 
79:
function serialize_details(parent) { //{{{
80:
  var ele = $('input.pname_element',parent).val();
81:
  var xml = $X('<' + ele + ' xmlns="http://cpee.org/ns/description/1.0"/>');
82:
  switch(ele) {
83:
    case 'call':
84:
        xml.attr('id',$('input.pname_id').val());
85:
        xml.attr('endpoint',$('input.pname_endpoint').val());
86:
 
87:
        var para = $X('<parameters xmlns="http://cpee.org/ns/description/1.0"/>');
88:
        xml.append(para);
89:
        
90:
        if ($('input.pname_method',parent).length > 0) {
91:
          var pars = $X('<parameters xmlns="http://cpee.org/ns/description/1.0"/>');
92:
          var meth = $X('<method xmlns="http://cpee.org/ns/description/1.0"/>');
93:
              meth.text($('input.pname_method',parent).val());
94:
          var labl = $X('<label xmlns="http://cpee.org/ns/description/1.0"/>');
95:
              labl.text($('input.pname_label',parent).val());
96:
          para.append(labl);
97:
          para.append(meth);
98:
          para.append(pars);
99:
          $('tr.pair',parent).each(function(){
100:
            var nam = $('input.pair_name',this).val();
101:
            var val = $('input.pair_value',this).val();
102:
            var par = $X('<' + nam + ' xmlns="http://cpee.org/ns/description/1.0"/>');
103:
            par.text(val);
104:
            pars.append(par);
105:
          });
106:
        }
107:
 
108:
        if ($('textarea.pname_script',parent).length > 0) {
109:
          var mani = $X('<manipulate xmlns="http://cpee.org/ns/description/1.0"/>');
110:
              mani.text($('textarea.pname_script',parent).val());
111:
          xml.append(mani);
112:
        }
113:
      break;
114:
    case 'manipulate':
115:
      xml.attr('id',$('input.pname_id').val());
116:
      if ($('textarea.pname_script',parent).length > 0) {
117:
        xml.text($('textarea.pname_script',parent).val());
118:
      }
119:
      break;
120:
    case 'loop':
121:
      xml.attr($('select.pname_mode').val(),$('input.pname_condition').val());
122:
      break;
123:
    case 'choose':
124:
      xml.attr('mode',$('select.pname_mode').val());
125:
      break;
126:
    case 'alternative':
127:
      xml.attr('condition',$('input.pname_condition').val());
128:
      break;
129:
    case 'critical':
130:
      xml.attr('sid',$('input.pname_sid').val());
131:
      break;
132:
    case 'parallel':
133:
      if (parseInt($('input.pname_wait').val()) > -1) {
134:
        xml.attr('wait',$('input.pname_wait').val());
135:
      }  
136:
      break;
137:
    case 'parallel_branch':
138:
      if ($('input.pname_pass',parent).length > 0) {
139:
        xml.attr('pass',$('input.pname_pass').val());
140:
      }  
141:
      if ($('input.pname_local',parent).length > 0) {
142:
        xml.attr('local',$('input.pname_local').val());
143:
      }  
144:
      break;
145:
    // TODO group
146:
  }  
147:
 
148:
  return xml;
149:
} //}}}