| lombardof | fb37bca | 2018-05-03 16:20:04 +0200 | [diff] [blame^] | 1 | function generateUID() { |
| 2 | return ("0000" + (Math.random() * Math.pow(36, 4) << 0).toString(36)).slice(-4) |
| 3 | } |
| 4 | |
| 5 | function openProject(pId) { |
| 6 | window.location.href = '/projects/' + pId; |
| 7 | } |
| 8 | |
| 9 | |
| 10 | function openDescriptorView(project_id, descriptor_type, descriptor_id) { |
| 11 | console.log("openDescriptorView", project_id, descriptor_type, descriptor_id); |
| 12 | window.location.href = '/projects/' + project_id + '/descriptors/' + descriptor_type + '/' + descriptor_id; |
| 13 | |
| 14 | } |
| 15 | |
| 16 | |
| 17 | function openEditorEvent(e, id) { |
| 18 | openEditor(id); |
| 19 | } |
| 20 | |
| 21 | function nodeDragStart(event) { |
| 22 | event.dataTransfer.setData("Text", event.target.id); |
| 23 | } |
| 24 | |
| 25 | function savePositions(el) { |
| 26 | graph_editor.savePositions(); |
| 27 | } |
| 28 | |
| 29 | function buildPalette(args) { |
| 30 | $("#paletteContainer").empty(); |
| 31 | var type_property = graph_editor.getTypeProperty(); |
| 32 | if (args.length > 0) { |
| 33 | args.forEach(function (category) { |
| 34 | |
| 35 | var category_id = "category_" + category.category_name.replace(/[\s.*+?^${}()\/|[\]\\]/g, "_");//.replace(/\s/g, ''); |
| 36 | var content_id = "palette-content-" + category.category_name.replace(/[\s.*+?^${}()\/|[\]\\]/g, "_");//.replace(/\s/g, ''); |
| 37 | |
| 38 | $("#paletteContainer").append('<div id="' + category_id + '" class="palette-category" ><div class="palette-header" onClick="handlePaletteCat(this);" category_id="' + category_id + '"> ' + |
| 39 | '<i class="fa fa-chevron-down "></i>' + |
| 40 | '<span> ' + category.category_name + '</span>' + |
| 41 | '</div>' + |
| 42 | '<div id="' + content_id + '" class="palette-content">' + |
| 43 | |
| 44 | '</div>' + |
| 45 | '</div>'); |
| 46 | category.types.forEach(function (type) { |
| 47 | console.log(graph_editor.get_name_from_d3_symbol(d3.symbolCircle)) |
| 48 | var type_id = type.id.replace(/[\s.*+?^${}()|[\]\\]/g, "_"); |
| 49 | var palette_node_icon; |
| 50 | if (type_property[type.id] && type_property[type.id].image && type_property[type.id].image != '') { |
| 51 | palette_node_icon = '<div class="palette-node-icon" style="background-image: url(' + (type_property[type.id].image || "") + ')"></div>'; |
| 52 | } |
| 53 | else if (type_property[type.id] && type_property[type.id].shape) { |
| 54 | palette_node_icon = buildHtmlShape({ |
| 55 | shape: type_property[type.id].shape, |
| 56 | color: type_property[type.id].color |
| 57 | }); |
| 58 | |
| 59 | } |
| 60 | else {//#1F77B4 |
| 61 | palette_node_icon = '<div class="palette-node-icon"> <div class="palette-node-square" style="background:#1F77B4;"></div></div>'; |
| 62 | } |
| 63 | |
| 64 | var html_to_append = '<div class="palette-node ui-draggable" draggable="true" type-name="' + type.id + '" id="' + type_id + '" ondragstart="nodeDragStart(event)">' + |
| 65 | '<div class="palette-node-label">' + type.name + '</div>' + |
| 66 | '<div class="palette-node-icon-container">' + |
| 67 | palette_node_icon + |
| 68 | '</div>' + |
| 69 | '</div>' |
| 70 | $("#" + content_id).append(html_to_append); |
| 71 | }); |
| 72 | |
| 73 | }); |
| 74 | } |
| 75 | togglePaletteSpinner(true); |
| 76 | |
| 77 | |
| 78 | } |
| 79 | |
| 80 | function handlePaletteCat(item) { |
| 81 | console.log("handlePaletteContainer") |
| 82 | var category_id = $(item).attr("category_id") |
| 83 | $('#' + category_id).toggleClass("palette-close"); |
| 84 | |
| 85 | } |
| 86 | |
| 87 | function togglePaletteSpinner(addOrRemove) { |
| 88 | $('#palette').toggleClass("palette-status-hidden", addOrRemove); |
| 89 | } |
| 90 | |
| 91 | function showAlert(msg) { |
| 92 | // modal_alert_text |
| 93 | var alert_msg = "" |
| 94 | if (typeof msg == "string") |
| 95 | alert_msg = msg |
| 96 | else |
| 97 | alert_msg = JSON.stringify(msg) |
| 98 | $('#modal_alert_text').text(alert_msg); |
| 99 | $('#modal_alert').modal('show'); |
| 100 | } |
| 101 | |
| 102 | function getUrlParameter(par_name) { |
| 103 | var results = new RegExp('[\?&]' + par_name + '=([^&#]*)').exec(window.location.href); |
| 104 | if (results == null) { |
| 105 | return null; |
| 106 | } else { |
| 107 | return results[1] || 0; |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | function buildHtmlShape(args) { |
| 112 | var mySymbol = args.shape; |
| 113 | switch (mySymbol) { |
| 114 | case d3.symbolCircle: |
| 115 | return '<div class="palette-node-icon"> <div class="palette-node-circle" style="background:' + args.color + ';"></div></div>'; |
| 116 | break; |
| 117 | case d3.symbolSquare: |
| 118 | return '<div class="palette-node-icon"> <div class="palette-node-square" style="background:' + args.color + ';"></div></div>'; |
| 119 | break; |
| 120 | case d3.symbolDiamond: |
| 121 | return '<div class="palette-node-icon" style="background-color:' + args.color + '"></div>'; |
| 122 | ; |
| 123 | break; |
| 124 | case d3.symbolTriangle: |
| 125 | return '<div class="palette-node-icon"> <div class="palette-node-triangle" style="border-color: transparent transparent ' + args.color + ' transparent;"></div></div>'; |
| 126 | break; |
| 127 | case d3.symbolStar: |
| 128 | return '<div class="palette-node-icon" style="background-color:' + args.color + '"></div>'; |
| 129 | ; |
| 130 | break; |
| 131 | case d3.symbolCross: |
| 132 | return '<div class="palette-node-icon" style="background-color:' + args.color + '"></div>'; |
| 133 | ; |
| 134 | break; |
| 135 | default: |
| 136 | // if the string is not recognized |
| 137 | return "unknown"; |
| 138 | //return d3.symbolCircleUnknown; |
| 139 | } |
| 140 | |
| 141 | |
| 142 | } |
| 143 | |
| 144 | if (!String.format) { |
| 145 | String.format = function (format) { |
| 146 | var args = Array.prototype.slice.call(arguments, 1); |
| 147 | return format.replace(/{(\d+)}/g, function (match, number) { |
| 148 | return typeof args[number] != 'undefined' ? |
| 149 | args[number] : |
| 150 | match; |
| 151 | }); |
| 152 | }; |
| 153 | } |