/* * jQuery OrgChart Plugin * https://github.com/dabeng/OrgChart * * Demos of jQuery OrgChart Plugin * http://dabeng.github.io/OrgChart/ * * Copyright 2016, dabeng * http://dabeng.github.io/ * * Licensed under the MIT license: * http://www.opensource.org/licenses/MIT */ 'use strict'; (function(factory) { if (typeof module === 'object' && typeof module.exports === 'object') { factory(require('jquery'), window, document); } else { factory(jQuery, window, document); } }(function($, window, document, undefined) { $.fn.orgchart = function(options) { var defaultOptions = { 'nodeTitle': 'name', 'nodeId': 'id', 'toggleSiblingsResp': false, 'depth': 999, 'chartClass': '', 'exportButton': false, 'exportFilename': 'OrgChart', 'exportFileextension': 'png', 'parentNodeSymbol': 'fa-users', 'draggable': false, 'direction': 't2b', 'pan': false, 'zoom': false, 'zoominLimit': 10, 'zoomoutLimit': 0.1, 'menu': false, 'menu_edit': 'edit', 'menu_delete': 'delete', 'unit_name': 'Unit' }; switch (options) { case 'buildHierarchy': return buildHierarchy.apply(this, Array.prototype.splice.call(arguments, 1)); case 'addChildren': return addChildren.apply(this, Array.prototype.splice.call(arguments, 1)); case 'addParent': return addParent.apply(this, Array.prototype.splice.call(arguments, 1)); case 'addSiblings': return addSiblings.apply(this, Array.prototype.splice.call(arguments, 1)); case 'removeNodes': return removeNodes.apply(this, Array.prototype.splice.call(arguments, 1)); case 'removeNode': return removeNode.apply(this, Array.prototype.splice.call(arguments, 1)); case 'getHierarchy': return getHierarchy.apply(this, Array.prototype.splice.call(arguments, 1)); case 'hideParent': return hideParent.apply(this, Array.prototype.splice.call(arguments, 1)); case 'showParent': return showParent.apply(this, Array.prototype.splice.call(arguments, 1)); case 'hideChildren': return hideChildren.apply(this, Array.prototype.splice.call(arguments, 1)); case 'showChildren': return showChildren.apply(this, Array.prototype.splice.call(arguments, 1)); case 'hideSiblings': return hideSiblings.apply(this, Array.prototype.splice.call(arguments, 1)); case 'showSiblings': return showSiblings.apply(this, Array.prototype.splice.call(arguments, 1)); case 'getNodeState': return getNodeState.apply(this, Array.prototype.splice.call(arguments, 1)); case 'getRelatedNodes': return getRelatedNodes.apply(this, Array.prototype.splice.call(arguments, 1)); case 'updateNode': return updateNode.apply(this, Array.prototype.splice.call(arguments, 1)) case 'setMenuEnabled': return setMenuEnabled.apply(this, Array.prototype.splice.call(arguments, 1)) default: // initiation time var opts = $.extend(defaultOptions, options); } // build the org-chart var $chartContainer = this; if ($chartContainer.children().length) { $chartContainer.empty(); } window.draggedId = -1; window.modId = 10000; var data = opts.data; var $chart = $('
', { 'data': { 'options': opts }, 'class': 'orgchart' + (opts.chartClass !== '' ? ' ' + opts.chartClass : '') + (opts.direction !== 't2b' ? ' ' + opts.direction : ''), 'click': function(event) { if (!$(event.target).closest('.node').length) { $chart.find('.node.focused').removeClass('focused'); } } }); if ($.type(data) === 'object') { if (data instanceof $) { // ul datasource buildHierarchy($chart, buildJsonDS(data.children()), 0, opts); } else { // local json datasource buildHierarchy($chart, opts.ajaxURL ? data : attachRel(data, '00'), 0, opts); } } else { $.ajax({ 'url': data, 'dataType': 'json', 'beforeSend': function () { $chart.append(''); } }) .done(function(data, textStatus, jqXHR) { buildHierarchy($chart, opts.ajaxURL ? data : attachRel(data, '00'), 0, opts); }) .fail(function(jqXHR, textStatus, errorThrown) { console.log(errorThrown); }) .always(function() { $chart.children('.spinner').remove(); }); } $chartContainer.append($chart); // append the export button if (opts.exportButton && !$chartContainer.find('.oc-export-btn').length) { var $exportBtn = $('