Home directory for Malawi's wwwroot
Duncan Ewan
2021-02-19 3e758c29e0fde36fc088efcfc88f9a3014432b64
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
   <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
   <title>Process Flow Test</title>
 
   <link rel="stylesheet" type="text/css" href="css/jquery-ui-lightness/jquery-ui-1.7.2.custom.css" />
 
   <!-- Process Flow Library Styling Dependencies -->
   <link rel="stylesheet" type="text/css" href="css/jquery.contextmenu.css"/>
   <link rel="stylesheet" type="text/css" href="css/processFlow.css" />
 
   <!-- Javascript Libraries -->
   <!-- Required By the Process Flow Library -->
   <script type="text/javascript" src="js/jquery/jquery-1.3.2.js"></script>
   <script type="text/javascript" src="js/jquery/jquery.contextmenu.js"></script>
   <script type="text/javascript" src="js/raphael/raphael.js"></script>
   <script type="text/javascript" src="js/raphael/raphael.zoom.js"></script>
   <script type="text/javascript" src="js/util/hashmap.js"></script>
   <script type="text/javascript" src="js/util/array_util.js"></script>
   <script type="text/javascript" src="js/util/arraylist.js"></script>
   <script type="text/javascript" src="js/util/dracula_graph.js"></script>
   <script type="text/javascript" src="js/jquery/jquery.qtip-1.0.0-rc3.custom.mtn.js"></script>
 
   <!-- These are only used by the client page -->
   <script type="text/javascript" src="js/jquery/jquery-ui-1.7.2.custom.mtn.js"></script>
   <script type="text/javascript" src="js/jquery/jquery.metadata.js"></script>
 
 
   <!-- Process Flow Library -->
   <script type="text/javascript" src="js/custom/ProcessFlow.js"></script>
 
   <!-- Test Data Structures -->
   <script type="text/javascript" src="js/custom/FlowJSON.js"></script>
   <script type="text/javascript" src="js/custom/editorProperties.js"></script>
   <script type="text/javascript" src="js/custom/catalogueConfig.js"></script>
 
   <script type="text/javascript">
      var lastNodeId = 6;
      var lastConnectionId = 5;
 
      var $controlBarWrapper = null;
      $controlBarWrapper = $('#controlBarWrapper');
 
      $(document).ready(function(){
        $(window).scroll(setFloatingElementPositions);
 
        // -------------------------------------------
        // Start - Process Flow Diagram Initialization
        // -------------------------------------------
        ProcessFlow.init({canvas                : '.canvas',               // The DOM element in which the flow elements will be drawn
                          node_items            : flowNodes ,           // The definition of all flow items currrently in the diagram
                          node_item_values      : nodeItemValues,
                          node_field_config     : fieldConfig,
                          node_connections      : nodeConnections,      // The definition of all existing connections between flow items
                          node_connection_types : nodeConnectionTypes,  // The list of supported connection types per node
                          connection_rules      : connectionRules,      // The list of supported connection targets per connection type
                          onNodeEdit            : function(nodeId, nodeType){            // The function to be called when the user click the "Edit" link on the node context menu
                                                     ProcessFlow.showNodeEditDialog('Node', nodeId, nodeType);
                                                  },
                          onConnectionEdit      : function(nodeId, nodeType){ // The function to be called when the user clicks on the "Edit" link on the connection context menu
                                                     ProcessFlow.showNodeEditDialog('Connection', nodeId, nodeType);
                                                  },
                          connectionIdFactory   : getNewConnectionId    // The function used to generate IDs for new connections
                          });
 
        // -------------------------------------------
        // End - Process Flow Diagram Initialization
        // -------------------------------------------
 
 
        // Show Dialogs
        $(".dialog").dialog({ autoOpen: true, minHeight: 250, minWidth: 200, height: 400});
        $('.catalogueItem').draggable({helper : 'clone', 'appendTo': '.canvas', containment : '.canvas', opacity : 0.7});
        $(".canvas").droppable({ accept: '.catalogueItem',
           drop :
              function(event, ui){
                  var itemMeta = $(ui.draggable).metadata();
                  var shape = null;
                  var newNode = null;
 
                  var thisOffset = $(this).offset();
 
                  if(itemMeta.shape.type == 'circle'){
                     shape = ProcessFlow.createCircle(itemMeta.shape.entity_id, event.pageX - thisOffset.left, event.pageY - thisOffset.top,itemMeta.shape.radius,
                           itemMeta.shape.border_color, itemMeta.shape.border_width, itemMeta.shape.fill);
                  }else if (itemMeta.shape.type == 'rect'){
                     shape = ProcessFlow.createRect(itemMeta.shape.entity_id, event.pageX - thisOffset.left, event.pageY - thisOffset.top,itemMeta.shape.width, itemMeta.shape.height, itemMeta.shape.border_radius,
                           itemMeta.shape.border_color, itemMeta.shape.border_width, itemMeta.shape.fill);
                  }
                  // Application should fire ajax request here to get a new ID for this object
                  var id = getNewNodeId();
                  var newNode = ProcessFlow.createNode(id, null, itemMeta.type, itemMeta.label, itemMeta.icon, shape);
                  ProcessFlow.addNode(newNode);
                  console.log(ProcessFlow.getNodeById(id));
                  ProcessFlow.selectOnlyNode(ProcessFlow.getNodeById(id))
              }
        });
 
        // Initialize the catalogue Items
        ProcessFlow.initCatalogueItems('#itemCatalogue', catalogueConfig, 2);
 
        // Intialize the toolbar
        initToolbar();
 
        // Initialize the Node edit dialog
        $('#nodeEditDialog').dialog({ autoOpen : false, modal : true});
 
      });
 
      // Generate a new connection ID
      // This will typical be an Ajax request to the server
      function getNewConnectionId(){
         return lastConnectionId++;
      }
 
      // Generate a new node ID
      // This will typical be an Ajax request to the server
      function getNewNodeId(){
         return lastNodeId++;
      }
 
      //Intialize the toolbar actions
      var currentZoom = 1;
      function initToolbar(){
         // Reset Process flow actions
         $('#cursorPointerBtn').click(function(){
            ProcessFlow.stopItemBlockSelection();
         });
 
         // Block Selection Button
         $('#blockSelBtn').click(function(){
            ProcessFlow.startItemBlockSelection();
         });
 
         // Alignment Buttons
         $('#alignLeftBtn').click(function(){
            ProcessFlow.alignNodes('left');
         });
         $('#alignTopBtn').click(function(){
            ProcessFlow.alignNodes('top');
         });
         $('#alignRightBtn').click(function(){
            ProcessFlow.alignNodes('right');
         });
         $('#alignBottomBtn').click(function(){
            ProcessFlow.alignNodes('bottom');
         });
         $('#alignMiddleBtn').click(function(){
            ProcessFlow.alignNodes('middle');
         });
         $('#alignCenterBtn').click(function(){
            ProcessFlow.alignNodes('center');
         });
 
         // Connection Router Modification Buttons
         $('#straightRouteBtn').click(function(){
            ProcessFlow.setConnectionRoutingType('straight');
         });
         $('#manhattanRouteBtn').click(function(){
            ProcessFlow.setConnectionRoutingType('manhattan');
         });
 
         // Auto Layout Button
          $('#springLayoutBtn').click(function(){
             ProcessFlow.layoutSpring();
          });
 
          $('#directedLayoutBtn').click(function(){
             ProcessFlow.layoutDirected();
          });
 
         // Canvas Sizing Buttons
          $('#decreasePageSizeBtn').click(function(){
            ProcessFlow.scaleCanvas(false, 0.1);
         });
         $('#increasePageSizeBtn').click(function(){
            ProcessFlow.scaleCanvas(true, 0.1);
         });
          $('#dynamicPageSizeBtn').click(function(){
             ProcessFlow.scaleCanvasDynamic();
          });
 
          $('#zoomInBtn').click(function(){
             currentZoom += 0.1;
             ProcessFlow.setZoomLevel(currentZoom);
          });
 
          $('#zoomOutBtn').click(function(){
             currentZoom -= 0.1;
             ProcessFlow.setZoomLevel(currentZoom);
          });         
 
          $('#apiTestBtn').click(function(){
             ProcessFlow.setNodeProperties(3, {label : "New Label"});
          });
 
         // Node Delete Button
         $('#delBtn').click(function(){
            ProcessFlow.deleteSelectedNodes();
         });
 
         // SAVE Button
         $('#saveButton').click(function(){
            var currentState = ProcessFlow.getCurrentStateJSON();
            console.log(currentState);
            console.log('Nodes');
            for(i = 0; i < currentState.nodes.length; i++){
               console.log('Node ID: ' + currentState.nodes[i].id + ', Label: ' +  currentState.nodes[i].label);
            }
 
            console.log('Connections');
            for(i = 0; i < currentState.connections.length; i++){
               console.log('Conn ID: ' + currentState.connections[i].id + ', From NodeID: ' +  currentState.connections[i].from_node_id + ', To NodeID: ' +  currentState.connections[i].to_node_id);
            }
         });
      }
 
      // Make sure that absolutely positioned elements stay in position
      // when the canvas size is increased.
      function setFloatingElementPositions(){
         $controlBarWrapper.css({'top' : $(this).scrollTop(), 'left' : $(this).scrollLeft()});
      }
 
      // Initialize the catalogue item functionality
      function initCatalogueItems(){
          $('.catalogueItem').each(function(){
             var nodeItemMeta = $(this).metadata();
             var paper = Raphael($(this)[0], $(this).width(), $(this).height());
 
             if(nodeItemMeta.shape.type == 'circle'){
                var circleXYR = ($(this).height() / 2);
                paper.circle(circleXYR, circleXYR, circleXYR - 2).attr({fill : nodeItemMeta.shape.fill});
             }else if(nodeItemMeta.shape.type == 'rect'){
                paper.rect(1, 1, $(this).width() - 2,$(this).height() - 2, 5).attr({fill : nodeItemMeta.shape.fill});
             }
          });
 
      }
 
   </script>
 
   <style type="text/css">
      .catalogueItem {
         width: 50px;
         height: 50px;
         padding: 4px;
      }
      .ui-draggable-dragging{
         z-index: 1020;
      }
 
      .toolBar {
         vertical-align: middle;
         border-bottom: 1px solid black;
      }
 
      html, body{
         width: 100%;
         height: 100%;
         background-color: #f0f0f0;
      }
 
      .canvas {
         width: 1024px;
         height: 768px;
         border: 1px dotted black;
      }
   </style>
 
</head>
<body>
   <div class="controlBarWrapper">
      <div class="titlebar">MTN FACTS</div>
      <div class="toolBar">
         <button id="cursorPointerBtn" class="toolBarButton">
            <img src="images/16x16_cursor.png"></img>
         </button>
         <button id="blockSelBtn" class="toolBarButton">
            <img src="images/16x16_block_sel.png"></img>
         </button>
         <span>&nbsp;|&nbsp;</span>
         <button id="alignLeftBtn" class="toolBarButton">
            <img src="images/16x16_shape_align_left.png"></img>
         </button>
         <button id="alignTopBtn" class="toolBarButton">
            <img src="images/16x16_shape_align_top.png"></img>
         </button>
         <button id="alignRightBtn" class="toolBarButton">
            <img src="images/16x16_shape_align_right.png"></img>
         </button>
         <button id="alignBottomBtn" class="toolBarButton">
            <img src="images/16x16_shape_align_bottom.png"></img>
         </button>
         <button id="alignCenterBtn" class="toolBarButton">
            <img src="images/16x16_shape_align_center.png"></img>
         </button>
         <button id="alignMiddleBtn" class="toolBarButton">
            <img src="images/16x16_shape_align_middle.png"></img>
         </button>
         <span>&nbsp;|&nbsp;</span>
         <button id="straightRouteBtn" class="toolBarButton">
            <img src="images/16x16_straightline.png"></img>
         </button>
         <button id="manhattanRouteBtn" class="toolBarButton">
            <img src="images/16x16_manhattan.png"></img>
         </button>
         <span>&nbsp;|&nbsp;</span>
         <button id="increasePageSizeBtn" class="toolBarButton">
            <img src="images/16x16_scaleout.png"></img>
         </button>
         <button id="decreasePageSizeBtn" class="toolBarButton">
            <img src="images/16x16_scalein.png"></img>
         </button>
         <button id="dynamicPageSizeBtn" class="toolBarButton">
            <img src="images/16x16_scalein.png" title="Scale Canvas"></img>
         </button>
          <button id="springLayoutBtn" class="toolBarButton" title="layout">
             <img src="images/16x16_layout.png" title="Apply Spring Layout"></img>
          </button>
          <button id="directedLayoutBtn" class="toolBarButton" title="layout">
             <img src="images/16x16_layout.png" title="Apply Directed Layout"></img>
          </button>
         <span>&nbsp;|&nbsp;</span>
         <button id="zoomInBtn" class="toolBarButton">
            <img src="images/16x16_zoom_in.png" title="Zoom In"></img>
         </button>
         <button id="zoomOutBtn" class="toolBarButton">
            <img src="images/16x16_zoom_out.png" title="Zoom Out"></img>
         </button>
         <span>&nbsp;|&nbsp;</span>
         <button id="delBtn" class="toolBarButton">
            <img src="images/16x16_delete.png"></img>
         </button>
         <button id="saveButton" class="toolBarButton">
            <img src="images/16x16_save.png"></img>
         </button>
      </div>
   </div>
   
   <div class="canvas-wrapper">
      <div class="canvas">
 
      </div>
   </div>
 
   <div id="itemCatalogue" title="Flow Item Catalogue">
   </div>
 
   <div id="nodeEditDialog" title="Node Edit Dialog">
   </div>
</body>
</html>