File: /home/barbeatleanalyti/public_html/manage.beatleanalytics.com/theme/black/js/ADM-treeView.min.js
/*
* Demo: http://amirkabirdataminers.github.io/ADM-treeView
*
* @version 1.2.0
*
* © 2017 Amirkabir Data Miners <info@adm-co.net> - www.adm-co.net
*/
!function(e){"use strict";Array.prototype.loop=function(e,t){for(var n=this.length;n--;){var i=this.length-n-1,o=t?n-1+1:i;if(e(this[o],i)===!1)break}};var t=function(e,t){for(var n=e,i=t.split(/[.]/g);!i[0]&&i.length;)i.shift();return i.loop(function(e){return void 0!==n&&void(n=n[e])}),n},n=function(e,n,i){if(!(e&&e instanceof Array&&e.length))return-1;if(i){for(var o=0,d=e.length;o<d;o++){var s=t(e[o],i),c=t(n,i);if(s==c)return o}return-1}return e.indexOf(n)},i=function(t){return!("object"!=typeof t||!e.isFunction(t.then))},o=function(){return function(e,t,n){t.bind("keydown keypress",function(t){13===t.which&&(e.$apply(function(){e.$eval(n.teEnter)}),t.preventDefault())})}},d=function(e){return function(t,n,i,o){i.$observe("teFocus",function(i){t.$applyAsync(function(){("string"==typeof i&&7==i.length&&"#"==i.substr(0,1)||t.$eval(i))&&e(function(){n[0].focus()},100)})})}},s=function(e){return function(t,n,i){i.$observe("teTemplate",function(i){t.$applyAsync(function(){n.html(i),e(n.contents())(t)})})}},c=function(t){return{scope:!0,link:function(n,i,o){var d=e.isDefined(o.small)?" small":"",s=e.element('<span class="te-loading disable'+d+'" ng-hide="!loading"><svg class="te-i noI te-i-spin" viewBox="0 0 24 24"><use xlink:href="#te-i-autorenew" /></svg></span>');i.append(s),n.$applyAsync(function(){t(s)(n),setTimeout(function(){s.removeClass("disable")},100)}),o.$observe("teLoading",function(e){n.$evalAsync(function(){n.$eval(e)?n.loading=!0:n.loading=!1})})}}},l=function(){var t={childName:"childs",title:"$item.title",kidType:"",selectable:!1,readOnly:!1,trackBy:"",maxDepth:9999,direction:"ltr",dictionary:{noItem:"No item!",titlePlaceholder:"Title ...",rootAddBtn:"Add.",confirmBtn:"Confirm",cancelBtn:"Cancel"}},n={getOptions:function(e){var n=e&&t[e]||t;return n}};this.setConfigs=function(n,i){return i?void(t[n]=e.extend(t[n]||{},i)):(n.dictionary=e.extend(t.dictionary,n.dictionary||{}),void e.extend(t,n))},this.$get=function(){return n}},a=function(o,d,s,c){return{scope:{configs:"=",selected:"=?",api:"=?"},require:"ngModel",template:'<div class="treeEditor relCenter" ng-if="ctrl.model" ng-class="[{notEditable: options.readOnly}, options.direction]" ng-init="$depth=0; $item={};"> <ul class="te-ui te-repeatAnim enterOnly"> <p class="te-empty main" ng-class="{active: !ctrl.model.length}"> <svg class="te-i noI" viewBox="0 0 24 24"><use xlink:href="#te-i-error"/></svg>{{options.dictionary.noItem}}</p><li ng-init="$depth=$parent.$depth && $parent.$depth + 1 || 1; $open=false; $item.add=false;" ng-repeat="node in ctrl.model track by $index" ng-include="\'treeEditorChild.html\'"></li><div class="te-add" ng-show="$depth < options.maxDepth"> <div class="te-add-btn" ng-show="!$item.add && !options.singleRoot" ng-click="$item.add=true"> <svg class="te-i noI" viewBox="0 0 24 24"><use xlink:href="#te-i-add"/></svg>{{options.dictionary.rootAddBtn}}</div><div class="add" ng-show="$item.add"> <input type="text" placeholder="{{options.dictionary.titlePlaceholder}}" te-focus="{{$item.add}}" ng-model="$item.newItem" te-enter="add(ctrl.model, $item, $parent);"/> <svg class="te-i te-c-success" viewBox="0 0 24 24" ng-click="add(ctrl.model, $item, $parent);"><use xlink:href="#te-i-check"/></svg> <svg class="te-i" viewBox="0 0 24 24" ng-click="$item.newItem=\'\'; $item.add=false;"><use xlink:href="#te-i-clear"/></svg> </div></div></ul></div><script type="text/ng-template" id="treeEditorChild.html"> <div class="te-header" ng-click="(!$item.edit && canBeOpen(node, $depth)?$open=!$open:kidOpen(node, $item))"> <span class="te-selectable" ng-show="options.selectable" ng-click="toggle(node, $event)"> <div class="te-checkbox" ng-class="{checked: exists(node)}"><div></div></div><span>{{grabTitle(node)}}</span> </span> <span ng-show="!$item.edit && !options.selectable">{{grabTitle(node)}}</span> <span ng-show="$item.edit" class="edit" ng-init=""> <svg class="te-i te-c-success" viewBox="0 0 24 24" ng-click="edit(node, $item, $parent.$parent, $index, $event);"><use xlink:href="#te-i-check"/></svg> <svg class="te-i" viewBox="0 0 24 24" ng-click="cancelEdit($item, $event)"><use xlink:href="#te-i-clear"/></svg> <input type="text" placeholder="{{options.dictionary.titlePlaceholder}}" te-focus="{{$item.add}}" ng-model="$item.editItem" te-enter="edit(node, $item, $parent.$parent, $index);"/> </span> </div><div class="te-toolbar" ng-init="initItem(node); $item={};" id="te-node-{{node.id}}"> <svg class="te-i" viewBox="0 0 24 24" ng-class="{deg90: $open}" ng-show="canBeOpen(node, $depth)" ng-click="$open=!$open"><use xlink:href="#te-i-chevron-right"/></svg> <svg class="te-i" viewBox="0 0 24 24" ng-hide="$item.edit || $depth==1 && options.singleRoot" ng-click="$item.edit=true; $item.editItem=grabTitle(node);"><use xlink:href="#te-i-mode-edit"/></svg> <svg class="te-i" viewBox="0 0 24 24" ng-hide="$depth==1 && options.singleRoot || $item.deleteConfirm" ng-click="$item.deleteConfirm=true;"><use xlink:href="#te-i-delete"/></svg> <span class="deleteConfirm" ng-show="$item.deleteConfirm"> <span ng-click="$item.deleteConfirm=false;">{{options.dictionary.cancelBtn}}</span> <span ng-click="$open=false; delete($item, $parent, $event);">{{options.dictionary.confirmBtn}}</span> </span> <svg class="te-i te-c-success" viewBox="0 0 24 24" ng-show="!$item.add && depthValid($depth)" ng-click="$item.add=true; $open=true;"><use xlink:href="#te-i-add"/></svg> </div><div class="te-kidContent" ng-show="canShowKidContent($item, node)" te-loading="{{$item.kidContentLoading}}" small> <div class="te-ngIfAnim enterOnly" ng-if="$item.kidContent" te-template="{{$item.kidContent}}"></div></div><p class="te-empty" ng-class="{active: $open && (!node[$chn] || !node[$chn].length)}"><svg class="te-i noI" viewBox="0 0 24 24"><use xlink:href="#te-i-error"/></svg>{{options.dictionary.noItem}}</p><ul class="te-ui te-repeatAnim enterOnly" ng-if="$open && node[$chn]"> <li ng-init="$depth=$parent.$depth && $parent.$depth + 1 || 1; $open=false;" ng-repeat="node in node[$chn] track by $index" ng-include="\'treeEditorChild.html\'"></li></ul> <div class="te-add" ng-show="$open && $item.add"> <div class="add"> <input type="text" placeholder="{{options.dictionary.titlePlaceholder}}" te-focus="{{$item.add}}" ng-model="$item.newItem" te-enter="add(node[$chn], $item, $parent);"/> <svg class="te-i te-c-success" viewBox="0 0 24 24" ng-click="add(node[$chn], $item, $parent);"><use xlink:href="#te-i-check"/></svg> <svg class="te-i" viewBox="0 0 24 24" ng-click="$item.newItem=\'\'; $item.add=false;"><use xlink:href="#te-i-clear"/></svg> </div></div></script><svg style="display:none;" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1"> <defs> <g id="te-i-add"> <path d="M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z"/> <path d="M0 0h24v24H0z" fill="none"/> </g> <g id="te-i-error"> <path d="M0 0h24v24H0z" fill="none"/> <path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 15h-2v-2h2v2zm0-4h-2V7h2v6z"/> </g> <g id="te-i-chevron-right"> <path d="M10 6L8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z"/> <path d="M0 0h24v24H0z" fill="none"/> </g> <g id="te-i-mode-edit"> <path d="M3 17.25V21h3.75L17.81 9.94l-3.75-3.75L3 17.25zM20.71 7.04c.39-.39.39-1.02 0-1.41l-2.34-2.34c-.39-.39-1.02-.39-1.41 0l-1.83 1.83 3.75 3.75 1.83-1.83z"/> <path d="M0 0h24v24H0z" fill="none"/> </g> <g id="te-i-delete"> <path d="M6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6v12zM19 4h-3.5l-1-1h-5l-1 1H5v2h14V4z"/> <path d="M0 0h24v24H0z" fill="none"/> </g> <g id="te-i-check"> <path d="M0 0h24v24H0z" fill="none"/> <path d="M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z"/> </g> <g id="te-i-clear"> <path d="M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z"/> <path d="M0 0h24v24H0z" fill="none"/> </g> <g id="te-i-autorenew"> <path d="M12 6v3l4-4-4-4v3c-4.42 0-8 3.58-8 8 0 1.57.46 3.03 1.24 4.26L6.7 14.8c-.45-.83-.7-1.79-.7-2.8 0-3.31 2.69-6 6-6zm6.76 1.74L17.3 9.2c.44.84.7 1.79.7 2.8 0 3.31-2.69 6-6 6v-3l-4 4 4 4v-3c4.42 0 8-3.58 8-8 0-1.57-.46-3.03-1.24-4.26z"/> <path d="M0 0h24v24H0z" fill="none"/> </g> </defs></svg>',link:function(d,c,l,a){d.options=e.extend({},o.getOptions(),d.configs||{}),d.options.dictionary=e.extend({},o.getOptions().dictionary,(d.configs||{}).dictionary||{}),d.options.trackBy=d.options.trackBy.replace("$item.",""),d.options.readOnly=d.options.readOnly||d.options.selectable,d.ctrl={model:[],selected:[]},d.$chn=d.options.childName,d.grabTitle=function(e){var n=d.options.title.replace("$item.","");return t(e,n)};var r=function(e,t){for(var n={},i=t.replace("$item.",""),o=i.split(/[.]/g);!o[0]&&o.length;)o.shift();return o.loop(function(t,i){var o={};e=i?n:e,o[t]=e,n=o},!0),n};d.depthValid=function(e){return e<d.options.maxDepth},d.canBeOpen=function(e,t){return(!d.options.readOnly||d.options.readOnly&&e[d.$chn]&&e[d.$chn].length)&&d.depthValid(t)},d.canShowKidContent=function(e,t){return(e.kidContent||e.kidContentLoading)&&(!t[d.$chn]||t[d.$chn]&&!t[d.$chn].length)};var p=function(e,t){d.$applyAsync(function(){e.kidContent=t,e.kidContentLoading=!1})};d.kidOpen=function(e,t){d.$applyAsync(function(){if(t.kidContent)t.kidContent="",t.kidContentLoading=!1;else if(d.options.onKidOpen){var n=d.options.onKidOpen(e);i(n)?(t.kidContentLoading=!0,s.when(n).then(function(e){p(t,e)})):"string"==typeof n&&p(t,n)}})};var h=function(e,t){e.push(t),u()};d.add=function(t,n,o){if(n.newItem.replace(/ /g,"")){t instanceof Array||(t=[]);var c=r(n.newItem,d.options.title),l=e.copy(o.node);if(l&&l[d.$chn].push(c),d.options.onAdd){var a=d.options.onAdd(l,c,n.newItem);i(a)?s.when(a).then(function(n){n&&h(t,e.extend({},c,n===!0?{}:n))}):a!==!1&&h(t,c)}else h(t,c);n.add=!1,n.newItem=""}};var g=function(t,n){e.extend(t,r(n.editItem,d.options.title)),u()};d.edit=function(t,n,o,c,l){l&&l.stopPropagation(),n.edit=!1;var a=e.extend(e.copy(t),r(n.editItem,d.options.title)),p=e.copy(o.$parent.node);if(p&&(p[d.$chn][c]=a),d.options.onEdit){var h=d.options.onEdit(a,p);i(h)?s.when(h).then(function(e){e&&g(t,n)}):h!==!1&&g(t,n)}else g(t,n)},d.cancelEdit=function(e,t){t&&t.stopPropagation(),e.edit=!1};var v=function(e){1==e.$depth?d.ctrl.model.splice(e.$index,1):e.$parent.node[d.$chn].splice(e.$index,1),u()};d.delete=function(t,n,o){t.deleteConfirm=!1;var c,l=e.copy(n.$parent.node);if(c=l?l[d.$chn].splice(n.$index,1)[0]:d.ctrl.model[n.$index],d.options.onDelete){var a=d.options.onDelete(c,l);i(a)?s.when(a).then(function(e){e&&v(n)}):a!==!1&&v(n)}else v(n)},d.initItem=function(e){e[d.options.childName]=e[d.options.childName]||[]},d.toggle=function(e,t){t&&t.stopPropagation(),d.selected||(d.selected=[]);var i=n(d.selected,e,d.options.trackBy);return i>-1?d.selected.splice(i,1):d.selected.push(e)},d.exists=function(e){return n(d.selected,e,d.options.trackBy)>-1};var u=function(e){d.$evalAsync(function(){d.ctrl.model=e||d.ctrl.model,a.$setViewValue(d.ctrl.model),a.$render()})},$=function(e){return e?(u(e),e):e};a.$formatters.push($)}}},r=function(e){e.setConfigs({isDeviceTouch:"ontouchstart"in window||navigator.maxTouchPoints})};return e.module("ADM-treeView",[]).constant("constants",{}).provider("ADMtrv",l).directive("teFocus",["$timeout",d]).directive("teEnter",[o]).directive("teTemplate",["$compile",s]).directive("teLoading",["$compile",c]).directive("admTrv",["ADMtrv","constants","$q","$http",a]).config(["ADMtrvProvider",r])}(window.angular);