+}
+
+//////////////////// the nodelabel buttons
+var nodelabel_methods = {
+
+ // set selected mode and render visually
+ selected: function (nodelabel, flag) {
+ nodelabel.selected=flag;
+ nodelabel.attr({'font-weight': (flag ? 'bold' : 'normal')});
+ },
+
+ // toggle selected
+ click: function (event) {
+ nodelabel_methods.selected( this, ! this.selected );
+ }
+}
+
+
+//////////////////// the lease buttons
+var lease_methods = {
+
+ /* in the process of merging leases before posting to the API */
+ compare: function (lease, until_time, next_lease) {
+ return (next_lease['nodename'] == lease['nodename'] &&
+ next_lease['from_time'] == until_time &&
+ next_lease['initial'] == lease['initial'] &&
+ next_lease['current'] == lease['current']);
+ },
+
+ init_free: function (lease, unclick) {
+ lease.current="free";
+ // set color
+ lease.animate((lease.initial=="free") ? attr_lease_free_free : attr_lease_mine_free,anim_delay);
+ // keep track of the current status
+ // record action
+ lease.click (lease_methods.click_free);
+ if (unclick) lease.unclick(unclick);
+ },
+
+ // find out all the currently free leases that overlap this one
+ click_free: function (event) {
+ var scheduler = this.scheduler;
+ lease_methods.init_mine(this,lease_methods.click_free);
+ },
+
+ init_mine: function (lease, unclick) {
+ lease.current="mine";
+ lease.animate((lease.initial=="mine") ? attr_lease_mine_mine : attr_lease_free_mine,anim_delay);
+ lease.click (lease_methods.click_mine);
+ if (unclick) lease.unclick(unclick);
+ },
+
+ click_mine: function (event) {
+ var scheduler = this.scheduler;
+ // this lease was originally free but is now marked for booking
+ // we free just this lease
+ lease_methods.init_free(this, lease_methods.click_mine);
+ },
+
+
+ init_other: function (lease, slicename) {
+ lease.animate (attr_lease_other,anim_delay);
+ /* a text obj to display the name of the slice that owns that lease */
+ var otherslicelabel = paper.text (lease.attr("x")+lease.attr("width")/2,
+ // xxx
+ lease.attr("y")+lease.attr("height")/2,slicename).attr(txt_otherslice);
+ /* hide it right away */
+ otherslicelabel.hide();
+ /* record it */
+ lease.label=otherslicelabel;
+ lease.hover ( function (e) { this.label.toFront(); this.label.show(); },
+ function (e) { this.label.hide(); } );
+ },
+}
+
+function init_scheduler () {
+ // Grab the data
+ var data = [], axisx = [], axisy = [];
+ var table = $$("table#leases_data")[0];
+ // no reservable nodes - no data
+ if ( ! table) return;
+ // the nodelabels
+ table.getElementsBySelector("tbody>tr>th").each(function (cell) {
+ axisy.push(getInnerText(cell));
+ });
+ // the timeslot labels
+ table.getElementsBySelector("thead>tr>th").each(function (cell) {
+ /* [0]: timestamp -- [1]: displayable*/
+ axisx.push(getInnerText(cell).split("&"));
+ });
+ // leases - expect colspan to describe length in grains
+ // the text contents is expected to be lease_id & slicename
+ table.getElementsBySelector("tbody>tr>td").each(function (cell) {
+ var cell_data;
+ slice_attributes=getInnerText(cell).split('&');
+ // booked leases come with lease id and slice name
+ if (slice_attributes.length == 2) {
+ // leases is booked : slice_id, slice_name, duration in grains
+ cell_data=new Array (slice_attributes[0], slice_attributes[1], cell.colSpan);
+ } else {
+ cell_data = new Array ('','',cell.colSpan);
+ }
+ data.push(cell_data);
+ });
+ // sliceid & slicename : the upper-left cell
+ var slice_attributes = getInnerText(table.getElementsBySelector("thead>tr>td")[0]).split('&');
+ var sliceid=slice_attributes[0];
+ var slicename=slice_attributes[1];
+ var scheduler = new Scheduler (sliceid,slicename, axisx, axisy, data);
+ table.hide();
+ // leases_area is a <div> created by slice.php as a placeholder
+ scheduler.init ("leases_area");
+
+ var submit=$$("button#leases_submit")[0];
+ submit.onclick = function () { scheduler.submit(); }
+ var clear=$$("button#leases_clear")[0];
+ clear.onclick = function () { scheduler.clear(); }
+
+}