7 var conexion_selecionada = null;
8 var objeto_selecionado = null;
10 var arrow_style = "Straight";
12 $( "#sortable-element li" ).draggable({
15 return $("<ul class='sortable-element'></ul>").append( $(this).clone() );
19 $( "#editor" ).droppable({
20 accept: "#sortable-element li",
21 drop: function(event,ui){
24 var type = $(ui.draggable).attr('attr-type');
25 var clase = 'diagrama';
46 //objeto_selecionado = this;
49 getItemsList(count,nodetype);
52 input = "<span> Node-"+count+"</span>"+
53 "<div class='connect'></div>";
55 $(" <div style='"+posicion_drop(ui)+"' id='"+count+"' class='objeto "+clase+"'></div> ").append(input).appendTo(this);
61 $("body").on('dblclick','.objeto span',function(){
62 var texto = prompt("Title");
63 //var text2 = prompt("Title2");
66 $("body").on('click','#editor',function(){
70 /*$(document).bind("contextmenu", function(event) {
71 event.preventDefault();
72 $("<div class='custom-menu'>Custom menu</div>")
74 .css({top: event.pageY + "px", left: event.pageX + "px"});
75 }).bind("click", function(event) {
76 $("div.custom-menu").hide();
79 // Trigger action when the contexmenu is about to be shown
80 $("body").on("contextmenu",'.objeto', function (event) {
81 objeto_selecionado = this;
83 readItemsList(this.id);
86 event.preventDefault();
89 $("#cssmenu").finish().toggle(100).
91 // In the right position (the mouse)
94 top: event.pageY-150 + "px",
95 left: event.pageX-450 + "px"
102 // If the document is clicked somewhere
103 $("body").bind("mousedown",'.objeto', function (e) {
105 // If the clicked element is not the menu
106 if (!$(e.target).parents("#cssmenu").length > 0) {
109 $("#cssmenu").hide(100);
114 // If the menu element is clicked
115 $("#cssmenu li").click(function(){
117 // This is the triggered action name
118 switch($(this).attr("data-action")) {
120 // A case for each action. Your actions here
121 case "first":document.getElementById('testbet').value="";getItemsList(gid); break;
122 case "second":document.getElementById('testbet').value="omf:netmode";getItemsList(gid); break;
123 case "third": alert("third"); break;
126 // Hide it AFTER the action was triggered
127 $("#cssmenu").hide(100);
130 $("body").on('dblclick','.objeto',function(){
132 $( "#menu" ).offset({ top: -10, left: -10 });
133 //console.log(this.name);
134 console.log(this.offsetTop);
135 var t = this.offsetTop;
136 var l = this.offsetLeft;
137 //var x = $(this.name).position();
138 //console.log(x.top);
139 $( "#menu" ).offset({ top: t, left: l });
144 $("body").on('click','.objeto',function(){
145 $('.objeto').contextMenu(menu);
146 objeto_selecionado = this;
149 //getItemsList(this.id);
156 workflow = function(){
158 jsPlumb.importDefaults({
159 Endpoint : ["Dot", {radius:2}],
160 HoverPaintStyle : {strokeStyle:"#1e8151", lineWidth:0 },
164 windows = jsPlumb.getSelector('.objeto');
166 jsPlumb.makeSource(windows, {
170 connector:[ arrow_style, { curviness:63 } ],
172 strokeStyle:"#5c96bc",
174 outlineColor:"transparent",
178 [ "Label", { label:"", id:"label" } ]
181 dropOptions : targetDropOptions
185 jsPlumb.makeTarget(windows, {
186 dropOptions:{ hoverClass:"dragHover" },
191 var targetDropOptions = {
193 hoverClass:'dropHover',
194 activeClass:'dragActive'
201 jsPlumb.bind("click", function(conn, originalEvent) {
202 conexion_selecionada = conn;
209 posicion_drop = function(ui){
210 var top = parseInt(ui.position['top'], 10) - 250;
211 var left = parseInt(ui.position['left'], 10) - 560;
212 var style = 'position:absolute;top:' + top + 'px;left:' + left + 'px;'
218 $(document).keyup(function(e){
220 if(conexion_selecionada != null){
221 jsPlumb.detach(conexion_selecionada);
222 conexion_selecionada = null;
226 if(objeto_selecionado != null){
227 jsPlumb.remove(objeto_selecionado);
228 resetForm('',objeto_selecionado.id);
229 console.log(objeto_selecionado.id);
230 objeto_selecionado = null;
234 console.log(jsPlumb.getSelector('.objeto'));
238 //Menu de opciones en la conexión (flecha,unión)
239 me.menu_arrow = function(){
241 selector: '._jsPlumb_connector ',
243 callback: function(key, options) {
252 "flecha": {"name": "Recto"},
253 "diagrama": {"name": "Diagrama"},
254 "ondular": {"name": "Ondular"},
255 "cursiva": {"name": "Cursiva"},
261 "solido": {"name": "Solido"},
262 "discontinua": {"name": "Discontinua"}
266 "Eliminar":{"name": "Eliminar", "icon": "delete"},
272 me.menu_accion = function(accion){
273 console.log(conexion_selecionada);
274 if(accion == "Eliminar"){
275 jsPlumb.detach(conexion_selecionada, {
281 if(accion == "flecha"){
282 conexion_selecionada.setConnector("Straight");
285 if(accion == "diagrama"){
286 conexion_selecionada.setConnector("Flowchart");
289 if(accion == "ondular"){
290 conexion_selecionada.setConnector("Bezier");
293 if(accion == "cursiva"){
294 conexion_selecionada.setConnector("StateMachine");
297 if(accion == "discontinua"){
298 conexion_selecionada.setPaintStyle({
301 outlineColor:"transparent",
307 if(accion == "solido"){
308 conexion_selecionada.setPaintStyle({
311 outlineColor:"transparent",
318 me.arrastrable = function(){
319 jsPlumb.draggable($(".objeto"), {
327 img: 'images/create.png',
328 title: 'create button',
330 alert('i am add button')
334 img: 'images/update.png',
335 title: 'update button',
338 title: 'It will merge row',
339 img:'images/merge.png',
341 alert('It will merge row')
345 title: 'It will replace row',
346 img:'images/replace.png',
348 name: 'replace top 100',
349 img:'images/top.png',
351 alert('It will replace top 100 rows');
356 img:'images/all.png',
358 alert('It will replace all rows');
364 img: 'images/delete.png',
365 title: 'create button',
367 'name': 'soft delete',
368 img:'images/soft_delete.png',
370 alert('You can recover back');
373 'name': 'hard delete',
374 img:'images/hard_delete.png',
376 alert('It will delete permanently');
382 //Calling context menu
385 var getMenuItem = function (itemData) {
386 console.log(itemData);
390 href: '#' + itemData.link,
394 var subList = $("<ul>");
395 $.each(itemData.sub, function () {
396 subList.append(getMenuItem(this));
398 item.append(subList);
403 var $menu = $("#menu");
404 $.each(data.menu, function () {