Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
dream
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
1
Issues
1
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
dream
Commits
e3e0d1ac
Commit
e3e0d1ac
authored
Jun 16, 2014
by
Thibaut Frain
Committed by
Jérome Perrin
Aug 11, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Made jsplumb gadget internal methods not redefined at each gadget declarations
parent
69f8884c
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
465 additions
and
465 deletions
+465
-465
dream/platform/src2/jsplumb/jsplumb.js
dream/platform/src2/jsplumb/jsplumb.js
+465
-465
No files found.
dream/platform/src2/jsplumb/jsplumb.js
View file @
e3e0d1ac
...
@@ -21,47 +21,141 @@
...
@@ -21,47 +21,141 @@
(
function
(
RSVP
,
rJS
,
$
,
jsPlumb
,
confirm
)
{
(
function
(
RSVP
,
rJS
,
$
,
jsPlumb
,
confirm
)
{
"
use strict
"
;
"
use strict
"
;
rJS
(
window
)
function
getNodeId
(
node_container
,
element_id
)
{
.
ready
(
function
(
g
)
{
g
.
private
=
{
getNodeId
:
function
(
element_id
)
{
var
node_id
;
var
node_id
;
$
.
each
(
g
.
private
.
node_container
,
function
(
k
,
v
)
{
$
.
each
(
node_container
,
function
(
k
,
v
)
{
if
(
v
.
element_id
===
element_id
)
{
if
(
v
.
element_id
===
element_id
)
{
node_id
=
k
;
node_id
=
k
;
return
false
;
return
false
;
}
}
});
});
return
node_id
;
return
node_id
;
},
}
getElementId
:
function
(
node_id
)
{
function
getElementId
(
node_container
,
node_id
)
{
return
g
.
private
.
node_container
[
node_id
].
element_id
;
return
node_container
[
node_id
].
element_id
;
},
}
generateNodeId
:
function
(
element_type
,
option
)
{
// function generateNodeId(node_container, element_type, option) {
var
n
=
1
;
// var n = 1;
while
(
g
.
private
.
node_container
[
// while (node_container[
((
option
.
short_id
||
element_type
)
+
n
)
// ((option.short_id || element_type) + n)
]
!==
undefined
)
{
// ] !== undefined) {
n
+=
1
;
// n += 1;
// }
// return (option.short_id || element_type) + n;
// }
// function generateElementId(gadget_element) {
// var n = 1;
// while ($(gadget_element).find('#DreamNode_' + n).length > 0) {
// n += 1;
// }
// return 'DreamNode_' + n;
// }
function
onDataChange
()
{
//$.publish("Dream.Gui.onDataChange", g.private.getData());
return
undefined
;
}
}
return
(
option
.
short_id
||
element_type
)
+
n
;
},
generateElementId
:
function
()
{
function
convertToAbsolutePosition
(
gadget
,
x
,
y
)
{
var
n
=
1
;
var
zoom_level
=
(
gadget
.
private
.
preference_container
.
zoom_level
||
1.0
)
*
while
(
$
(
g
.
private
.
element
).
find
(
'
#DreamNode_
'
+
n
).
length
>
0
)
{
1.1111
,
n
+=
1
;
canvas_size_x
=
$
(
gadget
.
private
.
element
).
find
(
'
#main
'
).
width
(),
canvas_size_y
=
$
(
gadget
.
private
.
element
).
find
(
'
#main
'
).
height
(),
size_x
=
$
(
gadget
.
private
.
element
).
find
(
'
.dummy_window
'
).
width
()
*
zoom_level
,
size_y
=
$
(
gadget
.
private
.
element
).
find
(
'
.dummy_window
'
).
height
()
*
zoom_level
,
top
=
Math
.
floor
(
y
*
(
canvas_size_y
-
size_y
))
+
"
px
"
,
left
=
Math
.
floor
(
x
*
(
canvas_size_x
-
size_x
))
+
"
px
"
;
return
[
left
,
top
];
}
function
convertToRelativePosition
(
gadget
,
x
,
y
)
{
var
zoom_level
=
(
gadget
.
private
.
preference_container
.
zoom_level
||
1.0
)
*
1.1111
,
canvas_size_x
=
$
(
gadget
.
private
.
element
).
find
(
'
#main
'
).
width
(),
canvas_size_y
=
$
(
gadget
.
private
.
element
).
find
(
'
#main
'
).
height
(),
size_x
=
$
(
gadget
.
private
.
element
).
find
(
'
.dummy_window
'
).
width
()
*
zoom_level
,
size_y
=
$
(
gadget
.
private
.
element
).
find
(
'
.dummy_window
'
).
height
()
*
zoom_level
,
top
=
Math
.
max
(
Math
.
min
(
y
.
replace
(
'
px
'
,
''
)
/
(
canvas_size_y
-
size_y
),
1
),
0
),
left
=
Math
.
max
(
Math
.
min
(
x
.
replace
(
'
px
'
,
''
)
/
(
canvas_size_x
-
size_x
),
1
),
0
);
return
[
left
,
top
];
}
}
return
'
DreamNode_
'
+
n
;
},
initJsPlumb
:
function
()
{
function
updateElementCoordinate
(
gadget
,
node_id
,
coordinate
)
{
g
.
private
.
jsplumb_instance
.
setRenderMode
(
var
element_id
=
gadget
.
private
.
node_container
[
node_id
].
element_id
,
g
.
private
.
jsplumb_instance
.
SVG
coordinates
=
gadget
.
private
.
preference_container
.
coordinates
||
{},
element
,
relative_position
;
if
(
coordinate
===
undefined
)
{
coordinate
=
{};
element
=
$
(
gadget
.
private
.
element
).
find
(
"
#
"
+
element_id
);
relative_position
=
convertToRelativePosition
(
gadget
,
element
.
css
(
'
left
'
),
element
.
css
(
'
top
'
)
);
);
g
.
private
.
jsplumb_instance
.
importDefaults
({
coordinate
.
top
=
relative_position
[
1
];
coordinate
.
left
=
relative_position
[
0
];
}
coordinates
[
node_id
]
=
coordinate
;
gadget
.
private
.
preference_container
.
coordinates
=
coordinates
;
onDataChange
();
return
coordinate
;
}
function
draggable
(
gadget
)
{
var
jsplumb_instance
=
gadget
.
private
.
jsplumb_instance
,
stop
=
function
(
element
)
{
updateElementCoordinate
(
gadget
,
getNodeId
(
gadget
.
private
.
node_container
,
element
.
target
.
id
));
};
jsplumb_instance
.
draggable
(
jsplumb_instance
.
getSelector
(
"
.window
"
),
{
containment
:
'
parent
'
,
grid
:
[
10
,
10
],
stop
:
stop
// FIXME: we should only accept if dropped in #main
});
jsplumb_instance
.
makeSource
(
jsplumb_instance
.
getSelector
(
"
.window
"
),
{
filter
:
"
.ep
"
,
anchor
:
"
Continuous
"
,
connector
:
[
"
StateMachine
"
,
{
curviness
:
20
}],
connectorStyle
:
{
strokeStyle
:
"
#5c96bc
"
,
lineWidth
:
2
,
outlineColor
:
"
transparent
"
,
outlineWidth
:
4
}
});
jsplumb_instance
.
makeTarget
(
jsplumb_instance
.
getSelector
(
"
.window
"
),
{
dropOptions
:
{
hoverClass
:
"
dragHover
"
},
anchor
:
"
Continuous
"
});
}
function
initJsPlumb
(
gadget
)
{
var
jsplumb_instance
=
gadget
.
private
.
jsplumb_instance
;
jsplumb_instance
.
setRenderMode
(
jsplumb_instance
.
SVG
);
jsplumb_instance
.
importDefaults
({
HoverPaintStyle
:
{
HoverPaintStyle
:
{
strokeStyle
:
"
#1e8151
"
,
strokeStyle
:
"
#1e8151
"
,
lineWidth
:
2
lineWidth
:
2
...
@@ -82,292 +176,201 @@
...
@@ -82,292 +176,201 @@
// listen for clicks on connections,
// listen for clicks on connections,
// and offer to change values on click.
// and offer to change values on click.
g
.
private
.
jsplumb_instance
.
bind
(
"
click
"
,
function
(
conn
)
{
jsplumb_instance
.
bind
(
"
click
"
,
function
(
conn
)
{
g
.
private
.
jsplumb_instance
.
detach
(
conn
);
jsplumb_instance
.
detach
(
conn
);
});
});
g
.
private
.
jsplumb_instance
.
bind
(
"
beforeDetach
"
,
function
(
conn
)
{
jsplumb_instance
.
bind
(
"
beforeDetach
"
,
function
(
conn
)
{
return
confirm
(
"
Delete connection?
"
);
return
confirm
(
"
Delete connection?
"
);
});
});
g
.
private
.
jsplumb_instance
jsplumb_instance
.
bind
(
"
connectionDrag
"
,
function
(
connection
)
{
.
bind
(
"
connectionDrag
"
,
function
(
connection
)
{
return
undefined
;
return
undefined
;
});
});
g
.
private
.
jsplumb_instance
jsplumb_instance
.
bind
(
"
connectionDragStop
"
,
function
(
connection
)
{
.
bind
(
"
connectionDragStop
"
,
function
(
connection
)
{
return
undefined
;
return
undefined
;
});
});
// split in 2 methods ? one for events one for manip
// split in 2 methods ? one for events one for manip
g
.
private
.
updateConnectionData
gadget
.
private
.
updateConnectionData
=
function
(
connection
,
remove
,
edge_data
)
{
=
function
(
connection
,
remove
,
edge_data
)
{
if
(
remove
)
{
if
(
remove
)
{
delete
g
.
private
.
edge_container
[
connection
.
id
];
delete
gadget
.
private
.
edge_container
[
connection
.
id
];
}
else
{
}
else
{
g
.
private
.
edge_container
[
connection
.
id
]
=
[
gadget
.
private
.
edge_container
[
connection
.
id
]
=
[
g
.
private
.
getNodeId
(
connection
.
sourceId
),
getNodeId
(
gadget
.
private
.
node_container
,
connection
.
sourceId
),
g
.
private
.
getNodeId
(
connection
.
targetId
),
edge_data
||
{}
getNodeId
(
gadget
.
private
.
node_container
,
connection
.
targetId
),
edge_data
||
{}
];
];
}
}
g
.
private
.
onDataChange
();
onDataChange
();
};
};
// bind to connection/connectionDetached events,
// bind to connection/connectionDetached events,
// and update the list of connections on screen.
// and update the list of connections on screen.
g
.
private
.
jsplumb_instance
jsplumb_instance
.
bind
(
"
connection
"
,
function
(
info
,
originalEvent
)
{
.
bind
(
"
connection
"
,
function
(
info
,
originalEvent
)
{
g
.
private
.
updateConnectionData
(
info
.
connection
);
gadget
.
private
.
updateConnectionData
(
info
.
connection
);
});
});
g
.
private
.
jsplumb_instance
jsplumb_instance
.
bind
(
"
connectionDetached
"
,
function
(
info
,
originalEvent
)
{
.
bind
(
"
connectionDetached
"
,
function
(
info
,
originalEvent
)
{
g
.
private
.
updateConnectionData
(
info
.
connection
,
true
);
gadget
.
private
.
updateConnectionData
(
info
.
connection
,
true
);
});
});
g
.
private
.
onDataChange
();
onDataChange
();
g
.
private
.
draggable
();
draggable
(
gadget
);
},
updateElementCoordinate
:
function
(
node_id
,
coordinate
)
{
var
element_id
=
g
.
private
.
node_container
[
node_id
].
element_id
,
coordinates
=
g
.
private
.
preference_container
.
coordinates
||
{},
element
,
relative_position
;
if
(
coordinate
===
undefined
)
{
coordinate
=
{};
element
=
$
(
g
.
private
.
element
).
find
(
"
#
"
+
element_id
);
relative_position
=
g
.
private
.
convertToRelativePosition
(
element
.
css
(
'
left
'
),
element
.
css
(
'
top
'
)
);
coordinate
.
top
=
relative_position
[
1
];
coordinate
.
left
=
relative_position
[
0
];
}
}
coordinates
[
node_id
]
=
coordinate
;
g
.
private
.
preference_container
.
coordinates
=
coordinates
;
g
.
private
.
onDataChange
();
return
coordinate
;
},
updateNodeStyle
:
function
(
element_id
)
{
function
updateNodeStyle
(
gadget
,
element_id
)
{
var
zoom_level
=
(
g
.
private
.
preference_container
.
zoom_level
||
1.0
)
*
var
zoom_level
=
(
gadget
.
private
.
preference_container
.
zoom_level
||
1.0
)
*
1.1111
,
1.1111
,
element
=
$
(
g
.
private
.
element
).
find
(
"
#
"
+
element_id
),
element
=
$
(
gadget
.
private
.
element
).
find
(
"
#
"
+
element_id
),
new_value
;
new_value
;
$
.
each
(
g
.
private
.
style_attr_list
,
function
(
i
,
j
)
{
$
.
each
(
gadget
.
private
.
style_attr_list
,
function
(
i
,
j
)
{
new_value
=
$
(
g
.
private
.
element
).
find
(
'
.dummy_window
'
).
css
(
j
)
new_value
=
$
(
gadget
.
private
.
element
).
find
(
'
.dummy_window
'
).
css
(
j
)
.
replace
(
'
px
'
,
''
)
*
zoom_level
+
'
px
'
;
.
replace
(
'
px
'
,
''
)
*
zoom_level
+
'
px
'
;
element
.
css
(
j
,
new_value
);
element
.
css
(
j
,
new_value
);
});
});
},
convertToAbsolutePosition
:
function
(
x
,
y
)
{
var
zoom_level
=
(
g
.
private
.
preference_container
.
zoom_level
||
1.0
)
*
1.1111
,
canvas_size_x
=
$
(
g
.
private
.
element
).
find
(
'
#main
'
).
width
(),
canvas_size_y
=
$
(
g
.
private
.
element
).
find
(
'
#main
'
).
height
(),
size_x
=
$
(
g
.
private
.
element
).
find
(
'
.dummy_window
'
).
width
()
*
zoom_level
,
size_y
=
$
(
g
.
private
.
element
).
find
(
'
.dummy_window
'
).
height
()
*
zoom_level
,
top
=
Math
.
floor
(
y
*
(
canvas_size_y
-
size_y
))
+
"
px
"
,
left
=
Math
.
floor
(
x
*
(
canvas_size_x
-
size_x
))
+
"
px
"
;
return
[
left
,
top
];
},
convertToRelativePosition
:
function
(
x
,
y
)
{
var
zoom_level
=
(
g
.
private
.
preference_container
.
zoom_level
||
1.0
)
*
1.1111
,
canvas_size_x
=
$
(
g
.
private
.
element
).
find
(
'
#main
'
).
width
(),
canvas_size_y
=
$
(
g
.
private
.
element
).
find
(
'
#main
'
).
height
(),
size_x
=
$
(
g
.
private
.
element
).
find
(
'
.dummy_window
'
).
width
()
*
zoom_level
,
size_y
=
$
(
g
.
private
.
element
).
find
(
'
.dummy_window
'
).
height
()
*
zoom_level
,
top
=
Math
.
max
(
Math
.
min
(
y
.
replace
(
'
px
'
,
''
)
/
(
canvas_size_y
-
size_y
),
1
),
0
),
left
=
Math
.
max
(
Math
.
min
(
x
.
replace
(
'
px
'
,
''
)
/
(
canvas_size_x
-
size_x
),
1
),
0
);
return
[
left
,
top
];
},
draggable
:
function
()
{
var
stop
=
function
(
element
)
{
g
.
private
.
updateElementCoordinate
(
g
.
private
.
getNodeId
(
element
.
target
.
id
));
};
g
.
private
.
jsplumb_instance
.
draggable
(
g
.
private
.
jsplumb_instance
.
getSelector
(
"
.window
"
),
{
containment
:
'
parent
'
,
grid
:
[
10
,
10
],
stop
:
stop
// FIXME: we should only accept if dropped in #main
});
g
.
private
.
jsplumb_instance
.
makeSource
(
g
.
private
.
jsplumb_instance
.
getSelector
(
"
.window
"
),
{
filter
:
"
.ep
"
,
anchor
:
"
Continuous
"
,
connector
:
[
"
StateMachine
"
,
{
curviness
:
20
}],
connectorStyle
:
{
strokeStyle
:
"
#5c96bc
"
,
lineWidth
:
2
,
outlineColor
:
"
transparent
"
,
outlineWidth
:
4
}
}
});
g
.
private
.
jsplumb_instance
function
addElementToContainer
(
node_container
,
element
)
{
.
makeTarget
(
g
.
private
.
jsplumb_instance
.
getSelector
(
"
.window
"
),
{
dropOptions
:
{
hoverClass
:
"
dragHover
"
},
anchor
:
"
Continuous
"
});
},
addElementToContainer
:
function
(
element
)
{
// Now update the container of elements
// Now update the container of elements
/*jslint nomen: true*/
/*jslint nomen: true*/
var
element_data
=
{
var
element_data
=
{
_class
:
element
.
_class
,
_class
:
element
.
_class
,
element_id
:
element
.
element_id
element_id
:
element
.
element_id
};
};
g
.
private
.
node_container
[
element
.
id
]
=
element_data
;
node_container
[
element
.
id
]
=
element_data
;
},
onDataChange
:
function
()
{
//$.publish("Dream.Gui.onDataChange", g.private.getData());
return
undefined
;
},
style_attr_list
:
[
'
width
'
,
'
height
'
,
'
padding-top
'
,
'
line-height
'
],
positionGraph
:
function
()
{
$
.
ajax
(
'
/positionGraph
'
,
{
data
:
JSON
.
stringify
(
g
.
private
.
getData
()),
contentType
:
'
application/json
'
,
type
:
'
POST
'
,
success
:
function
(
data
,
textStatus
,
jqXHR
)
{
$
.
each
(
data
,
function
(
node
,
pos
)
{
g
.
private
.
convertToAbsolutePosition
(
pos
.
left
,
pos
.
top
);
g
.
private
.
updateElementCoordinate
(
node
,
{
top
:
pos
.
top
,
left
:
pos
.
left
});
});
g
.
private
.
redraw
();
}
}
}
);
},
setZoom
:
function
(
zoom_level
)
{
// function getData(gadget) {
$
.
each
(
g
.
private
.
style_attr_list
,
function
(
i
,
j
)
{
// var data = {
var
new_value
=
$
(
g
.
private
.
element
).
find
(
'
.dummy_window
'
)
// "nodes": gadget.private.node_container,
.
css
(
j
).
replace
(
'
px
'
,
''
)
*
zoom_level
+
'
px
'
;
// "edges": gadget.private.edge_container,
$
(
g
.
private
.
element
).
find
(
'
.window
'
).
css
(
j
,
new_value
);
// "preference": gadget.private.preference_container,
});
// "general": gadget.private.general_container
},
// },
// wip_spreadsheet = $(gadget.private.element).find('#wip_spreadsheet'),
zoom_in
:
function
()
{
// wip_part_spreadsheet = $(gadget.private.element)
var
zoom_level
=
(
g
.
private
.
preference_container
.
zoom_level
||
1.0
)
*
// .find('#wip_part_spreadsheet'),
1.1111
;
// shift_spreadsheet = $(gadget.private.element)
g
.
private
.
setZoom
(
zoom_level
);
// .find('#shift_spreadsheet');
g
.
private
.
preference_container
.
zoom_level
=
zoom_level
;
// if (wip_spreadsheet.length > 0) {
g
.
private
.
onDataChange
();
// data.wip_spreadsheet = wip_spreadsheet.handsontable('getData');
g
.
private
.
redraw
();
// }
},
// if (wip_part_spreadsheet.length > 0) {
// data.wip_part_spreadsheet = wip_part_spreadsheet
zoom_out
:
function
()
{
// .handsontable('getData');
var
zoom_level
=
(
g
.
private
.
preference_container
.
zoom_level
||
1.0
)
*
// }
0.9
;
// if (shift_spreadsheet.length > 0) {
g
.
private
.
setZoom
(
zoom_level
);
// data.shift_spreadsheet = shift_spreadsheet.handsontable('getData');
g
.
private
.
preference_container
.
zoom_level
=
zoom_level
;
// }
g
.
private
.
onDataChange
();
// return data;
g
.
private
.
redraw
();
// }
},
function
redraw
(
gadget
)
{
redraw
:
function
()
{
var
coordinates
=
gadget
.
private
.
preference_container
.
coordinates
||
{},
var
coordinates
=
g
.
private
.
preference_container
.
coordinates
||
{},
absolute_position
,
absolute_position
,
element
;
element
;
$
.
each
(
coordinates
,
function
(
node_id
,
v
)
{
$
.
each
(
coordinates
,
function
(
node_id
,
v
)
{
absolute_position
=
g
.
private
.
convertToAbsolutePosition
(
absolute_position
=
convertToAbsolutePosition
(
gadget
,
v
.
left
,
v
.
left
,
v
.
top
v
.
top
);
);
element
=
$
(
g
.
private
.
element
).
find
(
'
#
'
+
g
.
private
.
getElementI
d
(
element
=
$
(
gadget
.
private
.
element
).
fin
d
(
node_id
'
#
'
+
getElementId
(
gadget
.
private
.
node_container
,
node_id
)
)
);
);
element
.
css
(
'
top
'
,
absolute_position
[
1
]);
element
.
css
(
'
top
'
,
absolute_position
[
1
]);
element
.
css
(
'
left
'
,
absolute_position
[
0
]);
element
.
css
(
'
left
'
,
absolute_position
[
0
]);
g
.
private
.
jsplumb_instance
.
repaint
(
element
);
gadget
.
private
.
jsplumb_instance
.
repaint
(
element
);
});
});
},
getData
:
function
()
{
var
data
=
{
"
nodes
"
:
g
.
private
.
node_container
,
"
edges
"
:
g
.
private
.
edge_container
,
"
preference
"
:
g
.
private
.
preference_container
,
"
general
"
:
g
.
private
.
general_container
},
wip_spreadsheet
=
$
(
g
.
private
.
element
).
find
(
'
#wip_spreadsheet
'
),
wip_part_spreadsheet
=
$
(
g
.
private
.
element
)
.
find
(
'
#wip_part_spreadsheet
'
),
shift_spreadsheet
=
$
(
g
.
private
.
element
)
.
find
(
'
#shift_spreadsheet
'
);
if
(
wip_spreadsheet
.
length
>
0
)
{
data
.
wip_spreadsheet
=
wip_spreadsheet
.
handsontable
(
'
getData
'
);
}
}
if
(
wip_part_spreadsheet
.
length
>
0
)
{
data
.
wip_part_spreadsheet
=
wip_part_spreadsheet
.
handsontable
(
'
getData
'
);
}
if
(
shift_spreadsheet
.
length
>
0
)
{
data
.
shift_spreadsheet
=
shift_spreadsheet
.
handsontable
(
'
getData
'
);
}
return
data
;
},
removeElement
:
function
(
node_id
)
{
// function positionGraph(gadget) {
var
element_id
=
g
.
private
.
node_container
[
node_id
].
element_id
;
// $.ajax(
g
.
private
.
jsplumb_instance
.
removeAllEndpoints
(
$
(
g
.
private
.
element
)
// '/positionGraph',
.
find
(
"
#
"
+
element_id
));
// {
$
(
g
.
private
.
element
).
find
(
"
#
"
+
element_id
).
remove
();
// data: JSON.stringify(getData()),
delete
g
.
private
.
node_container
[
node_id
];
// contentType: 'application/json',
delete
g
.
private
.
preference_container
.
coordinates
[
node_id
];
// type: 'POST',
$
.
each
(
g
.
private
.
edge_container
,
function
(
k
,
v
)
{
// success: function (data, textStatus, jqXHR) {
if
(
node_id
===
v
[
0
]
||
node_id
===
v
[
1
])
{
// $.each(data, function (node, pos) {
delete
g
.
private
.
edge_container
[
k
];
// convertToAbsolutePosition(
}
// gadget,
});
// pos.left,
g
.
private
.
onDataChange
();
// pos.top
},
// );
// updateElementCoordinate(gadget, node, {
updateElementData
:
function
(
node_id
,
data
)
{
// top: pos.top,
var
element_id
=
g
.
private
.
node_container
[
node_id
].
element_id
,
// left: pos.left
// });
// });
// redraw(gadget);
// }
// }
// );
// }
// function setZoom(gadget, zoom_level) {
// $.each(gadget.private.style_attr_list, function (i, j) {
// var new_value = $(gadget.private.element).find('.dummy_window')
// .css(j).replace('px', '') * zoom_level + 'px';
// $(gadget.private.element).find('.window').css(j, new_value);
// });
// }
// function zoom_in(gadget) {
// var zoom_level = (gadget.private.preference_container.zoom_level || 1.0) *
// 1.1111;
// setZoom(gadget, zoom_level);
// gadget.private.preference_container.zoom_level = zoom_level;
// onDataChange();
// redraw(gadget);
// }
// function zoom_out(gadget) {
// var zoom_level = (gadget.private.preference_container.zoom_level || 1.0) *
// 0.9;
// setZoom(gadget, zoom_level);
// gadget.private.preference_container.zoom_level = zoom_level;
// onDataChange();
// redraw(gadget);
// }
// function removeElement(gadget, node_id) {
// var element_id = gadget.private.node_container[node_id].element_id;
// gadget.private.jsplumb_instance.removeAllEndpoints(
// $(gadget.private.element).find("#" + element_id)
// );
// $(gadget.private.element).find("#" + element_id).remove();
// delete gadget.private.node_container[node_id];
// delete gadget.private.preference_container.coordinates[node_id];
// $.each(gadget.private.edge_container, function (k, v) {
// if (node_id === v[0] || node_id === v[1]) {
// delete gadget.private.edge_container[k];
// }
// });
// onDataChange();
// }
function
updateElementData
(
gadget
,
node_id
,
data
)
{
var
element_id
=
gadget
.
private
.
node_container
[
node_id
].
element_id
,
new_id
=
data
.
id
;
new_id
=
data
.
id
;
if
(
data
.
name
)
{
if
(
data
.
name
)
{
$
(
g
.
private
.
element
).
find
(
"
#
"
+
element_id
).
text
(
data
.
name
)
$
(
gadget
.
private
.
element
).
find
(
"
#
"
+
element_id
).
text
(
data
.
name
)
.
append
(
'
<div class="ep"></div></div>
'
);
.
append
(
'
<div class="ep"></div></div>
'
);
g
.
private
.
node_container
[
node_id
].
name
=
data
.
name
;
gadget
.
private
.
node_container
[
node_id
].
name
=
data
.
name
;
}
}
delete
data
.
id
;
delete
data
.
id
;
$
.
extend
(
g
.
private
.
node_container
[
node_id
],
data
.
data
);
$
.
extend
(
gadget
.
private
.
node_container
[
node_id
],
data
.
data
);
if
(
new_id
&&
new_id
!==
node_id
)
{
if
(
new_id
&&
new_id
!==
node_id
)
{
g
.
private
.
node_container
[
new_id
]
gadget
.
private
.
node_container
[
new_id
]
=
g
.
private
.
node_container
[
node_id
];
=
gadget
.
private
.
node_container
[
node_id
];
delete
g
.
private
.
node_container
[
node_id
];
delete
gadget
.
private
.
node_container
[
node_id
];
$
.
each
(
g
.
private
.
edge_container
,
function
(
k
,
v
)
{
$
.
each
(
gadget
.
private
.
edge_container
,
function
(
k
,
v
)
{
if
(
v
[
0
]
===
node_id
)
{
if
(
v
[
0
]
===
node_id
)
{
v
[
0
]
=
new_id
;
v
[
0
]
=
new_id
;
}
}
...
@@ -375,36 +378,28 @@
...
@@ -375,36 +378,28 @@
v
[
1
]
=
new_id
;
v
[
1
]
=
new_id
;
}
}
});
});
g
.
private
.
preference_container
.
coordinates
[
new_id
]
gadget
.
private
.
preference_container
.
coordinates
[
new_id
]
=
g
.
private
.
preference_container
.
coordinates
[
node_id
];
=
gadget
.
private
.
preference_container
.
coordinates
[
node_id
];
delete
g
.
private
.
preference_container
.
coordinates
[
node_id
];
delete
gadget
.
private
.
preference_container
.
coordinates
[
node_id
];
}
onDataChange
();
}
}
g
.
private
.
onDataChange
();
},
start
:
function
()
{
g
.
private
.
node_container
=
{};
g
.
private
.
edge_container
=
{};
g
.
private
.
preference_container
=
{};
g
.
private
.
general_container
=
{};
g
.
private
.
initJsPlumb
();
},
clearAll
:
function
()
{
$
.
each
(
g
.
private
.
node_container
,
function
(
node_id
)
{
g
.
private
.
removeElement
(
node_id
);
});
// delete anything if still remains
$
(
g
.
private
.
element
).
find
(
"
#main
"
).
children
().
remove
();
g
.
private
.
node_container
=
{};
g
.
private
.
edge_container
=
{};
g
.
private
.
preference_container
=
{};
g
.
private
.
general_container
=
{};
g
.
private
.
initGeneralProperties
();
g
.
private
.
prepareDialogForGeneralProperties
();
},
addEdge
:
function
(
edge_id
,
edge_data
)
{
// function clearAll(gadget) {
// $.each(gadget.private.node_container, function (node_id) {
// removeElement(gadget, node_id);
// });
// // delete anything if still remains
// $(gadget.private.element).find("#main").children().remove();
// gadget.private.node_container = {};
// gadget.private.edge_container = {};
// gadget.private.preference_container = {};
// gadget.private.general_container = {};
// gadget.private.initGeneralProperties();
// gadget.private.prepareDialogForGeneralProperties();
// }
function
addEdge
(
gadget
,
edge_id
,
edge_data
)
{
var
source_id
=
edge_data
[
0
],
var
source_id
=
edge_data
[
0
],
target_id
=
edge_data
[
1
],
target_id
=
edge_data
[
1
],
data
=
edge_data
[
2
],
data
=
edge_data
[
2
],
...
@@ -416,43 +411,43 @@
...
@@ -416,43 +411,43 @@
label
:
data
.
title
label
:
data
.
title
}]];
}]];
}
}
connection
=
g
.
private
.
jsplumb_instance
.
connect
({
connection
=
gadget
.
private
.
jsplumb_instance
.
connect
({
source
:
g
.
private
.
getElementId
(
source_id
),
source
:
getElementId
(
gadget
.
private
.
node_container
,
source_id
),
target
:
g
.
private
.
getElementId
(
target_id
),
target
:
getElementId
(
gadget
.
private
.
node_container
,
target_id
),
Connector
:
[
"
Bezier
"
,
{
curviness
:
75
}
],
Connector
:
[
"
Bezier
"
,
{
curviness
:
75
}
],
overlays
:
overlays
overlays
:
overlays
});
});
// call again updateConnectionData to set the connection data that
// call again updateConnectionData to set the connection data that
// was not passed to the connection hook
// was not passed to the connection hook
g
.
private
.
updateConnectionData
(
connection
,
0
,
data
);
gadget
.
private
.
updateConnectionData
(
connection
,
0
,
data
);
},
}
setPreferences
:
function
(
preferences
)
{
// function setPreferences(gadget,
preferences) {
g
.
private
.
preference_container
=
preferences
;
// gadget
.private.preference_container = preferences;
var
zoom_level
=
g
.
private
.
preference_container
.
zoom_level
||
1.0
;
// var zoom_level = gadget
.private.preference_container.zoom_level || 1.0;
g
.
private
.
setZoom
(
zoom_level
);
// setZoom(gadget,
zoom_level);
},
// }
setGeneralProperties
:
function
(
properties
)
{
// function setGeneralProperties(gadget,
properties) {
g
.
private
.
general_container
=
properties
;
// gadget
.private.general_container = properties;
g
.
private
.
onDataChange
();
//
onDataChange();
},
// }
updateGeneralProperties
:
function
(
properties
)
{
// function updateGeneralProperties(gadget,
properties) {
$
.
extend
(
g
.
private
.
general_container
,
properties
);
// $.extend(gadget
.private.general_container, properties);
g
.
private
.
onDataChange
();
//
onDataChange();
},
// }
newElement
:
function
(
element
,
option
)
{
function
newElement
(
gadget
,
element
,
option
)
{
element
.
name
=
element
.
name
||
option
.
name
;
element
.
name
=
element
.
name
||
option
.
name
;
g
.
private
.
addElementToContainer
(
element
);
addElementToContainer
(
gadget
.
private
.
node_container
,
element
);
var
render_element
,
var
render_element
=
$
(
gadget
.
private
.
element
).
find
(
"
#main
"
)
,
coordinate
=
element
.
coordinate
,
coordinate
=
element
.
coordinate
,
box
,
box
,
absolute_position
;
absolute_position
;
render_element
=
$
(
g
.
private
.
element
).
find
(
"
#main
"
);
if
(
coordinate
!==
undefined
)
{
if
(
coordinate
!==
undefined
)
{
coordinate
=
g
.
private
.
updateElementCoordinate
(
coordinate
=
updateElementCoordinate
(
gadget
,
element
.
id
,
element
.
id
,
coordinate
coordinate
);
);
...
@@ -464,25 +459,28 @@
...
@@ -464,25 +459,28 @@
(
element
.
name
||
element
.
id
)
+
'
">
'
+
(
element
.
name
||
element
.
id
)
+
'
">
'
+
element
.
id
+
element
.
id
+
'
<div class="ep"></div></div>
'
);
'
<div class="ep"></div></div>
'
);
box
=
$
(
g
.
private
.
element
).
find
(
"
#
"
+
element
.
element_id
);
box
=
$
(
gadget
.
private
.
element
).
find
(
"
#
"
+
element
.
element_id
);
absolute_position
=
g
.
private
.
convertToAbsolutePosition
(
absolute_position
=
convertToAbsolutePosition
(
gadget
,
coordinate
.
left
,
coordinate
.
left
,
coordinate
.
top
coordinate
.
top
);
);
box
.
css
(
"
top
"
,
absolute_position
[
1
]);
box
.
css
(
"
top
"
,
absolute_position
[
1
]);
box
.
css
(
"
left
"
,
absolute_position
[
0
]);
box
.
css
(
"
left
"
,
absolute_position
[
0
]);
g
.
private
.
updateNodeStyle
(
element
.
element_id
);
updateNodeStyle
(
gadget
,
element
.
element_id
);
g
.
private
.
draggable
(
);
draggable
(
gadget
);
g
.
private
.
onDataChange
();
onDataChange
();
}
}
};
})
rJS
(
window
)
.
ready
(
function
(
g
)
{
.
ready
(
function
(
g
)
{
window
.
g
=
g
;
g
.
private
=
{
return
g
.
getElement
(
function
(
el
)
{
node_container
:
{},
g
.
private
.
element
=
el
;
edge_container
:
{},
});
preference_container
:
{},
general_container
:
{},
style_attr_list
:
[
'
width
'
,
'
height
'
,
'
padding-top
'
,
'
line-height
'
]
};
})
})
.
declareMethod
(
'
render
'
,
function
(
data
)
{
.
declareMethod
(
'
render
'
,
function
(
data
)
{
...
@@ -491,15 +489,16 @@
...
@@ -491,15 +489,16 @@
})
})
.
declareMethod
(
'
startService
'
,
function
()
{
.
declareMethod
(
'
startService
'
,
function
()
{
var
g
=
this
;
var
gadget
=
this
,
return
this
.
getElement
()
preference
=
gadget
.
private
.
data
.
preference
!==
undefined
?
.
push
(
function
(
element
)
{
gadget
.
private
.
data
.
preference
:
{},
g
.
private
.
element
=
element
;
g
.
private
.
start
();
var
preference
=
g
.
private
.
data
.
preference
!==
undefined
?
g
.
private
.
data
.
preference
:
{},
coordinates
=
preference
.
coordinates
;
coordinates
=
preference
.
coordinates
;
$
.
each
(
g
.
private
.
data
.
nodes
,
function
(
key
,
value
)
{
return
gadget
.
getElement
()
.
push
(
function
(
el
)
{
gadget
.
private
.
element
=
el
;
initJsPlumb
(
gadget
);
$
.
each
(
gadget
.
private
.
data
.
nodes
,
function
(
key
,
value
)
{
if
(
coordinates
===
undefined
||
coordinates
[
key
]
===
undefined
)
{
if
(
coordinates
===
undefined
||
coordinates
[
key
]
===
undefined
)
{
value
.
coordinate
=
{
value
.
coordinate
=
{
'
top
'
:
0.0
,
'
top
'
:
0.0
,
...
@@ -509,24 +508,25 @@
...
@@ -509,24 +508,25 @@
value
.
coordinate
=
coordinates
[
key
];
value
.
coordinate
=
coordinates
[
key
];
}
}
value
.
id
=
key
;
value
.
id
=
key
;
g
.
private
.
newElement
(
value
);
newElement
(
gadget
,
value
);
if
(
value
.
data
)
{
// backward compatibility
if
(
value
.
data
)
{
// backward compatibility
g
.
private
.
updateElementData
(
key
,
{
updateElementData
(
gadget
,
key
,
{
data
:
value
.
data
data
:
value
.
data
});
});
}
}
});
});
$
.
each
(
g
.
private
.
data
.
edges
,
function
(
key
,
value
)
{
$
.
each
(
g
adget
.
private
.
data
.
edges
,
function
(
key
,
value
)
{
g
.
private
.
addEdge
(
key
,
value
);
addEdge
(
gadget
,
key
,
value
);
});
});
g
.
private
.
redraw
(
);
redraw
(
gadget
);
})
})
.
push
(
function
()
{
.
push
(
function
()
{
// Infinite wait, until cancelled
// Infinite wait, until cancelled
return
new
RSVP
.
defer
().
promise
;
return
new
RSVP
.
defer
().
promise
;
})
})
.
push
(
undefined
,
function
(
error
)
{
.
push
(
undefined
,
function
(
error
)
{
$
(
g
.
private
.
element
).
find
(
"
#main
"
).
html
(
""
);
$
(
g
adget
.
private
.
element
).
find
(
"
#main
"
).
html
(
""
);
throw
error
;
throw
error
;
});
});
});
});
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment