'use strict'; (function($){ $(function() { new QWebChannel(qt.webChannelTransport, function(channel) { // Connect to a signal: //channel.objects.webNotifier.jsonChanged.connect(function() //{ /// // This callback will be invoked whenever the signal is emitted on the C++/QML side. // console.log(arguments); // }); window.webNotifier = channel.objects.webNotifier; console.log(webNotifier.jsonString); // To get notified about remote property changes, // simply connect to the corresponding notify signal: webNotifier.jsonStringChanged.connect(function(newValue) { var hierarchy = $('#chart-container').orgchart('getHierarchy'); // console.error(JSON.stringify(hierarchy, null, 2)); }) webNotifier.getHierarchy.connect(function() { //console.error("I AM BATMAN!") var hierarchy = $('#chart-container').orgchart('getHierarchy'); // console.error(JSON.stringify(hierarchy, null, 2)); webNotifier.gotHierarchy(JSON.stringify(hierarchy)); }); webNotifier.updateStringChanged.connect(function(newValue) { // console.error(JSON.stringify(newValue, null, 2)); var success = $('#chart-container').orgchart('updateNode', newValue); }) }); $('#chart-container').orgchart( { 'data' : datascource, 'nodeContent': 'title', 'draggable': isDragEnabled, 'zoom': true, 'pan': true, 'menu': isMenuEnabled, 'menu_edit': menuEdit, 'menu_delete': menuDelete, 'unit_name': unitName, 'exportButton': false, 'exportFilename': 'Orbat', 'toggleSiblingsResp': false, 'dropCriteria': function($draggedNode, $dragZone, $dropZone) { if($dropZone.find('.unit').text() !== unitName ) { return false; } return true; }, }) .children('.orgchart').on('nodedropped.orgchart', function(event) { console.log('draggedNode:' + event.draggedNode.children('.title').text() + ', dragZone:' + event.dragZone.children('.title').text() + ', dropZone:' + event.dropZone.children('.title').text() ); }); $("html").on("contextmenu",function(e) { //prevent default context menu for right click e.preventDefault(); }); $("html").on("click", function() { $(".menu").hide(); window.currentSelectedDiv=""; }); $('.menuEdit').on("click", function() { $(".menu").hide(); //console.error(JSON.stringify(currentSelectedId)); webNotifier.startEdit(JSON.stringify(currentSelectedDiv)); }); $('.menuDelete').on("click", function() { $(".menu").hide(); $('#chart-container').orgchart('removeNode', currentSelectedDiv.id); webNotifier.startDelete(JSON.stringify(currentSelectedDiv)); }); }); })(jQuery);