From ff6765e274940206df8ff64120588ed85db5f8a8 Mon Sep 17 00:00:00 2001 From: WouterJ Date: Mon, 20 Jun 2016 11:32:31 +0200 Subject: [PATCH 1/5] Fix input binding with non-root root node --- Resources/assets/js/adapter/fancytree.js | 25 +++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/Resources/assets/js/adapter/fancytree.js b/Resources/assets/js/adapter/fancytree.js index 4fac0f8..ec541cc 100644 --- a/Resources/assets/js/adapter/fancytree.js +++ b/Resources/assets/js/adapter/fancytree.js @@ -183,28 +183,39 @@ export class FancytreeAdapter { bindToInput($input) { // output active node to input field - this.$tree.fancytree('option', 'activate', function(event, data) { - $input.val(data.node.getKeyPath()); + this.$tree.fancytree('option', 'activate', (event, data) => { + root = this.rootNode; + if (root.substr(-1) == '/') { + var root = this.rootNode.substr(0, -1); + } + + $input.val(root + data.node.getKeyPath()); }); - var tree = this.tree; - var showKey = function (key) { - tree.loadKeyPath(key, function (node, status) { + var showKey = (key) => { + this.tree.loadKeyPath(key, function (node, status) { if ('ok' == status) { node.setExpanded(); node.setActive(); } }); }; + var removeRoot = (path) => { + if (0 === path.indexOf(this.rootNode)) { + return path.substr(this.rootNode.length); + } + + return path; + }; // use initial input value as active node this.$tree.bind('fancytreeinit', function (event, data) { - showKey($input.val()); + showKey(removeRoot($input.val())); }); // change active node when the value of the input field changed $input.on('change', function (e) { - showKey($(this).val()); + showKey(removeRoot($(this).val())); }); } From c9221a4469fc730b6479c3eb31006a3818e0b9ee Mon Sep 17 00:00:00 2001 From: WouterJ Date: Wed, 31 Aug 2016 16:23:35 +0200 Subject: [PATCH 2/5] Display root node when it's not / --- Resources/assets/js/adapter/fancytree.js | 32 +++++++++++++++--------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/Resources/assets/js/adapter/fancytree.js b/Resources/assets/js/adapter/fancytree.js index ec541cc..933efa5 100644 --- a/Resources/assets/js/adapter/fancytree.js +++ b/Resources/assets/js/adapter/fancytree.js @@ -147,13 +147,20 @@ export class FancytreeAdapter { // transform the JSON response into a data structure that's supported by FancyTree postProcess: function (event, data) { if (null == data.error) { - data.result = requestNodeToFancytreeNode(data.response).children; - if (data.result.length == 1) { - data.result[0].expanded = true; + var result = requestNodeToFancytreeNode(data.response); + if ("" === result.key) { + result = result.children; + } else { + result = [result]; + } + + if (result.length == 1) { + result[0].expanded = true; } + data.result = result; if (useCache) { - cache.set(data.node.getKeyPath(), data.result); + cache.set(data.node.getKeyPath(), result); } } else { data.result = { @@ -182,14 +189,15 @@ export class FancytreeAdapter { } bindToInput($input) { + var root = this.rootNode; + if (root.substr(-1) == '/') { + var root = this.rootNode.substr(0, -1); + } + var rootParent = root.substr(0, root.lastIndexOf('/')); + // output active node to input field this.$tree.fancytree('option', 'activate', (event, data) => { - root = this.rootNode; - if (root.substr(-1) == '/') { - var root = this.rootNode.substr(0, -1); - } - - $input.val(root + data.node.getKeyPath()); + $input.val(rootParent + data.node.getKeyPath()); }); var showKey = (key) => { @@ -201,8 +209,8 @@ export class FancytreeAdapter { }); }; var removeRoot = (path) => { - if (0 === path.indexOf(this.rootNode)) { - return path.substr(this.rootNode.length); + if (0 === path.indexOf(rootParent + '/')) { + return path.substr(rootParent.length + 1); } return path; From a14691a1cd8c776b739e26e8dc06aab21026edf5 Mon Sep 17 00:00:00 2001 From: WouterJ Date: Mon, 20 Jun 2016 11:32:39 +0200 Subject: [PATCH 3/5] Regenerate assets --- Resources/public/js/cmf_tree_browser.fancytree.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Resources/public/js/cmf_tree_browser.fancytree.js b/Resources/public/js/cmf_tree_browser.fancytree.js index 7f3dd72..2458f2a 100644 --- a/Resources/public/js/cmf_tree_browser.fancytree.js +++ b/Resources/public/js/cmf_tree_browser.fancytree.js @@ -1,2 +1,2 @@ !function(e){function t(r){if(n[r])return n[r].exports;var i=n[r]={exports:{},id:r,loaded:!1};return e[r].call(i.exports,i,i.exports,t),i.loaded=!0,i.exports}var n={};return t.m=e,t.c=n,t.p="",t(0)}([function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{"default":e}}var i=n(27),o=r(i),s=n(29);o["default"].fn.cmfTree=function(e){e=o["default"].extend({adapter:null,request:{load:null},actions:{}},e);var t=(0,o["default"])(this),n=function(e){if("string"==typeof e)return(0,o["default"])(e);if(e instanceof o["default"])return e;throw"Cannot handle selector "+e+". You may want to pass a jQuery object or a jQuery selector."};if(!e.request.load)throw"cmfTree needs an AJAX URL to lazy load the tree, pass it using the `request.load` option.";e.adapter||(e.adapter=new s.FancytreeAdapter(e));var r=e.adapter;if(!r.bindToElement)throw"cmfTree adapters must have a bindToElement() method to specify the output element of the tree.";for(var i in e.actions)if(e.actions.hasOwnProperty(i)){if(!r.addAction)throw"The configured cmfTree adapter does not support actions, implement the addAction() method or use another adapter.";var a=e.actions[i];if(!a.url)throw'actions should have a url defined, "'+i+'" does not.';r.addAction(i,a.url,a.icon)}if(r.bindToElement(t),e.path_output){if(!r.bindToInput)throw"The configured cmfTree adapter does not support binding to an input field, implement the bindToInput() method or use another adapter.";r.bindToInput(n(e.path_output))}return r}},function(e,t,n){var r=n(43)("wks"),i=n(15),o=n(2).Symbol;e.exports=function(e){return r[e]||(r[e]=o&&o[e]||(o||i)("Symbol."+e))}},function(e,t){var n=e.exports="undefined"!=typeof window&&window.Math==Math?window:"undefined"!=typeof self&&self.Math==Math?self:Function("return this")();"number"==typeof __g&&(__g=n)},function(e,t,n){var r=n(4),i=n(23);e.exports=n(10)?function(e,t,n){return r.setDesc(e,t,i(1,n))}:function(e,t,n){return e[t]=n,e}},function(e,t){var n=Object;e.exports={create:n.create,getProto:n.getPrototypeOf,isEnum:{}.propertyIsEnumerable,getDesc:n.getOwnPropertyDescriptor,setDesc:n.defineProperty,setDescs:n.defineProperties,getKeys:n.keys,getNames:n.getOwnPropertyNames,getSymbols:n.getOwnPropertySymbols,each:[].forEach}},function(e,t){e.exports={}},function(e,t,n){var r=n(2),i=n(3),o=n(15)("src"),s="toString",a=Function[s],l=(""+a).split(s);n(7).inspectSource=function(e){return a.call(e)},(e.exports=function(e,t,n,s){"function"==typeof n&&(n.hasOwnProperty(o)||i(n,o,e[t]?""+e[t]:l.join(String(t))),n.hasOwnProperty("name")||i(n,"name",t)),e===r?e[t]=n:(s||delete e[t],i(e,t,n))})(Function.prototype,s,function(){return"function"==typeof this&&this[o]||a.call(this)})},function(e,t){var n=e.exports={version:"1.2.6"};"number"==typeof __e&&(__e=n)},function(e,t,n){var r=n(32);e.exports=function(e,t,n){if(r(e),void 0===t)return e;switch(n){case 1:return function(n){return e.call(t,n)};case 2:return function(n,r){return e.call(t,n,r)};case 3:return function(n,r,i){return e.call(t,n,r,i)}}return function(){return e.apply(t,arguments)}}},function(e,t){e.exports=function(e){if(void 0==e)throw TypeError("Can't call method on "+e);return e}},function(e,t,n){e.exports=!n(20)(function(){return 7!=Object.defineProperty({},"a",{get:function(){return 7}}).a})},function(e,t){var n={}.hasOwnProperty;e.exports=function(e,t){return n.call(e,t)}},function(e,t){e.exports=function(e){return"object"==typeof e?null!==e:"function"==typeof e}},function(e,t,n){"use strict";var r=n(41),i=n(19),o=n(6),s=n(3),a=n(11),l=n(5),c=n(39),d=n(14),u=n(4).getProto,h=n(1)("iterator"),f=!([].keys&&"next"in[].keys()),p="@@iterator",v="keys",y="values",g=function(){return this};e.exports=function(e,t,n,b,m,x,_){c(n,t,b);var k,N,w=function(e){if(!f&&e in T)return T[e];switch(e){case v:return function(){return new n(this,e)};case y:return function(){return new n(this,e)}}return function(){return new n(this,e)}},S=t+" Iterator",C=m==y,E=!1,T=e.prototype,A=T[h]||T[p]||m&&T[m],L=A||w(m);if(A){var P=u(L.call(new e));d(P,S,!0),!r&&a(T,p)&&s(P,h,g),C&&A.name!==y&&(E=!0,L=function(){return A.call(this)})}if(r&&!_||!f&&!E&&T[h]||s(T,h,L),l[t]=L,l[S]=g,m)if(k={values:C?L:w(y),keys:x?L:w(v),entries:C?w("entries"):L},_)for(N in k)N in T||o(T,N,k[N]);else i(i.P+i.F*(f||E),t,k);return k}},function(e,t,n){var r=n(4).setDesc,i=n(11),o=n(1)("toStringTag");e.exports=function(e,t,n){e&&!i(e=n?e:e.prototype,o)&&r(e,o,{configurable:!0,value:t})}},function(e,t){var n=0,r=Math.random();e.exports=function(e){return"Symbol(".concat(void 0===e?"":e,")_",(++n+r).toString(36))}},function(e,t,n){var r=n(12);e.exports=function(e){if(!r(e))throw TypeError(e+" is not an object!");return e}},function(e,t,n){var r=n(18),i=n(1)("toStringTag"),o="Arguments"==r(function(){return arguments}());e.exports=function(e){var t,n,s;return void 0===e?"Undefined":null===e?"Null":"string"==typeof(n=(t=Object(e))[i])?n:o?r(t):"Object"==(s=r(t))&&"function"==typeof t.callee?"Arguments":s}},function(e,t){var n={}.toString;e.exports=function(e){return n.call(e).slice(8,-1)}},function(e,t,n){var r=n(2),i=n(7),o=n(3),s=n(6),a=n(8),l="prototype",c=function(e,t,n){var d,u,h,f,p=e&c.F,v=e&c.G,y=e&c.S,g=e&c.P,b=e&c.B,m=v?r:y?r[t]||(r[t]={}):(r[t]||{})[l],x=v?i:i[t]||(i[t]={}),_=x[l]||(x[l]={});v&&(n=t);for(d in n)u=!p&&m&&d in m,h=(u?m:n)[d],f=b&&u?a(h,r):g&&"function"==typeof h?a(Function.call,h):h,m&&!u&&s(m,d,h),x[d]!=h&&o(x,d,f),g&&_[d]!=h&&(_[d]=h)};r.core=i,c.F=1,c.G=2,c.S=4,c.P=8,c.B=16,c.W=32,e.exports=c},function(e,t){e.exports=function(e){try{return!!e()}catch(t){return!0}}},function(e,t,n){var r=n(8),i=n(38),o=n(37),s=n(16),a=n(46),l=n(47);e.exports=function(e,t,n,c){var d,u,h,f=l(e),p=r(n,c,t?2:1),v=0;if("function"!=typeof f)throw TypeError(e+" is not iterable!");if(o(f))for(d=a(e.length);d>v;v++)t?p(s(u=e[v])[0],u[1]):p(e[v]);else for(h=f.call(e);!(u=h.next()).done;)i(h,p,u.value,t)}},function(e,t){e.exports=function(e,t){return{value:t,done:!!e}}},function(e,t){e.exports=function(e,t){return{enumerable:!(1&e),configurable:!(2&e),writable:!(4&e),value:t}}},function(e,t,n){var r=n(6);e.exports=function(e,t){for(var n in t)r(e,n,t[n]);return e}},function(e,t){e.exports=function(e,t,n){if(!(e instanceof t))throw TypeError(n+": use the 'new' operator!");return e}},function(e,t){var n=Math.ceil,r=Math.floor;e.exports=function(e){return isNaN(e=+e)?0:(e>0?r:n)(e)}},function(e,t){e.exports=jQuery},function(e,t){!function(e,t,n,r){"use strict";function i(t,n){t||(n=n?": "+n:"",e.error("Fancytree assertion failed"+n))}function o(e,n){var r,i,o=t.console?t.console[e]:null;if(o)try{o.apply(t.console,n)}catch(s){for(i="",r=0;ra;return!0}function l(e,t,n,r,i){var o=function(){var n=t[e],o=r[e],s=t.ext[i],a=function(){return n.apply(t,arguments)};return function(){var e=t._local,n=t._super;try{return t._local=s,t._super=a,o.apply(t,arguments)}finally{t._local=e,t._super=n}}}();return o}function c(t,n,r,i){for(var o in r)"function"==typeof r[o]?"function"==typeof t[o]?t[o]=l(o,t,n,r,i):"_"===o.charAt(0)?t.ext[i][o]=l(o,t,n,r,i):e.error("Could not override tree."+o+". Use prefix '_' to create tree."+i+"._"+o):"options"!==o&&(t.ext[i][o]=r[o])}function d(t,n){return t===r?e.Deferred(function(){this.resolve()}).promise():e.Deferred(function(){this.resolveWith(t,n)}).promise()}function u(t,n){return t===r?e.Deferred(function(){this.reject()}).promise():e.Deferred(function(){this.rejectWith(t,n)}).promise()}function h(e,t){return function(){e.resolveWith(t)}}function f(t){var n=e.extend({},t.data()),r=n.json;return delete n.fancytree,r&&(delete n.json,n=e.extend(n,r)),n}function p(e){return e=e.toLowerCase(),function(t){return t.title.toLowerCase().indexOf(e)>=0}}function v(e){var t=new RegExp("^"+e,"i");return function(e){return t.test(e.title)}}function y(t,n){var r,o,s,a;for(this.parent=t,this.tree=t.tree,this.ul=null,this.li=null,this.statusNodeType=null,this._isLoading=!1,this._error=null,this.data={},r=0,o=S.length;rul.fancytree-container").remove();var n,i={tree:this};this.rootNode=new y(i,{title:"root",key:"root_"+this._id,children:null,expanded:!0}),this.rootNode.parent=null,n=e("