Commit bdfebd53 authored by Romain Courteaud's avatar Romain Courteaud Committed by Jérome Perrin

Drop unused files.

parent e7e78514
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>DREAM</title>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.css">
<link rel="stylesheet" href="../css/gadget_dream.css">
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script type="text/javascript" src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<script type="text/javascript" src="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.js"></script>
<script type="text/javascript" src="../lib/jquery.ui.touch-punch.min.js"></script>
<script type="text/javascript" src="../lib/jschannel.js"></script>
<script type="text/javascript" src="../lib/renderjs.js"></script>
<script type="text/javascript" src="../lib/md5.js"></script>
<script type="text/javascript" src="../lib/jio.js"></script>
<script type="text/javascript" src="../lib/jio.localstorage.js"></script>
<script type="text/javascript" src="../lib/pubsub.js"></script>
<script type="text/javascript" src="../lib/jquery.jsPlumb-1.5.4-min.js"></script>
<script type="text/javascript" src="../lib/jquery.jsoneditor.js"></script>
<script type="text/javascript" src="../js/gadget_dream.js"></script>
</head>
<body>
<div data-role="page" class="ui-responsive-panel">
<div id="main"></div>
<div>
<textarea rows="20" cols="47" id="debug_zone" style="align:left"></textarea>
<button id="load_json">Load JSON</button>
</div>
</div>
<div data-role="page" data-url="dialog.html" id="dialog">
<div data-role="header">
<h1>Properties</h1>
</div>
<div data-role="content">
<p>XXX property editor screeen will be implemented here.</p>
<fieldset id="dialog-fieldset">
</fieldset>
<a href="#" data-role="button" data-rel="back" data-theme="b">Validate</a>
<a href="#" data-role="button" data-rel="back" data-theme="c">Deleve</a>
<a href="#" data-role="button" data-rel="back" data-theme="c">Cancel</a>
</div>
</div>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, user-scalable=no" />
<title>Nexedi ERP5 | Computers</title>
<!-- TODO: gadget mobile meta -->
<!-- TODO: schema.org? -->
<!-- TODO: all JQM widgets should have enhanced markup vs
letting JQM enhance -->
<!-- normalize -->
<link rel="stylesheet" href="../css/normalize.css">
<!-- JQM structure -->
<link rel="stylesheet" href="../css/jquery.mobile.css">
<!-- JQM extensions -->
<link rel="stylesheet" href="../css/extensions.css">
<!-- fontawesome icons -->
<link rel="stylesheet" href="../css/font-awesome.css">
<!-- JQM custom themes (slapos-white, slapos-black, slapos-active) -->
<link rel="stylesheet" href="../css/themes.css">
<!-- generic CSS -->
<link rel="stylesheet" href="../css/css.css">
<!-- Jquery, JQM, JQM extensions -->
<script src="../lib/jquery.js" type="text/javascript"></script>
<script src="../lib/jquery.mobile.js" type="text/javascript"></script>
<script src="../lib/extensions.js" type="text/javascript"></script>
<!-- renderjs -->
<script src="../lib/jschannel.js" type="text/javascript"></script>
<script src="../lib/renderjs.js" type="text/javascript"></script>
<!-- route -->
<script src="../lib/route.js" type="text/javascript"></script>
<script src="../lib/url.js" type="text/javascript"></script>
<!-- custom script -->
<!--script src="../js/erp5_loader.js" type="text/javascript"></script-->
<script src="../js/gadget_index.js" type="text/javascript"></script>
</head>
<body>
<div id="computers" data-role="page" data-theme="slapos-white">
<!-- left panel -->
<div data-role="panel" id="menu_computers" data-theme="slapos-black"
class="panel" data-position="left" data-display="push">
<div class="panel_element panel_element_first panel_header">
<!--input type="search" data-role="button" value=""
placeholder="Search" class="panel_search" /-->
<a href="#menu" class="panel-close" data-role="button"
data-iconpos="notext" data-icon="remove"
data-rel="close">Close</a>
</div>
<!--div class="panel_element">
<ul data-role="listview" class="listview" data-theme="slapos-black">
<li data-role="list-divider">Modules</li>
<li class="listview_item listview_icon">
<a href="webpages.html">
<span
class="ui-li-icon ui-li-icon-custom ui-icon-file-alt ui-icon"
>&nbsp;</span>
<h3>Webpages</h3>
<p>Generated Webpages</p>
</a>
</li>
</ul>
</div-->
<div class="panel_element">
<ul data-role="listview" class="listview" data-theme="slapos-black">
<li data-role="list-divider">Connection</li>
<li class="listview_item listview_icon">
<a href="#/login/">
<span class="ui-li-icon ui-li-icon-custom ui-icon-folder-open-alt ui-icon"
>&nbsp;</span>
<h3>Login</h3>
</a>
</li>
<li data-role="list-divider">Dream</li>
<li class="listview_item listview_icon">
<a href="#/graph/">
<span class="ui-li-icon ui-li-icon-custom ui-icon-folder-open-alt ui-icon"
>&nbsp;</span>
<h3>Graph editor</h3>
</a>
</li>
<li class="listview_item listview_icon">
<a href="#/simulation/">
<span class="ui-li-icon ui-li-icon-custom ui-icon-folder-open-alt ui-icon"
>&nbsp;</span>
<h3>Simulation</h3>
</a>
</li>
<li data-role="list-divider">General</li>
<li class="listview_item listview_icon">
<a href="#/about/">
<span class="ui-li-icon ui-li-icon-custom ui-icon-folder-open-alt ui-icon"
>&nbsp;</span>
<h3>About</h3>
</a>
</li>
<li class="listview_item listview_icon">
<a href="#/contact/">
<span class="ui-li-icon ui-li-icon-custom ui-icon-folder-open-alt ui-icon"
>&nbsp;</span>
<h3>Contact Us</h3>
</a>
</li>
<!--li class="listview_item listview_icon">
<a href="">
<span class="ui-li-icon ui-li-icon-custom ui-icon-folder-open-alt ui-icon"
>&nbsp;</span>
<h3>Software</h3>
</a>
</li>
<li class="listview_item listview_icon">
<a href="">
<span class="ui-li-icon ui-li-icon-custom ui-icon-book ui-icon"
>&nbsp;</span>
<h3>Documentation</h3>
</a>
</li>
<li class="listview_item listview_icon">
<a href=""><span
class="ui-li-icon ui-li-icon-custom ui-icon-cloud-download ui-icon"
>&nbsp;</span><h3>Download</h3></a></li>
<li class="listview_item listview_icon"><a href=""><span
class="ui-li-icon ui-li-icon-custom ui-icon-comments ui-icon"
>&nbsp;</span><h3>Forum</h3></a></li>
<li class="listview_item listview_icon"><a href=""><span
class="ui-li-icon ui-li-icon-custom ui-icon-microphone ui-icon"
>&nbsp;</span><h3>Blog</h3></a></li-->
</ul>
</div>
<div class="panel_element" data-theme="slapos-black">
<ul class="list mini">
<li><a href="http://nexedi.com/">Nexedi &copy; 2013</a></li>
</ul>
</div>
</div>
<!-- gadget header -->
<div id="headergadget" data-role="header" data-position="fixed">
<div class="wrap left">
<div data-role="controlgroup" data-type="horizontal"
class="buttongroup">
<a href="#menu_computers" data-rel="panel" data-role="button"
data-icon="reorder" class="responsive">Navigate</a>
</div>
</div>
<h1 class="ui-title"></h1>
<div class="wrap right">
<div data-role="controlgroup" data-type="horizontal"
class="buttongroup">
<a href="#/login/" data-position-to="window" data-role="button"
data-icon="user" class="responsive">Login</a>
</div>
</div>
</div>
<div id="iogadget"></div>
<!-- content -->
<div class="ui-content">
<!--table class="erp5_table" data-type="Computer">
</table-->
</div>
<!-- IO manager -->
<!-- <div id="io" class="wrap left buttongroup" data-type="horizontal" data-role="controlgroup"> -->
<!-- <div data-role="fieldcontain"> -->
<!-- <textarea name="Filename" id="io-doc" placeholder="Filename"></textarea> -->
<!-- </div> -->
<!-- <span href="" id="save-doc" data-role="button" href="#page1"> -->
<!-- Save -->
<!-- </span> -->
<!-- <span href="" id="load-doc" data-role="button" href="#page1"> -->
<!-- Load -->
<!-- </span> -->
<!-- <span href="" id="new-doc" data-role="button" href="#page1"> -->
<!-- New -->
<!-- </span> -->
<!-- </div> -->
<!-- Interactor -->
<div id="interactorgadget"></div>
<!-- footer -->
<div id="footergadget" data-role="footer" data-position="fixed">
<div data-role="navbar" class="navbar">
<!--ul>
<li>
<a href="#" data-rel="popup" data-icon="compass">Browse</a>
</li>
<li>
<a class="new_item" href="computer.html?mode=add"
data-rel="popup" data-icon="plus">
<span class="navbar_add">Add</span>/<span
class="navbar_clone">Clone</span>
</a>
</li>
<li><a class="remove_item" href="#" data-rel="popup"
data-icon="minus">Remove</a></li>
<li><a href="#" data-rel="popup" data-icon="cog">Action</a></li>
<li><a href="#" data-rel="popup"
data-icon="share">Import/Export</a></li>
</ul-->
</div>
</div>
</div>
<script type="text/javascript">
// force reload iframe in development environment
//$('#ui-content iframe').first().contentWindow.location.reload(true);
</script>
</body>
</html>
<html>
<head>
<title>IO</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="viewport" content="width=device-width, user-scalable=no" />
<!-- Jquery -->
<script src="../lib/jquery.js" type="text/javascript"></script>
<!-- renderjs -->
<script src="../lib/jschannel.js" type="text/javascript"></script>
<script src="../lib/renderjs.js" type="text/javascript"></script>
<!-- JIO -->
<script src="../lib/md5.amd.js" type="text/javascript"></script>
<script src="../lib/jio.js" type="text/javascript"></script>
<script src="../lib/complex_queries.js" type="text/javascript"></script>
<script src="../lib/localstorage.js" type="text/javascript"></script>
<script src="../js/gadget_io.js" type="text/javascript"></script>
<link rel="http://www.renderjs.org/rel/interface"
href="http://www.renderjs.org/interface/io"/>
</head>
<body>
<input type="text" name="fileName" id="svg-edit_docid" value="" placeholder="File name here">
<button id="save-doc" type="submit" class="btn btn-primary">
<i class="icon-download-alt icon-white"></i>
Save
</button>
<button id="load-doc" type="submit" class="btn btn-primary">
<i class="icon-download-alt icon-white"></i>
Load
</button>
<button id="new-doc" type="submit" class="btn btn-primary">
<i class="icon-download-alt icon-white"></i>
New document
</button>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta content="text/html;charset=utf-8" http-equiv="Content-Type"/>
<meta content="utf-8" http-equiv="encoding"/>
<title>Spreadsheet</title>
<link rel="stylesheet" type="text/css" href="../lib/jquery.sheet-2.0.0/jquery.sheet.css">
<link rel="stylesheet" type="text/css" href="../lib/jquery.sheet-2.0.0/jquery-ui/theme/jquery-ui.css">
<script src="../lib/jquery.sheet-2.0.0/jquery-1.5.2.min.js"></script>
<script src="../lib/jschannel.js"></script>
<script src="../lib/renderjs.js"></script>
<script src="../lib/jquery.sheet-2.0.0/jquery.sheet.min.js"></script>
<script src="../lib/jquery.sheet-2.0.0/parser.js"></script>
<script src="../js/gadget_jqs.js"></script>
</head>
<body>
<div class="jQuerySheet"></div>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, user-scalable=no" />
<title>Login</title>
<!-- Jquery -->
<script src="../lib/jquery.js" type="text/javascript"></script>
<!-- renderjs -->
<script src="../lib/jschannel.js" type="text/javascript"></script>
<script src="../lib/renderjs.js" type="text/javascript"></script>
<!-- custom script -->
<script src="../js/gadget_login.js" type="text/javascript"></script>
</head>
<body>
<div class="content_element">
<h2>Login</h2>
<p>Please enter your jIO localstorage username and validate.</p>
<form id="connect">
<input type="text" value="" name="username"
placeholder="jIO local username" spellcheck="false"
required autofocus="autofocus" />
<input type="submit" value="Login" data-inline="True" />
</form>
</div>
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>DREAM</title>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.css">
<link rel="stylesheet" href="../css/gadget_dream.css">
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script type="text/javascript" src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<script type="text/javascript" src="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.js"></script>
<script type="text/javascript" src="../lib/jquery.ui.touch-punch.min.js"></script>
<script type="text/javascript" src="../lib/jschannel.js"></script>
<script type="text/javascript" src="../lib/renderjs.js"></script>
<script type="text/javascript" src="../lib/md5.js"></script>
<script type="text/javascript" src="../lib/jio.js"></script>
<script type="text/javascript" src="../lib/jio.localstorage.js"></script>
<script type="text/javascript" src="../lib/pubsub.js"></script>
<script type="text/javascript" src="../lib/jquery.jsPlumb-1.5.4-min.js"></script>
<script type="text/javascript" src="../lib/jquery.jsoneditor.js"></script>
<script type="text/javascript" src="../lib/jquery.flot.js"></script>
<script type="text/javascript" src="../lib/jquery.flot.stack.js"></script>
<script type="text/javascript" src="../lib/jquery.jsoneditor.js"></script>
<script type="text/javascript" src="../js/gadget_dream.js"></script>
</head>
<body>
<div data-role="page" class="ui-responsive-panel">
<div id="main" style="display:none;"></div>
<div id="simulation">
Simulation Parameters
<div title="Configure">
<form>
<fieldset id="general-fieldset">
</fieldset>
<a id="run_simulation">Run Simulation</a>
</form>
</div>
</div>
<div id="graph_zone" style="display:none">
<div>Stations Utilization</div>
<div id="simulation_result"></div>
</div>
<div id="sidebar">
<table>
<tr>
<td>Input</td>
<td>Result</td>
</tr>
<tr>
<td>
<textarea rows="20" cols="47" id="json_output" style="align:left">
</textarea>
</td>
<td>
<textarea rows="20" cols="47" id="json_result" style="align:right">
</textarea>
</td>
</table>
</div>
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>DREAM</title>
<link rel="stylesheet" href="css/jquery-ui-1.10.3.custom.css">
<link rel="stylesheet" href="css/jquery.mobile.css">
<link rel="stylesheet" href="css/dream2.css">
<script type="text/javascript" src="lib/jquery.js"></script>
<script type="text/javascript" src="lib/jquery-ui-1.10.3.custom.js"></script>
<script type="text/javascript" src="lib/jquery.mobile.js"></script>
<script type="text/javascript" src="lib/jquery.ui.touch-punch.min.js"></script>
<script type="text/javascript" src="lib/md5.js"></script>
<script type="text/javascript" src="lib/jio.js"></script>
<script type="text/javascript" src="lib/jio.localstorage.js"></script>
<script type="text/javascript" src="lib/pubsub.js"></script>
<script type="text/javascript" src="lib/jquery.jsPlumb-1.5.4-min.js"></script>
<script type="text/javascript" src="lib/jquery.jsoneditor.js"></script>
<script type="text/javascript" src="src/dream2.js"></script>
</head>
<body>
<!--
<div class="content-secondary">
<div data-role="collapsible" data-collapsed="true" data-theme="b" data-content-theme="d">
<h3>Controls</h3>
<ul data-role="listview" data-theme="c">
<li><a href="menu-general.html">General</a></li>
<li><a href="menu-palette.html">Node</a></li>
<li><a href="menu-runsimulation.html">Run Simulation</a></li>
</ul>
</div>
</div>
-->
<div data-role="page" class="ui-responsive-panel">
<div data-role="header" data-theme="f">
<h1>DREAM</h1>
<a href="#nav-panel" data-icon="bars" data-iconpos="notext">Menu</a>
<a href="#add-form" data-icon="plus" data-iconpos="notext">Add</a>
</div>
<!-- /header -->
<div data-role="content">
<h2>Panel: Menu + form</h2>
<p>This is a typical page that has two buttons in the header bar that open panels. The left button opens a left menu with the reveal display mode. The right button opens a form in a right overlay panel.</p>
<div class="ui-grid-a">
<div class="ui-block-a"><strong>I'm Block A</strong> and text inside will wrap
<div id="main"></div>
</div>
<div class="ui-block-b"><strong>I'm Block B</strong> and text inside will wrap
<div>
<label for="node_id">Node ID:</label>
<input id="node_id" />
<label for="node_top">Node Top:</label>
<input type="range" name="node_top" id="node_top" value="" min="0" max="100" />
<label for="node_left">Node Left:</label>
<input type="range" name="node_left" id="node_left" value="" min="0" max="100" />
<button id="move_node">Move Node</button>
</div>
<div>
<textarea rows="20" cols="47" id="debug_zone" style="align:left"></textarea>
<button id="load_json">Load JSON</button>
</div>
</div>
</div>
<!-- /grid-a -->
<p>Since the panel links are in the top bar, there really isn't a need for the fixed positioning feature on the panel since you will always be scrolled to the top of the page. The fixed positioning impacts animation smoothness so it's off in this demo
(
<code>data-position-fixed="false"</code>) and the panel will scroll with the page.</p>
<p>To make this responsive, the left panel stays open and causes the page to re-flow at wider widths. This allows both the menu and page to be used together when more space is available. This behavior is controlled by CSS media queries. You can create
a custom one for a specific breakpoint or use the breakpoint preset by adding the <code> class="ui-responsive-panel"</code> to the page container.</p>
</div>
<!-- /content -->
<div data-role="panel" data-position="left" data-position-fixed="false" data-display="reveal" id="nav-panel" data-theme="a">
<!-- good style: -->
<div data-role="collapsible" data-collapsed="true" data-theme="b" data-content-theme="d">
<h3>Controls</h3>
<ul data-role="listview" data-theme="c">
<li><a href="menu-general.html">General</a>
</li>
<li><a href="menu-palette.html">Node</a>
</li>
<li><a href="menu-runsimulation.html">Run Simulation</a>
</li>
</ul>
</div>
<!-- from example: -->
<ul data-role="listview" data-theme="a" data-divider-theme="a" style="margin-top:-16px;" class="nav-search">
<li data-icon="delete" style="background-color:#111;">
<a href="#" data-rel="close">Close menu</a>
</li>
<li data-filtertext="wai-aria voiceover accessibility screen reader">
<a href="../about/accessibility.html">Accessibility</a>
</li>
<li data-filtertext="accordions collapsible set collapsible-set collapsed">
<a href="../content/content-collapsible-set.html">Accordions</a>
</li>
<li data-filtertext="ajax navigation model">
<a href="../pages/page-navmodel.html">Ajax navigation model</a>
</li>
<li data-filtertext="anatomy of page viewport">
<a href="../pages/page-anatomy.html">Anatomy of a page</a>
</li>
<li data-filtertext="events api animationComplete transition css">
<a href="../api/events.html">Animation events</a>
</li>
<li data-filtertext="listview autodivider">
<a href="../lists/lists-autodividers.html">Automatic listview dividers</a>
</li>
<li data-filtertext="button link submit cancel image reset mini buttonmarkup enable disable">
<a href="../buttons/buttons-types.html">Buttons</a>
</li>
<li data-filtertext="button icon">
<a href="../buttons/buttons-icons.html">Button icons</a>
</li>
<li data-filtertext="data-prefetch loadpage domCache data-dom-cache size clear cleanup pagehide lazyload spinner loader">
<a href="../pages/page-cache.html">Caching pages</a>
</li>
<li data-filtertext="input forms multi select checkbox checks grouped horizontal toggle legend">
<a href="../forms/checkboxes/">Checkbox</a>
</li>
<li data-filtertext="button icon">
<a href="buttons/buttons-icons.html">Button icons</a>
</li>
<li data-filtertext="data-prefetch loadpage domCache data-dom-cache size clear cleanup pagehide lazyload spinner loader">
<a href="../pages/page-cache.html">Caching pages</a>
</li>
<li data-filtertext="input forms multi select checkbox checks grouped horizontal toggle legend">
<a href="../forms/checkboxes/">Checkbox</a>
</li>
</ul>
<!-- panel content goes here -->
</div>
<!-- /panel -->
</div>
<!-- /page -->
<div data-role="page" data-url="dialog.html" id="dialog">
<div data-role="header">
<h1>Dialog</h1>
</div>
<div data-role="content">
<p>Is this an answer?</p>
</div>
</div>
</body>
</html>
/* ===========================================================================
* Copyright 2013 Nexedi SA and Contributors
*
* This file is part of DREAM.
*
* DREAM is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* DREAM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with DREAM. If not, see <http://www.gnu.org/licenses/>.
* =========================================================================== */
/*jslint indent: 2, maxlen: 80, nomen: true */
/*global window, jQuery, rJS*/
(function (window, $, rJS) {
"use strict";
$.widget("dream.grapheditor", {
options: {
node_class: "graph_node", // CSS class for nodes
node_data_key: "grapheditor_node_data", // Key to store data on nodes using $.data
// XXX is it good idea to use
// $.data ???
draggable_nodes: true // Can nodes be dragged
},
_create: function () {
this.general = {};
this.nodes = {};
this.edges = {};
if (this.options.graph) {
this.graph(this.options.graph);
}
},
destroy: function () {
this.clear();
this._destroy();
},
clear: function () {
this.general = {};
this.edges = {};
$.each(this.nodes, $.proxy(function (node_id, node) {
jsPlumb.remove(node);
delete(this["nodes"][node_id]);
}, this));
},
create_node_element: function (node_id, node_data) {
// Create an element for a node, and add it to the main element.
return $('<div>')
.uniqueId()
.addClass(this.options.node_class)
.text(node_data['name'] || node_id)
.appendTo(this.element);
},
add_node: function (node_id, node_data) {
/* add a node */
var element = this.create_node_element(node_id, node_data);
if (this.options.draggable_nodes) {
// make the node draggable
jsPlumb.draggable(element, {
containment: this.element,
stop: $.proxy(function (node_id, event) {
this.node_position(node_id, this.node_position(node_id));
this._trigger("node_moved", event, node_id);
}, this, node_id)
});
}
this.nodes[node_id] = element;
this.node_position(node_id, node_data);
this.node_data(node_id, node_data);
this._trigger('node_added', node_id);
},
create_edge_element: function (edge_id, source_node_id,
destination_node_id, edge_data) {
// Create an element for an edge
var edge_label = edge_data['name'] || "";
jsPlumb.connect({
source: this.nodes[source_node_id].attr("id"),
target: this.nodes[destination_node_id].attr("id"),
paintStyle: {
lineWidth: 1,
strokeStyle: "#000"
}, // XXX make this an option
overlays: [
["Label", {
label: edge_label
}]
]
});
},
add_edge: function (edge_id, source_node_id, destination_node_id,
edge_data) {
/* add an edge */
this.create_edge_element(edge_id, source_node_id,
destination_node_id, edge_data);
this.edges[edge_id] = [source_node_id, destination_node_id,
edge_data
];
this._trigger('edge_added', edge_id);
},
node_data: function (node_id, node_data) {
/* get or set data for a node */
var node = this.nodes[node_id];
if (node_data === undefined) {
return node.data(this.options.node_data_key);
}
this.nodes[node_id].data(this.options.node_data_key, node_data);
this._trigger("node_data_changed", node_id);
return this;
},
edge_data: function (edge_id, edge_data) {
/* get or set data for an edge */
var edge = this.edges[edge_id];
if (edge_data === undefined) {
return edge[2];
}
this.edges[edge_id] = [edge[0], edge[1], edge_data];
this._trigger("edge_data_changed", edge_id);
return this;
},
node_position: function (node_id, position) {
/* Get or set the position of a node with position given on a 0..1 scale */
var node = this.nodes[node_id],
node_position = node.position(),
element_position = this.element.position();
if (position === undefined) {
return {
"top": (node_position.top - element_position.top) / (this.element
.height() - node.height()),
"left": (node_position.left - element_position.left) / (this.element
.width() - node.width())
};
}
node.css({
"top": element_position.top +
Math.floor(position.top * (this.element.height() - node.height())) +
"px",
"left": element_position.left +
Math.floor(position.left * (this.element.width() - node.width())) +
"px"
});
// update node data with position
this.node_data(node_id, $.extend(this.node_data(node_id), {
top: position.top,
left: position.left
}));
jsPlumb.repaintEverything();
return this;
},
graph: function (value) {
// get or set the graph data
if (value === undefined) {
// get
var graph = {
"general": {},
"nodes": {},
"edges": {}
};
$.each(this.general, $.proxy(function (key, value) {
graph["general"][key] = value;
}, this));
$.each(this.nodes, $.proxy(function (node_id, node) {
graph["nodes"][node_id] = node.data(this.options.node_data_key);
}, this));
$.each(this.edges, $.proxy(function (edge_id, edge) {
graph["edges"][edge_id] = this.edges[edge_id];
}, this));
return graph;
}
this.clear();
$.each(value.general, $.proxy(function (key, value) {
this.general[key] = value;
}, this));
$.each(value.nodes, $.proxy(function (node_id, node) {
this.add_node(node_id, node);
}, this));
$.each(value.edges, $.proxy(function (edge_id, edge) {
this.add_edge(edge_id, edge[0], edge[1], edge[2] || {});
}, this));
return this;
}
});
jsPlumb.bind("ready", function () {
/* Initialize jsPlumb defaults
*/
// TODO: default for connections ?
jsPlumb.setRenderMode(jsPlumb.SVG);
jsPlumb.importDefaults({
Endpoint: ["Dot", {
radius: 2
}],
ConnectionOverlays: [
["Arrow", {
location: 1,
width: 10
}]
],
Anchor: "Continuous"
});
if ($("#main").length > 0) {
$.getJSON("../JSONInputs/Topology01.json", function (data) {
$("#main").grapheditor({
graph: data,
node_moved: function (event, node_id) {
$("#debug_zone").val(JSON.stringify(
$("#main").grapheditor("graph"), undefined, " "));
}
});
// Access the nodes
var grapheditor = $("#main").data("dreamGrapheditor");
$.each(grapheditor.nodes, function (node_id, node) {
// test: click to add a property
node.click(function (e) {
$.mobile.changePage("#dialog", {
role: "dialog"
});
$("#main").grapheditor("node_data", node_id,
$.extend($("#main").grapheditor("node_data", node_id), {
"dbclick": 1
}));
});
});
// reload from json
$("#load_json").click(function () {
$("#main").grapheditor("graph",
JSON.parse($("#debug_zone").val()));
});
});
};
if ($("#simulation").length > 0) {
$("#run_simulation").button().click(function () {
var graph_dict = $('#main').grapheditor('graph');
$("#json_output").val(JSON.stringify(graph_dict, undefined, ' '));
$.ajax(
'/runSimulation', {
data: JSON.stringify({
json: graph_dict
}),
contentType: 'application/json',
type: 'POST',
success: function (data, textStatus, jqXHR) {
if (data['success']) {
$("#json_result").text(JSON.stringify(data['success'],
undefined, " "));
// display demo graph.
$("#graph_zone").show();
var blockage_data = [],
waiting_data = [],
failure_data = [],
working_data = [],
ticks = [],
counter = 1;
$.each(data['success'].elementList, function (idx, obj) {
if (obj.results.working_ratio !== undefined) {
/* when there is only one replication, the ratio is given as a float,
otherwise we have a mapping avg, min max */
if (obj.results.blockage_ratio !== undefined) {
blockage_data.push([counter, obj.results.blockage_ratio
.avg || obj.results.blockage_ratio
]);
} else {
blockage_data.push([counter, 0.0]);
}
waiting_data.push([counter, obj.results.waiting_ratio.avg ||
obj.results.waiting_ratio
]);
if (obj.results.failure_ratio !== undefined) {
failure_data.push([counter, obj.results.failure_ratio
.avg || obj.results.failure_ratio
]);
} else {
failure_data.push([counter, 0.0]);
}
working_data.push([counter, obj.results.working_ratio.avg ||
obj.results.working_ratio
]);
ticks.push([counter, obj.id]);
counter++;
}
});
var series = [{
label: "Working",
data: working_data
}, {
label: "Waiting",
data: waiting_data
}, {
label: "Failures",
data: failure_data
}, {
label: "Blockage",
data: blockage_data
}];
var options = {
xaxis: {
minTickSize: 1,
ticks: ticks
},
yaxis: {
max: 100
},
series: {
bars: {
show: true,
barWidth: 0.9,
align: "center"
},
stack: true
}
};
$.plot("#simulation_result", series, options);
} else {
$("#json_result").effect('shake', 50).text(data['error']);
}
}
});
});
};
});
function init() {
}
rJS(window).declareMethod('getContent', function () {
return JSON.stringify($('#main').grapheditor('graph'), undefined, ' ');
})
.declareMethod('setContent', function (content) {
$('#main').grapheditor('graph', JSON.parse(content));
})
.declareMethod('clearContent', function () {
$('#main').grapheditor('clear');
})
.ready(function () {
init.apply(rJS(this));
});
}(window, jQuery, rJS));
/*global window, jQuery, rJS */
"use strict";
(function (window, $, rJS) {
$.mobile.ajaxEnabled = false;
$.mobile.linkBindingEnabled = false;
$.mobile.hashListeningEnabled = false;
$.mobile.pushStateEnabled = false;
rJS(window).ready(function () {
var g = rJS(this),
body = g.context,
main_context = g.context.find('.ui-content').first(),
ioGadgetConfig = {"type": "local",
"username": "officejs",
"application_name": "officejs"
},
jioGadget;
function setTitle(title) {
g.context.find("#headergadget").find("h1").text(title);
return $('title').text("OfficeJS | " + title);
}
function enhanceGadgetRendering(gadget) {
gadget.context.enhanceWithin();
return gadget.getTitle()
.then(setTitle);
}
function registerSaveButton(gadget) {
window.jqs = gadget;
$("#save-doc").click(function () {
var fileName = $("#iogadget input").val();
jioGadget.configureIO(ioGadgetConfig, fileName)
.then(gadget.getContent)
.then(function (o) {jioGadget.setIO(o); });
});
return gadget;
}
function registerLoadButton(gadget) {
$("#load-doc").click(function () {
var fileName = $("#iogadget input").val();
jioGadget.configureIO(ioGadgetConfig, fileName)
.then(jioGadget.getIO)
.then(gadget.setContent);
});
return gadget;
}
function registerClearButton(gadget) {
$("#new-doc").click(function () {
gadget.clearContent();
});
}
function registerIOButtons(gadget) {
registerSaveButton(gadget);
registerLoadButton(gadget);
registerClearButton(gadget);
}
function initializeRoute() {
body
.route("add", "", 1)
.done(function () {
$.url.redirect('/login/');
});
body
.route("add", "/about/", 1)
.done(function () {
g.declareGadget('./about.html', main_context)
.then(enhanceGadgetRendering);
});
body
.route("add", "/contact/", 1)
.done(function () {
g.declareGadget('./contact.html', main_context)
.then(enhanceGadgetRendering);
});
body
.route("add", "/login/", 1)
.done(function () {
g.declareGadget('./login.html', main_context)
.then(enhanceGadgetRendering);
});
body
.route("add", "/graph/", 1)
.done(function () {
g.declareIframedGadget('./graph.html', main_context)
.then(registerIOButtons);
});
body
.route("add", "/simulation/", 1)
.done(function () {
g.declareIframedGadget('./simulation.html', main_context)
.then(registerIOButtons);
});
}
g.declareGadget('./io.html', g.context.find("#iogadget"))
.done(function (ioGadget) {
window.jio = ioGadget;
jioGadget = ioGadget;
// Trigger route change
initializeRoute();
$.url.onhashchange(function () {
body.route("go", $.url.getPath())
.fail(function () {
g.declareGadget('./error.html', main_context)
.then(enhanceGadgetRendering)
.then(initializeRoute);
});
});
});
});
}(window, jQuery, rJS));
/*global window, jQuery, jIO, rJS */
/*jslint unparam: true*/
"use strict";
(function (window, $, jIO, rJS) {
var gk = rJS(window);
gk.declareMethod('configureIO', function (json_configuration, key) {
rJS(this).jio = jIO.newJio(json_configuration);
rJS(this).jio_key = key;
//console.log(rJS(this).jio);
return key;
})
.declareMethod('getIO', function () {
var deferred = $.Deferred(),
default_value = "",
gadget = rJS(this);
gadget.jio.getAttachment({
"_id": gadget.jio_key,
"_attachment": "body.txt"
}, function (err, response) {
if (err) {
if (err.status === 404) {
deferred.resolve(default_value);
} else {
deferred.reject(err);
}
} else {
//console.log("getIO: " + response);
deferred.resolve(response || default_value);
}
});
return deferred.promise();
})
.declareMethod('setIO', function (value) {
//console.log("couscous");
var deferred = $.Deferred(),
gadget = rJS(this);
gadget.jio.put({"_id": gadget.jio_key},
function (err, response) {
if (err) {
deferred.reject(err);
} else {
gadget.jio.putAttachment({
"_id": gadget.jio_key,
"_attachment": "body.txt",
"_data": value,
"_mimetype": "text/plain"
}, function (err, response) {
if (err) {
deferred.reject(err);
} else {
//console.log("putIO: " + value);
deferred.resolve();
}
});
}
});
return deferred.promise();
});
}(window, jQuery, jIO, rJS));
/*global window, jQuery, rJS*/
"use strict";
(function (window, $, rJS) {
function init(config) {
this.parent = this.context.find('.jQuerySheet');
this.parent.sheet(config);
this.instance = this.parent.getSheet();
}
var default_config = {
id: "jquerysheet-div",
style: '',
jquerySheet: true,
jquerySheetCss: true,
parser: true,
jqueryUiCss: true,
scrollTo: false,
jQueryUI: false,
raphaelJs: false,
gRaphaelJs: false,
colorPicker: false,
colorPickerCss: false,
elastic: false,
advancedMath: false,
finance: false,
editable: true,
autoFiller: true,
urlGet: '../lib/jquery.sheet-2.0.0/new_spreadsheet.html'
};
rJS(window).declareMethod('getContent', function () {
var content = JSON.stringify($.sheet.instance[0].exportSheet.json());
//console.log("function getContent" + content);
return content;
})
.declareMethod('setContent', function (content) {
var config = $.extend({
buildSheet: $.sheet.makeTable.json(JSON.parse(content))
}, default_config);
//console.log(config.buildSheet);
init.apply(rJS(this), [config]);
})
.declareMethod('clearContent', function () {
$.sheet.killAll();
init.apply(rJS(this), [default_config]);
})
.ready(function () {
init.apply(rJS(this), [default_config]);
});
}(window, jQuery, rJS));
/*global window, jQuery, rJS */
"use strict";
(function (window, $, rJS, undefined) {
var gk = rJS(window);
rJS(window).ready(function () {
var g = rJS(this),
form_context = g.context.find('form'),
field_context = form_context.find("input[type=text]");
function submit_event() {
var jio_json = {
"type": "local",
"username": field_context.val()
};
// XXX What to do?
g.context.text(JSON.stringify(jio_json));
return false;
}
form_context.submit(submit_event);
});
}(window, jQuery, rJS));
<ul>
<li>
<a href="#">File</a>
<ul>
<li><a onclick="sheetInstance.newSheet(); return false;" title="Creates a new spreadsheet.">New</a></li>
<li><a onclick="sheetInstance.s.fnOpen(); return false;" title="Open a new spreadsheet.">Open</a></li>
<li><a onclick="sheetInstance.s.fnSave(); return false;" title="Save the current spreadsheet.">Save</a></li>
<li><a onclick="sheetInstance.s.fnClose(); return false;" title="Close the current spreadsheet without saving.">Close</a></li>
</ul>
</li>
<li>
<a href="#">Edit</a>
<ul>
<li>
<a href="#">Cell</a>
<ul>
<li><a onclick="sheetInstance.setCellRef(); return false;">Set Reference</a></li>
</ul>
</li>
<li>
<a menu="menuEditRow_menuInstance">Row</a>
<ul>
<li><a onclick="sheetInstance.merge(); return false;">Merge</a></li>
<li><a onclick="sheetInstance.unmerge(); return false;">Un-Merge</a></li>
<li><a onclick="sheetInstance.controlFactory.addRow(null, null, ':last'); return false;" title="Adds an additional row to bottom of the spreadsheet.">Add Row</a></li>
<li><a onclick="sheetInstance.controlFactory.addRowMulti(); return false;" title="Adds an additional rows to bottom of the spreadsheet.">Add Multi-Rows</a></li>
<li><a onclick="sheetInstance.deleteRow(); return false;" title="Delets the current row thats highlighted.">Delete Row</a></li>
<li><a onclick="sheetInstance.controlFactory.addRow(null, true); return false;" title="Inserts an additional row after currently selected row.">Insert Row Before</a></li>
<li><a onclick="sheetInstance.controlFactory.addRow(); return false;" title="Inserts an additional row after currently selected row.">Insert Row After</a></li>
<!--<li><a onclick="sheetInstance.toggleHide.rowAll();" title="Unhides all the hidden rows.">Show All</a></li>
<li><a onclick="sheetInstance.toggleHide.row();" title="Hides or shows the currently selected row.">Toggle Hide Row</a></li>-->
</ul>
</li>
<li>
<a menu="menuEditColumn_menuInstance">Column</a>
<ul>
<li><a onclick="sheetInstance.controlFactory.addColumn(null, null, ':last'); return false;" title="Adds an additional column to the right of the spreadsheet.">Add Column</a></li>
<li><a onclick="sheetInstance.controlFactory.addColumnMulti(); return false;" title="Adds an additional columns to the right of the spreadsheet.">Add Multi-Columns</a></li>
<li><a onclick="sheetInstance.deleteColumn(); return false;" title="Deletes the current column thats highlighted.">Delete Column</a></li>
<li><a onclick="sheetInstance.controlFactory.addColumn(null, true); return false;" title="Inserts an additional column after currently selected column.">Insert Column Before</a></li>
<li><a onclick="sheetInstance.controlFactory.addColumn(); return false;" title="Inserts an additional column after currently selected column.">Insert Column After</a></li>
<li><a onclick="sheetInstance.fillUpOrDown(); return false;" title="Fill down current cell value.">Fill Down</a></li>
<li><a onclick="sheetInstance.fillUpOrDown(true); return false;" title="Fill up current cell value.">Fill Up</a></li>
<!--<li><a onclick="sheetInstance.toggleHide.columnAll();" title="Unhides all the hidden columns.">Show All</a></li>
<li><a onclick="sheetInstance.toggleHide.column();" title="Hides or shows the currently selected column.">Toggle Hide Column</a></li>-->
</ul>
</li>
<li>
<a menu="menuEditSheet_menuInstance">Sheet</a>
<ul>
<li><a onclick="sheetInstance.addSheet(); return false;" title="Add new spreadsheet.">Add Spreadsheet</a></li>
<li><a onclick="sheetInstance.deleteSheet(); return false;" title="Delete the current spreadsheet.">Delete Spreadsheet</a></li>
<li><a onclick="sheetInstance.calc(); return false;" title="Recompiles the current sheet">Refresh Calculations</a></li>
<li><a onclick="sheetInstance.sheetTitle(); return false;" title="Change the title of the sheet.">Title</a></li>
</ul>
</li>
<li><a onclick="sheetInstance.cellFind(); return false;">Find</a></li>
<li><a onclick="sheetInstance.getTdRange(null, sheetInstance.obj.formula().val()); return false;">Get Cell Range</a></li>
<li>
<a href="#">Wrap Cell Range</a>
<ul>
<li><a onclick="sheetInstance.getTdRange(null, sheetInstance.obj.formula().val(), 'SUM'); return false;" title="Wrap with SUM">SUM()</a></li>
<li><a onclick="sheetInstance.getTdRange(null, sheetInstance.obj.formula().val(), 'CEILING'); return false;" title="Wrap with CEILING">CEILING()</a></li>
<li><a onclick="sheetInstance.getTdRange(null, sheetInstance.obj.formula().val(), 'COUNT'); return false;" title="Wrap with COUNT">COUNT()</a></li>
<li><a onclick="sheetInstance.getTdRange(null, sheetInstance.obj.formula().val(), 'MAX'); return false;" title="Wrap with MAX">MAX()</a></li>
<li><a onclick="sheetInstance.getTdRange(null, sheetInstance.obj.formula().val(), 'MIN'); return false;" title="Wrap with MIN">MIN()</a></li>
</ul>
</li>
<li><a onclick="sheetInstance.cellUndoable.undoOrRedo(true); return false;">Undo</a></li>
<li><a onclick="sheetInstance.cellUndoable.undoOrRedo(); return false;">Redo</a></li>
<li><a onclick="sheetInstance.toggleState(); return false;">Toggle State</a></li>
</ul>
</li>
<li>
<a href="#">View</a>
<ul>
<li><a onclick="sheetInstance.viewSource(true); return false;" title="Shows the HTML that makes up the current spreadsheet.">Pretty Source</a></li>
<li><a onclick="sheetInstance.viewSource(false); return false;" title="Shows the compact HTML that makes up the current spreadsheet.">Compact Source</a></li>
<li><a onclick="sheetInstance.print(sheetInstance.HTMLtoPrettySource(jQuery(sheetInstance.exportSheet.xml(true))[0])); return false;">As XML</a></li>
<li><a onclick="sheetInstance.print(JSON.stringify(sheetInstance.exportSheet.json())); return false;">As JSON</a></li>
<li>
<a menu="menuViewFunctionReference_menuInstance">Function Reference</a>
<ul>
<li>
<a href="#">Math & Standard</a>
<ul>
<li><a title="Returns the absolute value of a number">ABS()</a></li>
<li><a title="Returns a rounded number">AVG(), AVERAGE()</a></li>
<li><a title="Returns a number rounded up based on a multiple of significance">CEILING()</a></li>
<li><a title="Counts the number of cells that contain a value">COUNT()</a></li>
<li><a title="Counts full days from a specific date - format(YYYY,MM,DD)">DAYSFROM()</a></li>
<li><a title="Converts a number to text, using a currency format - options(number, decimals, symbol)">DOLLAR()</a></li>
<li><a title="Returns a logical value of FALSE">FALSE()</a></li>
<li><a title="Returns a text representation of a number rounded to a specified number of decimal places - options(number, decimals, useCommas)">FIXED()</a></li>
<li><a title="Returns a number rounded down based on a multiple of significance">FLOOR()</a></li>
<li><a title="Creates and executes a javascript function. example: FN(alert('Hello World')), this will execute when sheet compiles.">FN()</a></li>
<li><a title="Returns the integer portion of a number">INT()</a></li>
<li><a title="Returns the largest value from the numbers provided">MAX()</a></li>
<li><a title="Returns the smallest value from the numbers provided">MIN()</a></li>
<li><a title="Converts a value to a number">N()</a></li>
<li><a title="Gets full date of today">NOW()</a></li>
<li><a title="Returns the mathematical constant called pi, which is 3.14159265358979">PI()</a></li>
<li><a title="Returns the result of a number raised to a given power">POWER(x, y)</a></li>
<li><a title="Returns a random number that is greater than or equal to 0 and less than 1">RAND(), RND()</a></li>
<li><a title="Returns a number rounded to a specified number of digits">ROUND()</a></li>
<li><a title="Returns all of the values in each of the specified cells and added together">SUM()</a></li>
<li><a title="Gets full date of today">TODAY()</a></li>
<li><a title="Returns a logical value of TRUE">TRUE()</a></li>
<li><a title="Converts a text value that represents a number to a number">VALUE()</a></li>
</ul>
</li>
<li>
<a href="#">Chart</a>
<ul>
<li><a href="#" title="Simple verticle style bar chart.">BARCHART()</a></li>
<li><a href="#" title="Simple horizontal style bar chart.">HBARCHART()</a></li>
<li><a href="#" title="Simple line style bar chart.">LINECHART()</a></li>
<li><a href="#" title="Simple pie style bar chart.">PIECHART()</a></li>
</ul>
</li>
<li>
<a href="#">Inputs</a>
<ul>
<li><a href="#">DROPDOWN()</a></li>
<li><a href="#">RADIO()</a></li>
<li><a href="#">CHECKBOX()</a></li>
</ul>
</li>
<li>
<a href="#">Finance</a>
<ul>
<li><a href="#">COMMINGSOON()</a></li>
</ul>
</li>
<li>
<a href="#">Advanced Math</a>
<ul>
<li><a href="#">COMINGSOON()</a></li>
</ul>
</li>
</ul>
</li>
<li><a onclick="sheetInstance.toggleFullScreen();">Toggle Full Screen</a></li>
</ul>
</li>
<li>
<a href="#">Style</a>
<ul>
<li><a class="cellStyleToggle" onclick="sheetInstance.cellStyleToggle('styleBold'); return false;">Bold</a></li>
<li><a class="cellStyleToggle" onclick="sheetInstance.cellStyleToggle('styleItalics'); return false;">Italics</a></li>
<li><a class="cellStyleToggle" onclick="sheetInstance.cellStyleToggle('styleUnderline', 'styleLineThrough'); return false;">Underline</a></li>
<li><a class="cellStyleToggle" onclick="sheetInstance.cellStyleToggle('styleLineThrough', 'styleUnderline'); return false;">Strikethrough</a></li>
<li><a class="cellStyleToggle" onclick="sheetInstance.cellStyleToggle('styleLeft', 'styleCenter styleRight'); return false;">Left</a></li>
<li><a class="cellStyleToggle" onclick="sheetInstance.cellStyleToggle('styleCenter', 'styleLeft styleRight'); return false;">Center</a></li>
<li><a class="cellStyleToggle" onclick="sheetInstance.cellStyleToggle('styleRight', 'styleLeft styleCenter'); return false;">Right</a></li>
<li><a class="cellStyleToggle" onclick="sheetInstance.cellStyleToggle('styleUpper', 'styleCapital styleLower'); return false;">Uppercase</a></li>
<li><a class="cellStyleToggle" onclick="sheetInstance.cellStyleToggle('styleCapital', 'styleUpper styleLower'); return false;">Capitalize</a></li>
<li><a class="cellStyleToggle" onclick="sheetInstance.cellStyleToggle('styleLower', 'styleCapital styleUpper'); return false;">Lowercase</a></li>
<li><a class="cellStyleToggle" onclick="sheetInstance.cellStyleToggle('styleTop', 'styleMiddle styleBottom'); return false;">Top</a></li>
<li><a class="cellStyleToggle" onclick="sheetInstance.cellStyleToggle('styleMiddle', 'styleTop styleBottom'); return false;">Middle</a></li>
<li><a class="cellStyleToggle" onclick="sheetInstance.cellStyleToggle('styleBottom', 'styleTop styleMiddle'); return false;">Bottom</a></li>
<li><a class="cellStyleToggle" onclick="sheetInstance.fontReSize('up'); return false;">Font Size +</a></li>
<li><a class="cellStyleToggle" onclick="sheetInstance.fontReSize('down'); return false;">Font Size -</a></li>
</ul>
</li>
</ul>
/* ===========================================================================
* Copyright 2013 Nexedi SA and Contributors
*
* This file is part of DREAM.
*
* DREAM is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* DREAM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with DREAM. If not, see <http://www.gnu.org/licenses/>.
* =========================================================================== */
/*jslint indent: 2, maxlen: 80, nomen: true */
(function ($) {
"use strict";
jsPlumb.bind("ready", function () {
/* Initialize jsPlumb defaults
*/
// TODO: default for connections ?
jsPlumb.setRenderMode(jsPlumb.SVG);
jsPlumb.importDefaults({
Endpoint: ["Dot", {
radius: 2
}],
ConnectionOverlays: [
["Arrow", {
location: 1,
width: 10
}]
],
Anchor: "Continuous"
});
$.widget("dream.grapheditor", {
options: {
node_class: "graph_node", // CSS class for nodes
node_data_key: "grapheditor_node_data", // Key to store data on nodes using $.data
// XXX is it good idea to use
// $.data ???
draggable_nodes: true // Can nodes be dragged
},
_create: function () {
this.nodes = {};
this.edges = {};
if (this.options.graph) {
this.graph(this.options.graph);
}
},
destroy: function () {
this.clear();
this._destroy();
},
clear: function () {
this.edges = {};
$.each(this.nodes, $.proxy(function (node_id, node) {
jsPlumb.remove(node);
delete(this["nodes"][node_id]);
}, this));
},
create_node_element: function (node_id, node_data) {
// Create an element for a node, and add it to the main element.
return $('<div>')
.uniqueId()
.addClass(this.options.node_class)
.text(node_data['name'] || node_id)
.appendTo(this.element);
},
add_node: function (node_id, node_data) {
/* add a node */
var element = this.create_node_element(node_id, node_data);
if (this.options.draggable_nodes) {
// make the node draggable
jsPlumb.draggable(element, {
containment: this.element,
stop: $.proxy(function (node_id, event) {
this.node_position(node_id, this.node_position(node_id));
this._trigger("node_moved", event, node_id);
}, this, node_id)
});
}
this.nodes[node_id] = element;
this.node_position(node_id, node_data);
this.node_data(node_id, node_data);
this._trigger('node_added', node_id);
},
create_edge_element: function (edge_id, source_node_id,
destination_node_id, edge_data) {
// Create an element for an edge
var edge_label = edge_data['name'] || "";
jsPlumb.connect({
source: this.nodes[source_node_id].attr("id"),
target: this.nodes[destination_node_id].attr("id"),
paintStyle: {
lineWidth: 1,
strokeStyle: "#000"
}, // XXX make this an option
overlays: [
["Label", {
label: edge_label
}]
]
});
},
add_edge: function (edge_id, source_node_id, destination_node_id,
edge_data) {
/* add an edge */
this.create_edge_element(edge_id, source_node_id,
destination_node_id, edge_data);
this.edges[edge_id] = [source_node_id, destination_node_id,
edge_data
];
this._trigger('edge_added', edge_id);
},
node_data: function (node_id, node_data) {
/* get or set data for a node */
var node = this.nodes[node_id];
if (node_data === undefined) {
return node.data(this.options.node_data_key);
}
this.nodes[node_id].data(this.options.node_data_key, node_data);
this._trigger("node_data_changed", node_id);
return this;
},
edge_data: function (edge_id, edge_data) {
/* get or set data for an edge */
var edge = this.edges[edge_id];
if (edge_data === undefined) {
return edge[2];
}
this.edges[edge_id] = [edge[0], edge[1], edge_data];
this._trigger("edge_data_changed", edge_id);
return this;
},
node_position: function (node_id, position) {
/* Get or set the position of a node with position given on a 0..1 scale */
var node = this.nodes[node_id],
node_position = node.position(),
element_position = this.element.position();
if (position === undefined) {
return {
"top": (node_position.top - element_position.top) / (this.element
.height() - node.height()),
"left": (node_position.left - element_position.left) / (this.element
.width() - node.width())
};
}
node.css({
"top": element_position.top +
Math.floor(position.top * (this.element.height() - node.height())) +
"px",
"left": element_position.left +
Math.floor(position.left * (this.element.width() - node.width())) +
"px"
});
// update node data with position
this.node_data(node_id, $.extend(this.node_data(node_id), {
top: position.top,
left: position.left
}));
jsPlumb.repaintEverything();
return this;
},
graph: function (value) {
// get or set the graph data
if (value === undefined) {
// get
var graph = {
"nodes": {},
"edges": {}
};
$.each(this.nodes, $.proxy(function (node_id, node) {
graph["nodes"][node_id] = node.data(this.options.node_data_key);
}, this));
$.each(this.edges, $.proxy(function (edge_id, edge) {
graph["edges"][edge_id] = this.edges[edge_id];
}, this));
return graph;
}
this.clear();
$.each(value.nodes, $.proxy(function (node_id, node) {
this.add_node(node_id, node);
}, this));
$.each(value.edges, $.proxy(function (edge_id, edge) {
this.add_edge(edge_id, edge[0], edge[1], edge[2] || {});
}, this));
return this;
}
});
$.getJSON("JSONInputs/Topology01.json", function (data) {
$("#main").grapheditor({
graph: data,
node_moved: function (event, node_id) {
$("#debug_zone").val(JSON.stringify(
$("#main").grapheditor("graph"), undefined, " "));
}
});
// move a node
function move_node() {
$("#main").grapheditor("node_position", $("#node_id").val(), {
top: $("#node_top").val() / 100,
left: $("#node_left").val() / 100
});
}
$("#move_node").click(move_node);
$("#node_top").change(move_node);
$("#node_left").change(move_node);
// when node is selected or moved, update the sliders
function updateSliders(node_id) {
var node_pos = grapheditor.node_position(node_id);
$("#node_id").val(node_id);
$("#node_top").val(Math.floor(node_pos.top * 100)).slider(
"refresh");
$("#node_left").val(Math.floor(node_pos.left * 100)).slider(
"refresh");
}
// Access the nodes
var grapheditor = $("#main").data("dreamGrapheditor");
$.each(grapheditor.nodes, function (node_id, node) {
node.click(function (e) {
updateSliders(node_id);
});
// test: click to add a property
node.click(function (e) {
$.mobile.changePage("#dialog", {
role: "dialog"
});
$("#main").grapheditor("node_data", node_id,
$.extend($("#main").grapheditor("node_data", node_id), {
"dbclick": 1
}));
});
});
$("#main").on("grapheditornode_moved", function (event, node_id) {
updateSliders(node_id);
});
// reload from json
$("#load_json").click(function () {
$("#main").grapheditor("graph",
JSON.parse($("#debug_zone").val()));
});
});
});
})(jQuery);
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment