index2.js 74 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251
  1. var EventEmitter = require("events").EventEmitter;
  2. var opath = require("opath");
  3. var async = require("async");
  4. var tool = require("tools2")();
  5. var getthezip = require("libs/getthezip");
  6. var unpackzip = require("libs/unpackzip");
  7. var generatezip = require("libs/generatezip");
  8. var random = require("sharedkey-thing").randoma(0xbadebabe)("#CHANGE BEFORE CHRISTMAS#");
  9. var _ = require("lodash");
  10. var templates = require("./templates");
  11. var ignores =
  12. "_created _data _events _extends _hasa _inherits _isa _maxListeners _metas _references _relations _rootname addListener children data data2 domain emit emita emitas eventNames export export2 exportFlatSync exportSerialised exportSync exporta extends getMaxListeners getStuff getStuff2 getStuff3 inherits innerExport isa listenerCount listeners metas metas2 metas3 name on once parents path pickdeep pingup prependListener prependOnceListener rawListeners relatesAsToWith removeAllListeners removeListener setMaxListeners test unextends uninherits unisa withAll withAllSync"
  13. .split(" ");
  14. function template_helpers(self) {
  15. return {
  16. "toTextArea": function(str) {
  17. return '<textarea>' + str + '</textarea>'
  18. },
  19. "toWrap": function(str, tag, attr) {
  20. return '<' + tag + ' ' + attr + '>' + str + '</' + tag + '>';
  21. },
  22. toLowerCase: function(str) {
  23. return str.toLowerCase();
  24. },
  25. toUpperCase: function(str) {
  26. return str.toUpperCase();
  27. },
  28. "pagecontent": function(obj) {
  29. console.log("pagecontent", obj, arguments);
  30. return self.template(obj._data.content, obj);
  31. },
  32. "siblings": function(obj) {
  33. return [_.keys(obj.parents).shift()].map(function(parentpath) {
  34. var ares = _.map(obj.parents[parentpath] ? obj.parents[parentpath].children : [], function(a) {
  35. return a();
  36. })
  37. ares.sort(sorter(function(a) {
  38. return a._metas.menu_order || 100
  39. }, -1));
  40. var ss = _.map(ares, function(child, name) {
  41. return child.path
  42. });
  43. if (ss.length > 12) {
  44. var cindex = ss.indexOf(obj.path);
  45. cindex = cindex < 6 ? 6 : cindex;
  46. var spp = _.map(ares, renderlin(obj))
  47. var sasa = [].concat(spp.slice(cindex - 6, cindex + 7))
  48. } else {
  49. var sasa = _.map(ares, renderlin(obj))
  50. }
  51. return sasa.join("\n")
  52. }).join("\n")
  53. },
  54. "parents": function(obj, ss_, sss_) {
  55. if (typeof(ss_) !== "undefined" && typeof(sss_) !== "undefined") {
  56. return gpath(obj, []).slice(parseInt(ss_), parseInt(sss_)).map(function(p, i) {
  57. return '<a href="#' + p + '" elepath="' + p + '" class="ele elecontent button button-rounded button-' + (i == 0 ? 'small' : 'tiny') + ' button-royal">' +
  58. self.oget(p +
  59. "/._data.title", p) + '</a>';
  60. }).join("\n");
  61. } else {
  62. return gpath(obj, []).slice(1).map(function(p, i) {
  63. return '<a href="#' + p + '" elepath="' + p + '" class="ele elecontent button button-rounded button-' + (i == 0 ? 'small' : 'tiny') + ' button-royal">' +
  64. self.oget(p +
  65. "/._data.title", p) + '</a>';
  66. }).join("\n");
  67. }
  68. },
  69. "parent": function(obj) {
  70. return _.map(obj.parents, function(par, nam) {
  71. self.rendertemplate(par)
  72. }).join("\n");
  73. },
  74. "children2": function(obj) {
  75. var ret = [];
  76. _.map(obj.children, function(child) {
  77. var cho = typeof(child) === "function" ? child() : child;
  78. ret.push(self.rendertemplate(cho))
  79. })
  80. return ret.join("\n")
  81. },
  82. "children": function(obj) {
  83. var ret = [];
  84. _.map(obj.children, function(child) {
  85. var cho = typeof(child) === "function" ? child() : child;
  86. ret.push(renderlin(cho)(cho, cho.name))
  87. })
  88. return ret.join("\n");
  89. },
  90. "relations": function(obj) {
  91. var stash = [];
  92. _.map(obj._relations, function(rels, relname) {
  93. var relators = _.keys(rels);
  94. var sss = relators.slice(0, 25).map(function(relator) {
  95. return '<li elepath="' + relator + '"><a href="#' + relator + '" class="elecontent" title="' + JSON.stringify(rels[relator].context).toHtmlEntities() +
  96. '">' + relator + '</a> </li> '
  97. }).join("\n");;
  98. stash.push([relname + "(" + relators.length + ")", sss]);
  99. })
  100. var ss = ('<div class="stash">' + stash.map(function(a) {
  101. return '<div class="stt"> <div class="st1">' + (a[0] === false ? "" : a[0] + "") + '</div><div class="st2">' + a[1] +
  102. '</div> </div>'
  103. }).join("\n") + '</div>');
  104. return ss
  105. },
  106. "grandchildren": function(obj) {
  107. var ret = [];
  108. _.map(obj.children, function(child) {
  109. var cho = typeof(child) === "function" ? child() : child;
  110. ret = [].concat.apply(ret, _.map(cho.children, renderlin(cho)))
  111. })
  112. return ret
  113. },
  114. "created": function(obj) {
  115. return obj._created.toJSON();
  116. },
  117. "_isa": function(obj) {
  118. return _.map(obj._isa, renderlin(obj)).join("\n")
  119. },
  120. "_isa2": function(obj) {
  121. return _.map(obj._isa, function(o, n) {
  122. return self.rendertemplate(o)
  123. }).join("\n")
  124. },
  125. "_isa3": function(obj, a, b) {
  126. console.log(";;;;;;;;;;;", a, b);
  127. return _.map(obj._isa, function(o, n) {
  128. return self.rendertemplate(o)
  129. }).slice(parseInt(a), parseInt(b)).join("\n")
  130. },
  131. "_hasa": function(obj) {
  132. return _.map(obj._hasa, renderlin(obj)).join("\n")
  133. },
  134. "findall": function(obj, withprop, target_) {
  135. var target = target_ || "content";
  136. var aa = []
  137. _.keys(self.oo).filter(aa => ["trash", "system", ""].indexOf(aa) === -1 && typeof(self.oo[aa]) === "function").map(function(key) {
  138. aa = [].concat.apply(aa, allchildren(self.oo[key]()).filter(function(a) {
  139. return a._isdirty
  140. }))
  141. })
  142. return aa.map(function(a) {
  143. return renderlin2(obj, {
  144. target: target
  145. })(a, a.name)
  146. }).join("\n");
  147. },
  148. "jsondata": function(obj) {
  149. return JSON.stringify(obj._data, true, 2).toHtmlEntities();
  150. }
  151. }
  152. }
  153. function gpath(cc, p) {
  154. if (cc.parents) {
  155. var k = _.keys(cc.parents).shift();
  156. if (k) {
  157. return gpath(cc.parents[k], p.concat(cc.path))
  158. } else {
  159. return p.concat(cc.path)
  160. }
  161. }
  162. }
  163. function renderlin2(obj, opt) {
  164. return function(child, name) {
  165. var pp = typeof(child) === "function" ? child() : child;
  166. return '<a href="#' + pp.path + '" elepath="' + pp.path + '" eletarget="' + opt.target + '" class="elecontent button button-rounded button-small button-' + (pp.path ==
  167. obj.path ? 'royal' : 'inverse') +
  168. '">' + (pp._data.title ?
  169. pp._data.title : pp.name) +
  170. '</a>'
  171. }
  172. }
  173. function renderlin(obj) {
  174. return function(child, name) {
  175. var pp = typeof(child) === "function" ? child() : child;
  176. return '<a href="#' + pp.path + '" elepath="' + pp.path + '" class="elecontent button button-rounded button-small button-' + (pp.path == obj.path ? 'royal' : 'inverse') +
  177. '">' + (pp._data.title ?
  178. pp._data.title : pp.name) +
  179. '</a>'
  180. }
  181. }
  182. function Asystem(oo) {
  183. this.oo = oo;
  184. this.name = "noname"
  185. this._logs = [];
  186. this._linked = {};
  187. this._templatefunction = templates(this, template_helpers(this));
  188. }
  189. Asystem.prototype.__proto__ = EventEmitter.prototype;
  190. Asystem.prototype.slugger = function(str) {
  191. var ret = ("" + str).replace(/\/+/g, '/').replace(/[^\x20-\x7E]/g, '')
  192. // ret=decodeURIComponent(ret);
  193. ret = ret.replace(/[\<\>]/g, '')
  194. if (ret.indexOf("/") == ret.length - 1) {
  195. ret = ret.substring(0, ret.length - 1);
  196. }
  197. return ret
  198. }
  199. Asystem.prototype.t_content = function(path) {
  200. return this.oget(path)._data.content
  201. }
  202. Asystem.prototype.odelete = function(path) {
  203. var self = this;
  204. self.omove(path, "trash/" + path)
  205. if (self.oo[path]) {
  206. _.map(self.oo[path]().children, function(child, name) {
  207. self.odelete(child().path)
  208. })
  209. delete self.oo[path]
  210. }
  211. self.emit("deleted", path)
  212. }
  213. Asystem.prototype.ozap = function(path) {
  214. var t = path.split("/");
  215. var ta = t.pop();
  216. delete this.oget(t.join("/")).children[ta];
  217. this.emit("deleted", path)
  218. }
  219. Asystem.prototype.omove = function(path, topath) {
  220. var self = this;
  221. var newa = self.oget(topath)
  222. var olda = self.oget(path);
  223. var ss = olda.exportSync();
  224. if (!ss) {
  225. return false;
  226. }
  227. ss.name = topath.split("/").pop();
  228. ss.path = topath;
  229. var np = topath.split("/")
  230. np.pop();
  231. _.map(olda._relations, function(rels, relsname) {
  232. _.map(rels, function(rel, name) {
  233. delete rel.ref._relations[rel.context.out]
  234. })
  235. delete olda._relations[relsname]
  236. })
  237. _.map(olda._isa, function(isa, name) {
  238. delete isa._hasa[name]
  239. delete olda._isa[name]
  240. })
  241. _.map(olda._hasa, function(hasa, name) {
  242. delete hasa._isa[olda.path]
  243. delete olda._hasa[name]
  244. })
  245. _.map(olda._inherits, function(inheri, name) {
  246. delete inheri._extends[olda.path]
  247. delete olda._inherits[name]
  248. })
  249. _.map(olda._extends, function(extendi, name) {
  250. delete extendi._inherits[olda.path]
  251. delete olda._extends[name]
  252. })
  253. _.map(olda.parents, function(par, nam) {
  254. delete par.children[olda.name];
  255. })
  256. _.keys(olda.children, function(key) {
  257. delete olda.children[key];
  258. })
  259. delete olda;
  260. self.rev_conv2(ss, np.join("/"));
  261. self.emit("moved", path, topath)
  262. }
  263. Asystem.prototype.oclone = function(path, topath) {
  264. var self = this;
  265. var newa = self.oget(topath)
  266. var olda = self.oget(path);
  267. var ss = olda.exportSync();
  268. ss.name = topath.split("/").pop();
  269. ss.path = topath;
  270. var np = topath.split("/")
  271. np.pop();
  272. self.rev_conv2(ss, np.join("/"));
  273. self.emit("cloned", path, topath)
  274. }
  275. Asystem.prototype.oset = function(path_, data) {
  276. var self = this;
  277. var path = self.slugger(path_);
  278. var ar = path.split("/");
  279. var first = ar.shift();
  280. var prop, obj;
  281. if (typeof(self.oo[first]) === "undefined") {
  282. self.oo[first] = self.oo(first);
  283. self.oo[first]()._isdirty = true;
  284. self.emit("rootcreated", self.oo[first]())
  285. }
  286. if (ar.length > 0 && ar[ar.length - 1].indexOf(".") === 0) {
  287. prop = ar.pop().substring(1);
  288. }
  289. path = ar.join("/")
  290. if (path !== "") {
  291. var exists = self.ofind(path_);
  292. if (exists.remainder !== "") {
  293. obj = self.oo[first](path)();
  294. self.emit("created1", obj)
  295. } else {
  296. obj = self.oo[first](path)();
  297. }
  298. } else {
  299. obj = self.oo[first]()
  300. }
  301. if (prop) {
  302. obj._isdirty = true;
  303. opath.set(obj, prop, data);
  304. //return obj[prop] || getpath(obj, prop)
  305. self.emit("changed", obj.path + "/" + prop, data)
  306. }
  307. return obj;
  308. }
  309. Asystem.prototype.ogetsilent = function(path_, alternative) {
  310. var self = this;
  311. var path = self.slugger(path_);
  312. var ar = path.split("/");
  313. var first = ar.shift();
  314. var prop, obj;
  315. if (typeof(self.oo[first]) === "undefined") {
  316. self.oo[first] = self.oo(first);
  317. }
  318. if (ar.length > 0 && ar[ar.length - 1].indexOf(".") === 0) {
  319. prop = ar.pop().substring(1);
  320. }
  321. path = ar.join("/")
  322. if (path !== "") {
  323. var exists = self.ofind(path_);
  324. if (exists.remainder !== "") {
  325. obj = self.oo[first](path)();
  326. } else {
  327. obj = self.oo[first](path)();
  328. }
  329. } else {
  330. obj = self.oo[first]()
  331. }
  332. if (prop) {
  333. return obj[prop] || opath.get(obj, prop) || alternative;
  334. }
  335. return obj;
  336. }
  337. Asystem.prototype.oget = function(path_, alternative) {
  338. var self = this;
  339. var path = self.slugger(path_);
  340. var ar = path.split("/");
  341. var first = ar.shift();
  342. var prop, obj;
  343. if (typeof(self.oo[first]) === "undefined") {
  344. self.oo[first] = self.oo(first);
  345. self.oo[first]()._isdirty = true;
  346. self.emit("rootcreated", self.oo(first)())
  347. }
  348. if (ar.length > 0 && ar[ar.length - 1].indexOf(".") === 0) {
  349. prop = ar.pop().substring(1);
  350. }
  351. path = ar.join("/")
  352. if (path !== "") {
  353. var exists = self.ofind(path_);
  354. if (exists.remainder !== "" && exists.remainder.indexOf("/") > -1) {
  355. obj = self.oo[first](path)();
  356. obj._isdirty = true;
  357. self.emit("created2", obj)
  358. } else {
  359. obj = self.oo[first](path)();
  360. }
  361. } else {
  362. obj = self.oo[first]()
  363. }
  364. if (prop) {
  365. return obj[prop] || opath.get(obj, prop) || alternative;
  366. }
  367. return obj;
  368. }
  369. Asystem.prototype.getele = function(action) {
  370. var self = this;
  371. action = self.slugger(action);
  372. var a = action.split("/");
  373. var roo = a.shift();
  374. var ffu;
  375. if (a[a.length - 1].indexOf(".") > -1) {
  376. //function call;
  377. ffu = a.pop().split(".").pop();
  378. } else {
  379. //straight
  380. }
  381. var name = a.join("/");
  382. var eles = self.oo[roo](name)();
  383. if (ffu && eles[ffu]) {
  384. return {
  385. ele: eles,
  386. func: eles[ffu]
  387. };
  388. }
  389. return {
  390. ele: eles
  391. }
  392. }
  393. Asystem.prototype.ofind = function(path) {
  394. /* returns {found: "spath"|false , remainder: "rest"|"" , obj: obj}*/
  395. var self = this;
  396. path = self.slugger(path);
  397. var ar = path.split("/");
  398. var first = ar.shift();
  399. if (typeof(self.oo[first]) === "undefined") {
  400. return {
  401. found: false
  402. }
  403. } else {
  404. var pa = self.oo[first]()
  405. var ch = "";
  406. var rest = [];
  407. while (ar.length) {
  408. ch = ar.shift();
  409. if (pa.children[ch]) {
  410. pa = pa.children[ch]();
  411. } else {
  412. rest.push(ch)
  413. }
  414. }
  415. return {
  416. found: pa.path,
  417. /* is false if not found*/
  418. remainder: rest.join("/"),
  419. /* is not "" if not found rest of path*/
  420. obj: pa /* the found object*/
  421. }
  422. }
  423. }
  424. Asystem.prototype.rev_conv = function(obj, path) {
  425. if (typeof(obj) !== "object" || obj == null) {
  426. return false;
  427. }
  428. var self = this;
  429. var zzz = self.ogetsilent(obj.path);
  430. zzz.data(obj.data)
  431. zzz._created = new Date(obj.created);
  432. zzz.metas(obj.meta);
  433. if (_.size(obj.rel) > 0) {
  434. _.map(obj.rel, function(rels, name) {
  435. _.map(rels, function(dats, relator) {
  436. if (name === dats.in) {} else {
  437. // console.log("RR: ", obj.path, relator, name, dats.in, dats.out);
  438. zzz.relatesAsToWith(dats.out, self.ogetsilent(relator), dats.in, dats)
  439. }
  440. })
  441. })
  442. }
  443. if (obj.inherits && obj.inherits.length) {
  444. obj.inherits.map(function(alp) {
  445. zzz.inherits(self.ogetsilent(alp))
  446. })
  447. }
  448. if (obj.extends && obj.extends.length) {
  449. obj.extends.map(function(alp) {
  450. zzz.extends(self.ogetsilent(alp))
  451. })
  452. }
  453. if (obj.isa && obj.isa.length) {
  454. obj.isa.map(function(alp) {
  455. zzz.isa(self.ogetsilent(alp))
  456. })
  457. }
  458. if (obj.hasa && obj.hasa.length) {
  459. obj.hasa.map(function(alp) {
  460. self.ogetsilent(alp).isa(zzz)
  461. })
  462. }
  463. _.map(_.omit(obj, ["getStuff3", "name", "hasa", "meta", "data", "parents", "children", "path", "_rootname", "created", "rel", "inherits", "extends", "isa", "children",
  464. "_isdirty"
  465. ]),
  466. function(
  467. val,
  468. ke) {
  469. if (typeof(val) === "string" && val.indexOf("$$$FUNCTION$$$") === 0) {
  470. if (zzz._metas && zzz._metas.protected && zzz._metas.protected[ke]) {} else {
  471. var ttt = {};
  472. try {
  473. eval("(function(tt){ tt.func = " + val.split("$$$FUNCTION$$$").pop() + ";})(ttt)");
  474. zzz[ke] = ttt.func;
  475. } catch (ea) {
  476. console.log("error func: ", ea)
  477. }
  478. }
  479. } else {
  480. if (typeof(val) === "object") {
  481. var r = {}
  482. _.map(val, function(v, kp) {
  483. if (typeof(v) === "string" && v.indexOf("$$$FUNCTION$$$") === 0) {
  484. var ttt = {};
  485. try {
  486. eval("(function(tt){ tt.func = " + v.split("$$$FUNCTION$$$").pop() + ";})(ttt)");
  487. r[kp] = ttt.func;
  488. } catch (ea) {
  489. console.log("error func: ", ea)
  490. }
  491. } else {
  492. r[kp] = v
  493. }
  494. })
  495. zzz[ke] = r;
  496. } else {
  497. zzz[ke] = val
  498. }
  499. }
  500. })
  501. delete obj._isdirty;
  502. if (obj.children && obj.children.length) {
  503. obj.children.map(function(child) {
  504. self.rev_conv(child)
  505. })
  506. }
  507. }
  508. Asystem.prototype.rev_conv2 = function(obj, path) {
  509. var self = this;
  510. var zzz = self.ogetsilent(path + "/" + obj.name);
  511. zzz.data(obj.data)
  512. zzz._created = new Date(obj.created);
  513. zzz.metas(obj.meta);
  514. if (_.size(obj.rel) > 0) {
  515. _.map(obj.rel, function(rels, name) {
  516. _.map(rels, function(dats, relator) {
  517. if (name === dats.in) {} else {
  518. // console.log("RR: ", obj.path, relator, name, dats.in, dats.out);
  519. zzz.relatesAsToWith(dats.out, self.ogetsilent(relator), dats.in, dats)
  520. }
  521. })
  522. })
  523. }
  524. if (obj.inherits && obj.inherits.length) {
  525. obj.inherits.map(function(alp) {
  526. zzz.inherits(self.ogetsilent(alp))
  527. })
  528. }
  529. if (obj.extends && obj.extends.length) {
  530. obj.extends.map(function(alp) {
  531. zzz.extends(self.ogetsilent(alp))
  532. })
  533. }
  534. if (obj.isa && obj.isa.length) {
  535. obj.isa.map(function(alp) {
  536. zzz.isa(self.ogetsilent(alp))
  537. })
  538. }
  539. if (obj.hasa && obj.hasa.length) {
  540. obj.hasa.map(function(alp) {
  541. self.ogetsilent(alp).isa(zzz)
  542. })
  543. }
  544. _.map(_.omit(obj, ["getStuff3", "name", "hasa", "meta", "data", "parents", "children", "path", "_rootname", "created", "rel", "inherits", "extends", "isa", "children",
  545. "_isdirty"
  546. ]),
  547. function(
  548. val,
  549. ke) {
  550. if (typeof(val) === "string" && val.indexOf("$$$FUNCTION$$$") === 0) {
  551. // console.log(val.split("$$$FUNCTION$$$").pop())
  552. if (zzz._metas && zzz._metas.protected && zzz._metas.protected[ke]) {} else {
  553. var ttt = {};
  554. try {
  555. eval("(function(tt){ tt.func = " + val.split("$$$FUNCTION$$$").pop() + ";})(ttt)");
  556. zzz[ke] = ttt.func;
  557. } catch (ea) {
  558. console.log("error func: ", ea)
  559. }
  560. }
  561. } else {
  562. if (typeof(val) === "object") {
  563. var r = {}
  564. _.map(val, function(v, kp) {
  565. if (typeof(v) === "string" && v.indexOf("$$$FUNCTION$$$") === 0) {
  566. var ttt = {};
  567. try {
  568. eval("(function(tt){ tt.func = " + v.split("$$$FUNCTION$$$").pop() + ";})(ttt)");
  569. r[kp] = ttt.func;
  570. } catch (ea) {
  571. console.log("error func: ", ea)
  572. }
  573. } else {
  574. r[kp] = v
  575. }
  576. })
  577. zzz[ke] = r;
  578. } else {
  579. zzz[ke] = val
  580. }
  581. }
  582. })
  583. delete obj._isdirty;
  584. if (obj.children && obj.children.length) {
  585. obj.children.map(function(child) {
  586. self.rev_conv2(child, zzz.path)
  587. })
  588. }
  589. }
  590. /*Asystem.prototype.save = function() {
  591. var self = this;
  592. return new Promise(function(resolve, reject) {
  593. $lib.exporter(self, function(err, data) {
  594. $lib.generate_thezip(self.name + "-" + $lib.getTimedName() + ".zip",
  595. $lib.arrayedToObject(data, "name"), function(err, zz) {
  596. console.log(err);
  597. resolve(zz)
  598. })
  599. })
  600. })
  601. }
  602. */
  603. Asystem.prototype.exporter = function(cb) {
  604. var self = this;
  605. var obj = self.oo;
  606. var stores = _.keys(obj).filter(function(a) {
  607. return typeof(obj[a]) === "function"
  608. }).map(function(a) {
  609. return obj[a]()
  610. }).map(function(a) {
  611. var da = a.exportSync("");
  612. return da
  613. });
  614. stores.unshift({
  615. "name": "namespace.manifest",
  616. "data": {
  617. "namespace": self.name
  618. }
  619. })
  620. var ret = {}
  621. stores.map(function(a) {
  622. ret[a.name] = a;
  623. })
  624. cb(null, ret)
  625. }
  626. Asystem.prototype.log = function() {}
  627. Asystem.prototype.template = function() {
  628. return this._templatefunction.apply(this, arguments)
  629. }
  630. Asystem.prototype.loadInto = function(url, callback, linked) {
  631. var self = this;
  632. getthezip(url, function(res) {
  633. return res.json()
  634. })
  635. .then(function(obj) {
  636. self.rev_conv(obj);
  637. self.restart();
  638. })
  639. }
  640. Asystem.prototype.loadZipLocal = function(blob, callback) {
  641. var self = this;
  642. var importer = self.importer_zip();
  643. unpackzip(importer)(blob)
  644. .then(
  645. function() {
  646. self.emit("status", "early ready yes yes")
  647. if (self._loadqueue && self._loadqueue.length) {
  648. var ff = self._loadqueue.shift()
  649. self.ozap(importer.path);
  650. self.loadZip(ff[1], callback, ff[0]);
  651. } else {
  652. if (self.name_imported) {
  653. self.name = self.name_imported;
  654. }
  655. self.ozap(importer.path);
  656. callback(null, self);
  657. }
  658. }
  659. ).catch(console.log)
  660. }
  661. Asystem.prototype.loadZip = function(url, callback, linked) {
  662. var self = this;
  663. if (linked) {
  664. self._linked[linked] = url;
  665. }
  666. getthezip(url)
  667. .then(function(data) {
  668. self.emit("status", "got data" + data.length)
  669. var importer = self.importer_zip();
  670. unpackzip(importer)(data)
  671. .then(
  672. function() {
  673. self.emit("status", "early ready yes yes")
  674. if (self._loadqueue && self._loadqueue.length) {
  675. var ff = self._loadqueue.shift()
  676. self.ozap(importer.path);
  677. self.loadZip(ff[1], callback, ff[0]);
  678. } else {
  679. if (self.name_imported) {
  680. self.name = self.name_imported;
  681. }
  682. self.ozap(importer.path);
  683. callback(null, self);
  684. }
  685. }
  686. )
  687. .catch(console.log)
  688. })
  689. .catch(console.log)
  690. }
  691. Asystem.prototype.saveZip = function() {
  692. var self = this;
  693. return new Promise(function(resolve, reject) {
  694. self.exporter(function(err, data) {
  695. var seperate_save = _.keys(data).filter(function(name) {
  696. return self._linked && self._linked[name + ".link"]
  697. })
  698. var ddata = _.omit(data, seperate_save);
  699. seperate_save.map(function(om) {
  700. var url = self._linked[om + ".link"].split("/");
  701. url.pop();
  702. url.push(self.name + "-" + om + ".zip");
  703. ddata[om + ".link"] = url.join("/");
  704. })
  705. generatezip(self.name + "-" + "" + ".zip", ddata, function(err, zz) {
  706. async.mapSeries(seperate_save, function(name, next) {
  707. var dda = {};
  708. dda[name] = data[name];
  709. generatezip(self.name + "-" + name + ".zip", dda, next)
  710. }, function(err, all) {
  711. all.push(zz);
  712. resolve(all)
  713. })
  714. })
  715. })
  716. })
  717. }
  718. Asystem.prototype.saveAsJS = function() {
  719. var self = this;
  720. return new Promise(function(resolve, reject) {
  721. self.exporterJS(function(err, data) {
  722. var tm = {}
  723. _.map(data, function(dat, name) {
  724. if (typeof(dat.data) === "object" && dat.data.length) {
  725. tm[name + ".js"] = {
  726. data: dat.data.map(function(a) {
  727. return '$E(' + JSON.stringify(a) + ');'
  728. }).join("\n")
  729. };
  730. } else {
  731. tm[name] = {
  732. data: dat.data
  733. };
  734. }
  735. })
  736. generatezip(self.name + "-" + "" + ".zip", tm, function(err, zz) {
  737. resolve(zz);
  738. })
  739. //console.log("TTTT",tm);
  740. // console.log("DDD",data);
  741. })
  742. })
  743. }
  744. Asystem.prototype.exporterJS = function(cb) {
  745. var self = this;
  746. var obj = self.oo;
  747. var stores = _.keys(obj).filter(function(a) {
  748. return typeof(obj[a]) === "function"
  749. }).map(function(a) {
  750. return obj[a]()
  751. }).map(function(a) {
  752. var da = a.exportFlatSync(a.name);
  753. return {
  754. name: a.name,
  755. data: da
  756. }
  757. });
  758. stores.unshift({
  759. "name": "namespace.manifest",
  760. "data": {
  761. "namespace": self.name
  762. }
  763. })
  764. var ret = {}
  765. stores.map(function(a) {
  766. ret[a.name] = a;
  767. })
  768. cb(null, ret)
  769. }
  770. Asystem.prototype.importer_zip = function() {
  771. var self = this;
  772. self.oget("system/emmm").metas("_hide", true);
  773. var emname = "system/emmm/a/" + random(0xffffff)
  774. var emmm = self.oget(emname);
  775. emmm.metas("unsaveable", true);
  776. emmm.on("file", function(filename, data) {
  777. if (filename.indexOf(".link") > -1) {
  778. emmm.emit("link", data);
  779. self._loadqueue = self._loadqueue || [];
  780. self._loadqueue.push([filename, data])
  781. self.emit("status", "gotlink", filename);
  782. } else {
  783. self.emit("status", "gotfile", filename + " : " + typeof(data) + " : " + data.substring(0, 20));
  784. self.oget("folders/" + filename.indexOf("/") > -1 ? filename : "folders/" + filename).data("data", data);
  785. }
  786. })
  787. emmm.on("json", function(filename, data) {
  788. self.emit("status", "gotfile", filename);
  789. self.rev_conv(data)
  790. })
  791. emmm.on("namespace", function(data, cont) {
  792. self.emit("status", "gotnamespace", data.namespace);
  793. self.name_imported = data.namespace;
  794. cont();
  795. })
  796. emmm.on("nonamespace", function(cont) {
  797. //self.name = url.split("/").pop().split(".").shift();
  798. self.emit("status", "gotnonamespace", self.name);
  799. cont();
  800. })
  801. return emmm
  802. }
  803. function createnav(rk, key) {
  804. return '#' + key;
  805. }
  806. $linkstr2 = '<li class="{{liclass}}"><i class="{{iclass}}"></i> <a href="{{href}}" class="eletree">{{title}}</a> <em>{{size}}</em></li>';
  807. function allchildpaths(obj_) {
  808. var obj = typeof(obj_) === "function" ? obj_() : obj_;
  809. return [].concat.apply([obj.path], _.map(obj.children, allchildpaths))
  810. }
  811. function allchildren(obj_) {
  812. var obj = typeof(obj_) === "function" ? obj_() : obj_;
  813. return [].concat.apply([obj], _.map(obj.children, allchildren))
  814. }
  815. function sorter(prop, dir) {
  816. return function(aa, bb) {
  817. var a = prop(aa);
  818. var b = prop(bb);
  819. return a > b ? dir * -1 : a < b ? dir * 1 : 0;
  820. }
  821. }
  822. Asystem.prototype.t_icon = function(obj) {
  823. var self = this;
  824. if (obj._data.iconclass) {
  825. var dd = self.oget(obj._data.iconclass)._data.data;
  826. if (!dd) {
  827. return "";
  828. }
  829. if (dd.indexOf("data:") === 0) {
  830. return '<i><img src="' + dd + '"></i>';
  831. } else {
  832. return '<i>' + dd + '</i>';
  833. }
  834. }
  835. return "<i> </i>"
  836. }
  837. Asystem.prototype.t_title = function(obj) {
  838. var self = this;
  839. //contexts;
  840. return opath.get(obj._data, "title") || obj.name
  841. }
  842. Asystem.prototype.renderme = function(obj, maxlevels, atlevel, viewa) {
  843. var self = this;
  844. var ssi = _.size(obj.children);
  845. var childas = obj;
  846. if (ssi === 1) {
  847. var ooj = obj.children[_.keys(obj.children).shift()]()
  848. if (ooj._metas.skipme) {
  849. childas = ooj;
  850. }
  851. }
  852. var ssia = allchildpaths(obj).length - 1;
  853. //(ssi > 0 ? ssi : '') +
  854. if (obj._metas.pickchild) {
  855. childas = obj.children[obj._metas.pickchild]();
  856. }
  857. if (obj._metas.pickpath) {
  858. childas = self.oget(obj._metas.pickpath);
  859. }
  860. var s = "";
  861. if (viewa && typeof(viewa) === "function") {
  862. s += "" + viewa(obj, atlevel);
  863. }
  864. if (obj._metas._hide) {
  865. return "";
  866. }
  867. s += '<div class="obj l' + atlevel + ' ' + (obj._metas.hide ? 'hidden' : '') + '" eleview="menulink" elepath="' + obj.path + '" atlevel="' + atlevel + '">'
  868. s += '<a href="#' + obj.path + '" >' + self.t_icon(obj) + self.t_title(obj) + '<em>' + (ssia > 0 ? ssia : '') + '</em></a>'
  869. if (atlevel < maxlevels) {
  870. if (ssi > 0) {
  871. var xxx = _.map(childas.children, function(cc) {
  872. return cc()
  873. })
  874. xxx.sort(sorter(function(a) {
  875. return a._metas.menu_order || 100
  876. }, -1));
  877. var aa = xxx.slice(0, 25).map(function(cc) {
  878. return self.renderme(cc, maxlevels, atlevel + 1, viewa)
  879. }).join("\n")
  880. return s + '<div class="children">' + aa + '</div></div>'
  881. } else {
  882. return s + '</div>';
  883. }
  884. } else {
  885. return s + '</div>'
  886. }
  887. }
  888. Asystem.prototype.render = function() {
  889. var self = this;
  890. return new Promise(function(resolve, reject) {
  891. var rooten = self.oget("root");
  892. var ss = [self.template('<div id="{{_data.id}}" class="obj root" eleview="" elepath="">', rooten)];
  893. // ss.push('<pre onclick="$lib.toggle_admin()">' + self.oget("root/._data.title") + '</pre><hr>')
  894. /* var kka = _.keys(self.oo).filter(aa => ["trash", "system", "root"].indexOf(aa) === -1 && typeof(self.oo[aa]) === "function")
  895. kka.sort(function(aa, bb) {
  896. var a = self.oo[aa]()._metas.menu_order;
  897. var b = self.oo[bb]()._metas.menu_order;
  898. return a > b ? 1 : a < b ? -1 : 0
  899. })
  900. */
  901. var kkas = _.filter(self.oo, function(sto) {
  902. return typeof(sto) === "function"
  903. }).map(function(sto, nam) {
  904. return sto();
  905. })
  906. kkas.sort(sorter(function(a) {
  907. return a._metas.menu_order || 100
  908. }, -1));
  909. var privates = [];
  910. var publics = [];
  911. kkas.filter(function(obj) {
  912. return obj._metas.public !== true
  913. }).map(function(obj) {
  914. privates.push(self.rendera("menulink", obj, 0, 0));
  915. })
  916. kkas.filter(function(obj) {
  917. return obj._metas.public === true
  918. }).map(function(obj) {
  919. publics.push(self.rendera("menulink", obj, 2, 0));
  920. })
  921. publics.map(function(a) {
  922. ss.push(a);
  923. })
  924. /* kka.map(function(key) {
  925. ss.push(self.rendera("menulink", self.oo[key](), 0, 0));
  926. })
  927. */
  928. ss.push('</div>')
  929. ss.push('<div id="editorlinks">');
  930. ss.push('<div id="mmme" class="obj root" eleview="" elepath="">');
  931. privates.map(function(a) {
  932. ss.push(a);
  933. })
  934. ss.push('</div>');
  935. ss.push('</div>')
  936. resolve(ss.join("\n"));
  937. })
  938. }
  939. Asystem.prototype.render_editorlinks = function(levels) {
  940. var self = this;
  941. var kkas = _.filter(self.oo, function(sto) {
  942. return typeof(sto) === "function"
  943. }).map(function(sto, nam) {
  944. return sto();
  945. })
  946. kkas.sort(sorter(function(a) {
  947. return a._metas.menu_order || 100
  948. }, -1));
  949. return kkas.map(function(obj) {
  950. return self.renderme(obj, levels || 0, 0);
  951. }).join("\n");
  952. }
  953. Asystem.prototype.rendermenu = function(obj, levels) {
  954. var self = this;
  955. var temps = obj.getStuff3("_data.menuobj", function(a) {
  956. return a
  957. }, "_data.menuobj")
  958. console.log("TEMenu", temps);
  959. if (temps.length > 0) {
  960. return self.renderme(self.oget(temps[0].data), levels || 0, 0);
  961. }
  962. return self.renderme(obj, levels || 0, 0);
  963. }
  964. Asystem.prototype.renderq = function(kkey) {
  965. var self = this;
  966. return new Promise(function(resolve, reject) {
  967. var rooten = self.oget("root");
  968. var ss = [self.template('<div id="{{_data.id}}" class="obj root" eleview="" elepath="">', rooten)];
  969. // ss.push('<pre onclick="$lib.toggle_admin()">' + self.oget("root/._data.title") + '</pre><hr>')
  970. if (!self.oo[kkey]) {
  971. self.oget(kkey);
  972. }
  973. ss.push(self.rendera("menulink", self.oo[kkey](), 1, 0));
  974. ss.push('</div>')
  975. resolve(ss.join("\n"));
  976. })
  977. }
  978. Asystem.prototype.rendera = function(template) {
  979. var args = Array.prototype.slice.apply(arguments, [1]);
  980. if (template == "view") {
  981. return "VIEW"
  982. }
  983. if (template == "menulink") {
  984. return this.renderme.apply(this, args);
  985. }
  986. if (template == "editor") {
  987. return this.renderEditorTools(args[0], "editor");
  988. }
  989. return "NOT VIEW " + template
  990. }
  991. //
  992. Asystem.prototype.renderEditorTools = function(obj, state) {
  993. var buts = [];
  994. if (obj.path.indexOf("trash") == 0) {
  995. buts.push('<button class="elerestore"><i class="fa fa-undo-alt"></i></button>')
  996. }
  997. if (state == "editor") {
  998. buts.push('<button class="eleview"><i class="fa fa-eye"></i></button>')
  999. if (!(obj._metas.nochildren)) {
  1000. buts.push('<button class="eleplus"><i class="fa fa-plus-circle"></i></button>')
  1001. }
  1002. if (obj.path.indexOf("trash") == -1 && !(obj._metas.undeletable)) {
  1003. buts.push('<button class="eledelete"><i class="fa fa-trash-alt"></i></button>')
  1004. }
  1005. buts.push('<button class="eleexport"><i class="fa fa-file-export"></i></button>')
  1006. } else {
  1007. buts.push('<button class="eleeditor"><i class="fa fa-edit"></i></button>')
  1008. }
  1009. return '<div id="editor" elepath="' + obj.path + '" eleview="editor" class="editorline" ><div class="buttons">' + buts.map(function(a) {
  1010. return a
  1011. }).join(" ") + '</div><div id="editor_context"></div></div>'
  1012. }
  1013. tool.add_filters("editor_sections", function(arr, obj) {
  1014. arr.push({
  1015. title: "Template",
  1016. content: function() {
  1017. return "<div class=\"status\">x</div> <textarea class=htmleditor data-id=\"" + obj.path + "/._data.template\">" + obj._data.template + '</textarea>'
  1018. }
  1019. })
  1020. return arr;
  1021. }, 100, "Template")
  1022. function wrap(tag, obj, content) {
  1023. var args = Array.prototype.slice.apply(arguments, [2]);
  1024. return '<' + tag + ' ' + _.map(obj, (val, prop) => prop + '="' + val + '"').join(" ") + '>' + args.join("\n") + '</' + tag + '>'
  1025. }
  1026. Asystem.prototype.renderEditor = function(obj) {
  1027. var self = this;
  1028. var ss = "";
  1029. //"<div class=\"status\">x</div> <textarea class=htmleditor data-id=\"" + obj.path + "/._data.content\">" + obj._data.content + '</textarea>'
  1030. // ss += self.template(self.oget("system/editor")._data.template,obj);
  1031. var self = this;
  1032. var aa = []
  1033. _.keys(self.oo).filter(aa => ["trash", ""].indexOf(aa) === -1 && typeof(self.oo[aa]) === "function").map(function(key) {
  1034. aa = [].concat.apply(aa, allchildren(self.oo[key]()).filter(function(a) {
  1035. return a.editor_function
  1036. }))
  1037. })
  1038. ss += aa.map(function(a) {
  1039. return wrap("div", {
  1040. elepath: a.path,
  1041. class: "editor_module"
  1042. }, wrap("h3", {}, a.name), wrap("div", {}, a._metas.help), wrap("div", {}, a.editor_function(obj)))
  1043. }).join("\n")
  1044. // return aa.map( function(a){ return renderlin(a)(a,a.name) } ).join("\n");
  1045. ss += '<hr>'
  1046. ss += self.renderEditor2(obj);
  1047. return ss
  1048. }
  1049. String.prototype.toHtmlEntities = function() {
  1050. return this.replace(/./gm, function(s) {
  1051. return "&#" + s.charCodeAt(0) + ";";
  1052. });
  1053. };
  1054. /**
  1055. * Create string from HTML entities
  1056. */
  1057. String.fromHtmlEntities = function(string) {
  1058. return (string + "").replace(/&#\d+;/gm, function(s) {
  1059. return String.fromCharCode(s.match(/\d+/gm)[0]);
  1060. })
  1061. };
  1062. Asystem.prototype.uniq_relnames = function() {
  1063. var self = this;
  1064. var rels = {}
  1065. self.allchildren().map(function(c) {
  1066. _.keys(c._relations).map(function(relname) {
  1067. rels[relname] = rels[relname] || 0;
  1068. rels[relname] = rels[relname] + 1;
  1069. })
  1070. })
  1071. return _.keys(rels).map(function(a) {
  1072. return {
  1073. name: a,
  1074. cnt: rels[a]
  1075. }
  1076. });
  1077. }
  1078. function mmb(t, d) {
  1079. return '<div class="mb"><h3>' + t + '</h3>' + d + '</div>';
  1080. }
  1081. Asystem.prototype.addEditorContext = function(conobj) {
  1082. this.editorContexts = this.editorContexts || [];
  1083. this.editorContexts.push(conobj);
  1084. }
  1085. Asystem.prototype.renderEditor2 = function(obj) {
  1086. var self = this;
  1087. var types = self.editorTypes();
  1088. var tabs_links = '<ul class="tabs">' + self.editorContexts.filter(function(con) {
  1089. return con.filter ? con.filter(obj) : true;
  1090. }).map(function(con) {
  1091. return self.template('<li data-id="{{name}}" class="tablink {{active}}">{{name}}</li>', {
  1092. name: con.name,
  1093. active: (self.current_tab === con.name ? 'active' : '')
  1094. });
  1095. }).join("\n") + '</ul>';
  1096. /* var tabs_content = _.map(self.editorContexts,function(con, name){
  1097. return self.template('<div id="t_{{name}}" class="tab-content">{{body}}</li>', {body: con(), name: name, });
  1098. }).join("\n");
  1099. */
  1100. var str = "";
  1101. if (self.current_tab) {} else {
  1102. self.current_tab = self.editorContexts[0].name;
  1103. }
  1104. str = self.editorContexts.filter((con) => con.name === self.current_tab).pop().func(obj, types);
  1105. return tabs_links + '<div id="etabcontent">' + str + '</div>';
  1106. }
  1107. Asystem.prototype.editorTypes = function() {
  1108. var self = this;
  1109. var types = {
  1110. jsfuncs: function(obj, fiels) {
  1111. var qq = [];
  1112. _.map(_.omit(obj, ignores), function(val, prop) {
  1113. if (typeof(val) === "function") {
  1114. qq.push(["JS " + prop + '<li><button class="deletefunc" data-id="' + obj.path + "/." + prop + '">Delete</button></li>',
  1115. "<div class=\"status\"></div> <textarea class=jseditor data-id=\"" + obj.path + "/." + prop + "\">" + (obj[prop] + "") +
  1116. '</textarea> '
  1117. ]);
  1118. }
  1119. })
  1120. qq.push(["JS ", "<input class=\"createfunc\" data-id=\"" + obj.path + "\"> "]);
  1121. var ss = ('<div class="sas">' + qq.map(function(a) {
  1122. return '<div class="sa"><div class="inn"><div class="saa">' + (a[0] === false ? "" : a[0] + "") + '</div><div class="sab">' + a[1] +
  1123. '</div></div></div>'
  1124. }).join("\n") + '</div>');
  1125. return ss
  1126. },
  1127. relations: function(obj, field) {
  1128. var s = "";
  1129. var ss = []
  1130. _.map(obj._relations, function(rels, relname) {
  1131. var relators = _.keys(rels);
  1132. var sss = relators.slice(0, 25).map(function(relator) {
  1133. return '<li elepath="' + relator + '"><a href="#' + relator + '" class="elecontent" title="' + JSON.stringify(rels[relator].context).toHtmlEntities() +
  1134. '">' + relator + '</a> <button class="btn unrelate" data-id="' + obj
  1135. .path + '" data-rel="' + relname + '" data-rela="' + relator + '" >X</button></li> '
  1136. }).join("\n");;
  1137. ss.push([relname + "(" + relators.length + ")", sss]);
  1138. });
  1139. s += ss.map(function(a) {
  1140. return '<div><h3>' + a[0] + '</h3><div>' + a[1] + '</div></div>'
  1141. }).join("\n")
  1142. return s;
  1143. },
  1144. relationsadd: function(obj, field) {
  1145. var s = "";
  1146. s += '<li class="relationseditor" data-id="' + obj.path +
  1147. '"><input class="relout" type="text" placeholder="is what " /><em><select class=uniq_relnames target=".relout"></select>' +
  1148. '</em><hr> to: <input class="relaeditor" placeholder="find obj"><hr> as: <input type="text" class=relin data-id="' +
  1149. obj.path +
  1150. '" placeholder="as what " /> <select class=uniq_relnames target=".relin"></select><hr> with: <input class="what" type="text" > <button class="relateasto">Relate</button></li>';
  1151. return s;
  1152. },
  1153. templatepaths: function(obj, field) {
  1154. return "<div class=\"status\"></div>" + _.map(self.getRenderTemplate(obj), function(a) {
  1155. return '<li elepath="' + a.name + '" ><a href="#' + a.name + '" class="elecontent" title="' + a.from + ": " + a.data.toHtmlEntities() + '" > ' +
  1156. a.name +
  1157. '</a></li>'
  1158. }).join("\n");
  1159. },
  1160. visa: function(obj, field) {
  1161. function mkaa(obja) {
  1162. }
  1163. setTimeout(function() {
  1164. var cols = {
  1165. parent: "#000000",
  1166. child: "#ff00ff",
  1167. extends: "#00ff00",
  1168. inherits: "#ff0000",
  1169. isa: "#ff9900",
  1170. hasa: "#00ff99"
  1171. }
  1172. function lokup(tp) {
  1173. return cols[tp];
  1174. }
  1175. var graph = Viva.Graph.graph();
  1176. var graphics = Viva.Graph.View.svgGraphics(),
  1177. nodeSize = 10;
  1178. self.allchildren().filter(function(c) {
  1179. return c.path.indexOf("trash/") === -1 && c.path.indexOf("folders/") === -1 && c.path.indexOf("blobs/") === -1
  1180. }).slice(0, 100).map(function(c) {
  1181. graph.addNode(c.path);
  1182. _.map(c.children, function(child, name) {
  1183. graph.addLink(c.path, child().path, 'child')
  1184. });
  1185. _.map(c._isa, function(child, name) {
  1186. graph.addLink(c.path, child.path, 'isa')
  1187. });
  1188. _.map(c._hasa, function(child, name) {
  1189. graph.addLink(c.path, child.path, 'hasa')
  1190. });
  1191. _.map(c._extends, function(child, name) {
  1192. graph.addLink(c.path, child.path, 'extends')
  1193. });
  1194. _.map(c._inherits, function(child, name) {
  1195. graph.addLink( c.path,child.path, 'inherits')
  1196. });
  1197. _.map(c._relations, function(rels, relname) {
  1198. _.map(rels, function(child, name) {
  1199. graph.addLink(c.path, name, relname)
  1200. })
  1201. });
  1202. })
  1203. var a = obj.path
  1204. //graph.addNode(a, '91bad8ceeec43ae303790f8fe238164b');
  1205. /* _.map(obj.parents, function(parent, name) {
  1206. graph.addNode(name, '');
  1207. graph.addLink(name, a, 'parent')
  1208. });
  1209. */
  1210. /*
  1211. var ogs = gpath(obj, []);
  1212. console.log("OOOOOOOOOOOO", ogs);
  1213. var roo = obj.path,
  1214. nexta;
  1215. graph.addNode(roo, '');
  1216. while (ogs.length) {
  1217. nexta = ogs.shift();
  1218. graph.addLink(roo, nexta, 'parent')
  1219. roo = nexta;
  1220. }
  1221. roo = obj.path
  1222. _.map(obj.children, function(child, name) {
  1223. graph.addNode(name, '');
  1224. graph.addLink(roo, name, 'child')
  1225. });
  1226. _.map(obj._isa, function(child, name) {
  1227. graph.addNode(name, '');
  1228. graph.addLink(roo, name, 'isa')
  1229. });
  1230. _.map(obj._hasa, function(child, name) {
  1231. graph.addNode(name, '');
  1232. graph.addLink(roo, name, 'hasa')
  1233. });
  1234. _.map(obj._extends, function(child, name) {
  1235. graph.addNode(name, '');
  1236. graph.addLink(roo, name, 'extends')
  1237. });
  1238. _.map(obj._inherits, function(child, name) {
  1239. graph.addNode(name, '');
  1240. graph.addLink(name, roo, 'inherits')
  1241. });
  1242. */
  1243. var idas = 1;
  1244. var ida = function(){
  1245. return "ida"+(idas++)
  1246. }
  1247. graphics.node(function(node) {
  1248. var ui = Viva.Graph.svg('g');
  1249. var circle = Viva.Graph.svg('circle')
  1250. .attr('cx', 2)
  1251. .attr('cy', 2)
  1252. .attr('r', 2)
  1253. .attr('fill', obj.path === node.id ? "#ff0000" : "#dadada");
  1254. ui.append(circle);
  1255. var svgText = Viva.Graph.svg('text').attr('font-size', '12px').attr('y', '4px').text(node.id.split("/").pop());
  1256. ui.append(svgText);
  1257. return ui;
  1258. }).placeNode(function(nodeUI, pos) {
  1259. nodeUI.attr('transform',
  1260. 'translate(' +
  1261. (pos.x - nodeSize / 2) + ',' + (pos.y - nodeSize / 2) +
  1262. ')');
  1263. });
  1264. var createMarker = function(id) {
  1265. return Viva.Graph.svg('marker')
  1266. .attr('id', id)
  1267. .attr('viewBox', "0 0 10 10")
  1268. .attr('refX', "10")
  1269. .attr('refY', "5")
  1270. .attr('markerUnits', "strokeWidth")
  1271. .attr('markerWidth', "10")
  1272. .attr('markerHeight', "5")
  1273. .attr('orient', "auto");
  1274. },
  1275. marker = createMarker('Triangle');
  1276. marker.append('path').attr('d', 'M 0 0 L 10 5 L 0 10 z');
  1277. // Marker should be defined only once in <defs> child element of root <svg> element:
  1278. var defs = graphics.getSvgRoot().append('defs');
  1279. defs.append(marker);
  1280. var geom = Viva.Graph.geom();
  1281. graphics.link(function(link) {
  1282. // Notice the Triangle marker-end attribe:
  1283. var isParent = (link.data === 'parent');
  1284. var ui = Viva.Graph.svg('g');
  1285. var p = Viva.Graph.svg('path')
  1286. .attr('stroke', lokup(link.data) || "#000000")
  1287. .attr('fill', 'none')
  1288. .attr('marker-end', 'url(#Triangle)')
  1289. .attr('id', ida() )
  1290. ui.isParent = isParent; // remember for future.
  1291. ui.linka = link.data;
  1292. ui.ry = 50 //- (Math.random() * 100);
  1293. ui.pp = p;
  1294. var svgText = Viva.Graph.svg('text').attr("dy",-4).attr("class","slabel");
  1295. var textPath = Viva.Graph.svg("textPath");
  1296. textPath.attr("href","#"+p.id).attr("startOffset","25%").text( link.data+ " >");
  1297. svgText.append(textPath)
  1298. ui.tt = svgText;
  1299. ////<textPath xlink:href="#'+link.id+'">
  1300. // svgText.attr('xlink', link.id);
  1301. ui.append(svgText)
  1302. ui.append(p);
  1303. return ui;
  1304. }).placeLink(function(linkUI, fromPos, toPos) {
  1305. // using arc command: http://www.w3.org/TR/SVG/paths.html#PathDataEllipticalArcCommands
  1306. //var data = 'M' + fromPos.x + ',' + fromPos.y +
  1307. // ' A 4,' + linkUI.ry + ',-' + linkUI.ry + ',0,1,' + toPos.x + ',' + toPos.y;
  1308. var data = 'M' + fromPos.x + ',' + fromPos.y +
  1309. ' C ' + (fromPos.x+50)+' '+(fromPos.y+10)+','+ (toPos.x-50) + ' ' +(toPos.y-10) + ',' +toPos.x + ' ' + toPos.y ;
  1310. linkUI.pp.attr("d", data);
  1311. return;
  1312. // linkUI.tt.attr("y", ((fromPos.y + toPos.y) / 2) - linkUI.ry);
  1313. // linkUI.tt.attr("x", ((fromPos.x + toPos.x) / 2) );
  1314. if (linkUI.isParent) {
  1315. /* var ry = linkUI.isParent ? 4 : 0,
  1316. // using arc command: http://www.w3.org/TR/SVG/paths.html#PathDataEllipticalArcCommands
  1317. data = 'M' + fromPos.x + ',' + fromPos.y +
  1318. ' A 4,' + ry + ',-4,0,1,' + toPos.x + ',' + toPos.y;
  1319. linkUI.attr("d", data);
  1320. */
  1321. var data = 'M' + fromPos.x + ',' + fromPos.y +
  1322. 'L' + toPos.x + ',' + toPos.y;
  1323. linkUI.pp.attr("d", data);
  1324. }
  1325. if (linkUI.linka === 'isa') {
  1326. var data = 'M' + fromPos.x + ',' + fromPos.y +
  1327. 'L' + toPos.x + ',' + toPos.y;
  1328. linkUI.pp.attr("d", data);
  1329. }
  1330. if (linkUI.linka === 'hasa') {
  1331. // var data = 'M' + fromPos.x + ',' + fromPos.y +
  1332. // 'L' + toPos.x + ',' + toPos.y;
  1333. var ry = 4;
  1334. // using arc command: http://www.w3.org/TR/SVG/paths.html#PathDataEllipticalArcCommands
  1335. var data = 'M' + fromPos.x + ',' + fromPos.y +
  1336. ' A 4,' + ry + ',-4,0,1,' + toPos.x + ',' + toPos.y;
  1337. linkUI.pp.attr("d", data);
  1338. }
  1339. if (linkUI.linka === 'inherits') {
  1340. var data = 'M' + fromPos.x + ',' + fromPos.y +
  1341. 'L' + toPos.x + ',' + toPos.y;
  1342. linkUI.pp.attr("d", data);
  1343. }
  1344. if (linkUI.linka === 'extends') {
  1345. var data = 'M' + fromPos.x + ',' + fromPos.y +
  1346. 'L' + toPos.x + ',' + toPos.y;
  1347. linkUI.pp.attr("d", data);
  1348. }
  1349. if (linkUI.linka === 'child') {
  1350. var toNodeSize = nodeSize,
  1351. fromNodeSize = nodeSize;
  1352. var from = geom.intersectRect(
  1353. // rectangle:
  1354. fromPos.x - fromNodeSize / 2, // left
  1355. fromPos.y - fromNodeSize / 2, // top
  1356. fromPos.x + fromNodeSize / 2, // right
  1357. fromPos.y + fromNodeSize / 2, // bottom
  1358. // segment:
  1359. fromPos.x, fromPos.y, toPos.x, toPos.y) || fromPos; // if no intersection found - return center of the node
  1360. var to = geom.intersectRect(
  1361. // rectangle:
  1362. toPos.x - toNodeSize / 2, // left
  1363. toPos.y - toNodeSize / 2, // top
  1364. toPos.x + toNodeSize / 2, // right
  1365. toPos.y + toNodeSize / 2, // bottom
  1366. // segment:
  1367. toPos.x, toPos.y, fromPos.x, fromPos.y) || toPos; // if no intersection found - return center of the node
  1368. var data = 'M' + from.x + ',' + from.y +
  1369. 'L' + to.x + ',' + to.y;
  1370. linkUI.pp.attr("d", data);
  1371. }
  1372. });
  1373. // graph.addNode( b, 'd43e8ea63b61e7669ded5b9d3c2e980f');
  1374. // graph.addLink(a, b);
  1375. /*
  1376. graphics.link(function(link) {
  1377. var isParent = (link.data === 'parent'),
  1378. ui = Viva.Graph.svg('path')
  1379. .attr('stroke', isParent ? 'red' : 'blue')
  1380. .attr('fill', 'none');
  1381. ui.isParent = isParent; // remember for future.
  1382. return ui;
  1383. }).placeLink(function(linkUI, fromPos, toPos) {
  1384. // linkUI - is the object returend from link() callback above.
  1385. var ry = linkUI.isParent ? 10 : 0,
  1386. // using arc command: http://www.w3.org/TR/SVG/paths.html#PathDataEllipticalArcCommands
  1387. data = 'M' + fromPos.x + ',' + fromPos.y +
  1388. ' A 10,' + ry + ',-30,0,1,' + toPos.x + ',' + toPos.y;
  1389. // 'Path data' (http://www.w3.org/TR/SVG/paths.html#DAttribute )
  1390. // is a common way of rendering paths in SVG:
  1391. linkUI.attr("d", data);
  1392. });
  1393. */
  1394. var layout = Viva.Graph.Layout.forceDirected(graph, {
  1395. springLength: 80,
  1396. springCoeff: 0.00001,
  1397. dragCoeff: 0.001,
  1398. gravity: -1.2
  1399. });
  1400. var renderer = Viva.Graph.View.renderer(graph, {
  1401. graphics: graphics,
  1402. container: document.getElementById('visagraf'),
  1403. layout: layout
  1404. });
  1405. renderer.run();
  1406. }, 200)
  1407. return '<div id="visagraf" class="svga">v</div>'
  1408. },
  1409. meta: function(obj, field) {
  1410. return "<div class=\"status\"></div> <textarea class=dataeditor data-id=\"" + obj.path + "/._metas\">" + JSON.stringify(obj._metas, true, 2) + '</textarea>'
  1411. },
  1412. data: function(obj, field) {
  1413. return "<div class=\"status\"></div> <textarea class=dataeditor data-id=\"" + obj.path + "/._data\">" + JSON.stringify(obj._data, true, 2) + '</textarea>'
  1414. },
  1415. hasas: function(obj, field) {
  1416. return '<div class="hasas">' + _.map(obj._hasa, function(tob, name) {
  1417. return self.template(
  1418. '<li elepath="{{tob.path}}" pelepath="{{obj.path}}" ><a href="#{{name}}" class="elecontent">{{name}}</a> <button class="btn unhasa">X</button></li>', {
  1419. tob: tob,
  1420. obj: obj,
  1421. name: name
  1422. });
  1423. }).join("\n") + '</div>'
  1424. },
  1425. isas: function(obj, field) {
  1426. return '<div class="isas">' + _.map(obj._isa, function(tob, name) {
  1427. return self.template(
  1428. '<li elepath="{{tob.path}}" pelepath="{{obj.path}}" ><a href="#{{name}}" class="elecontent">{{name}}</a> <button class="btn unisa">X</button></li>', {
  1429. tob: tob,
  1430. obj: obj,
  1431. name: name
  1432. });
  1433. }).join("\n") + '</div>' + self.template('<input class=isaeditor data-id="{{obj.path}}" placeholder="find isas here.." />', {
  1434. obj: obj
  1435. });
  1436. },
  1437. extends: function(obj, field) {
  1438. return '<div class="extends">' + _.map(obj._extends, function(tob, name) {
  1439. return self.template(
  1440. '<li elepath="{{tob.path}}" pelepath="{{obj.path}}" ><a href="#{{name}}" class="elecontent">{{name}}</a> <button class="btn unextend">X</button></li>', {
  1441. tob: tob,
  1442. obj: obj,
  1443. name: name
  1444. });
  1445. }).join("\n") + '</div>' + self.template('<input class=extendeditor data-id="{{obj.path}}" placeholder="find inheritants here.." />', {
  1446. obj: obj
  1447. });
  1448. },
  1449. inherits: function(obj, field) {
  1450. return '<div class="inherits">' + _.map(obj._inherits, function(tob, name) {
  1451. return self.template(
  1452. '<li elepath="{{tob.path}}" pelepath="{{obj.path}}" ><a href="#{{name}}" class="elecontent">{{name}}</a> <button class="btn uninherit">X</button></li>', {
  1453. tob: tob,
  1454. obj: obj,
  1455. name: name
  1456. });
  1457. }).join("\n") + '</div>' + self.template('<input class=inheriteditor data-id="{{obj.path}}" placeholder="find extenders here.." />', {
  1458. obj: obj
  1459. });
  1460. },
  1461. children: function(obj, field) {
  1462. var s = '';
  1463. s += mmb("Add child", "<input type=\"text\" class=addchildeditor data-id=\"" + obj.path + "\" value=\"" + '"> ');
  1464. s += '<div class="children">' + _.map(obj.children, function(a) {
  1465. return a().path
  1466. }).map(function(k) {
  1467. return '<li elepath="' + k + '" pelepath="' + obj.path + '"><a href="#' + k + '" class="elecontent" > ' + k +
  1468. '</a> '
  1469. }).join("\n") + '</div>'
  1470. return s;
  1471. },
  1472. info: function(obj, field) {
  1473. return "Path: " + obj.path
  1474. },
  1475. upload: function(obj, field) {
  1476. return (
  1477. '<div class="upload-btn-wrapper"><button class="btn" onclick="$(\'#myupload\').click()">Upload files</button><input id="myupload" type="file" class="afile" style="opacity: 0;" name="file1" multiple data-id="' +
  1478. obj.path +
  1479. '" data-action="browser_handlefilen" data-emit="filesloaded" /></div> ');
  1480. },
  1481. content: function(obj, field) {
  1482. var content_type = "<div><input type=\"text\" class=propeditor data-id=\"" + obj.path + "/._metas.type\" value=\"" +
  1483. obj._metas.type +
  1484. '">' + "<select class=propselector data-id=\"" + obj.path + "/._metas.type\"></select></div>";
  1485. var s = '';
  1486. s += mmb("Title", types.propeditor(obj, {
  1487. "path": "_data.title"
  1488. }))
  1489. if (obj._metas.type && obj._metas.type == "html") {
  1490. s += mmb("Content", "<div class=\"adj\"><div class=\"status\"></div> <textarea class=mceeditor data-id=\"" + obj.path + "/._data.content\">" + obj._data.content +
  1491. '</textarea></div>')
  1492. } else {
  1493. s += mmb("Body", "<div class=\"adj\"><div class=\"status\"></div> <textarea class=htmleditor data-id=\"" + obj.path + "/._data.content\">" + obj._data.content +
  1494. '</textarea></div>')
  1495. }
  1496. s += mmb("Type", content_type);
  1497. return s;
  1498. },
  1499. template: function(obj, field) {
  1500. return "<textarea class=htmleditor data-id=\"" + obj.path + "/._data.template\">" + obj._data.template +
  1501. '</textarea>'
  1502. },
  1503. texteditor: function(obj, field) {
  1504. var s = "";
  1505. s += '<textarea data-id="' + obj.path + '">' + opath.get(obj, field.path) + '</textarea>'
  1506. return s
  1507. },
  1508. propeditor: function(obj, field) {
  1509. var s = "";
  1510. s += '<input class="propeditor" data-id="' + obj.path + '/.' + field.path + '" value="' + opath.get(obj, field.path) + '">'
  1511. return s
  1512. },
  1513. lookup: function(obj, field) {
  1514. var temps = obj.getStuff3(field.path, function(a) {
  1515. return a
  1516. }, field.path)
  1517. var current_name = "",
  1518. current_data = "";
  1519. if (temps.length > 0) {
  1520. current_name = temps[0].name
  1521. current_data = temps[0].data;
  1522. }
  1523. var s = ''; //' <input type="text" data-id="'+obj.path+'/.'+field.path+'" value="' + opath.get(obj,field.path) + '">'
  1524. var path = opath.get(obj, field.path);
  1525. if (current_name !== "" && !path) {
  1526. path = opath.get(self.oget(current_name), field.path);
  1527. s += ' inherit <a elepath="' + path + '" href="#' + path + '" class="elecontent" > ' + path + '</a>';
  1528. s += ' from ' + '<a elepath="' + current_name + '" href="#' + current_name + '" class="elecontent" > ' + current_name + '</a>'
  1529. } else {
  1530. if (!path) {
  1531. s += 'no object selected'
  1532. } else {
  1533. s += 'Current: <li> <a elepath="' + path + '" href="#' + path + '" class="elecontent" > ' + path + '</a> <button class="btn unset" data-id="' + obj.path +
  1534. '" ele-prop="' + field.path + '">X</button> </li>';
  1535. }
  1536. }
  1537. s += "<br><input class=\"propselector22\" ele-has=\"" + field.has + "\" ele-list=\"" + field.lookup + "\" ele-pick=\"" + field.pick + "\" data-id=\"" + obj.path +
  1538. "\" ele-prop=\"" + field.path + "\" >";
  1539. return s;
  1540. },
  1541. lookup2: function(obj, field) {
  1542. var temps = obj.getStuff3(field.path, function(a) {
  1543. return a
  1544. }, field.path)
  1545. var current_name = "",
  1546. current_data = "";
  1547. if (temps.length > 0) {
  1548. current_name = temps[0].name
  1549. current_data = temps[0].data;
  1550. }
  1551. var s = ''; //' <input type="text" data-id="'+obj.path+'/.'+field.path+'" value="' + opath.get(obj,field.path) + '">'
  1552. s += "<select class=propselector2 data-has=\"" + field.has + "\" data-list=\"" + field.lookup + "\" data-pick=\"" + field.pick + "\" data-id=\"" +
  1553. obj.path + "/." +
  1554. field.path + "\"></select>";
  1555. var path = opath.get(obj, field.path);
  1556. if (current_name !== "" && !path) {
  1557. path = opath.get(self.oget(current_name), field.path);
  1558. s += ' inherit <a elepath="' + path + '" href="#' + path + '" class="elecontent" > ' + path + '</a>';
  1559. s += ' from ' + '<a elepath="' + current_name + '" href="#' + current_name + '" class="elecontent" > ' + current_name + '</a>'
  1560. } else {
  1561. s += '<a elepath="' + path + '" href="#' + path + '" class="elecontent" > ' + path + '</a>';
  1562. }
  1563. return s;
  1564. }
  1565. }
  1566. return types;
  1567. }
  1568. Asystem.prototype.renderEditor2a = function(obj) {
  1569. var self = this;
  1570. var stash = [];
  1571. // stash.push(["Parent", '<div class="parents">' + self.template("{{parents::}}", obj) + '</div>']);
  1572. // stash.push(["Path", "<input type=\"text\" class=patheditor data-id=\"" + obj.path + "\" value=\"" + obj.path + '">']);
  1573. /* stash.push(["Title", "<div class=\"status\"></div> <input type=\"text\" class=propeditor data-id=\"" + obj.path + "/._data.title\" value=\"" + obj._data.title +
  1574. '">'
  1575. ]);
  1576. */
  1577. /* if (obj.name !== "root") {
  1578. (self.oget("root")._metas.fields || []).map(function(field) {
  1579. stash.push([field.title, types[field.type](obj, field)]);
  1580. })
  1581. }*/
  1582. /*
  1583. if (obj._metas && obj.name !== "root") {
  1584. (obj._metas.fields || []).map(function(field) {
  1585. stash.push([field.title, types[field.type](obj, field)]);
  1586. })
  1587. }*/
  1588. function mkmod(obj, field) {
  1589. var data = "";
  1590. if (types[field.type]) {
  1591. data = types[field.type](obj, field)
  1592. } else {
  1593. data = field.data;
  1594. }
  1595. var s = '<div class="module ' + field.type + '" ><div class="head">' + field.title + '</div><div class="content">' + data + '</div></div>'
  1596. return s
  1597. }
  1598. function mkmodg(name, title, data) {
  1599. var s = '<div id="m_' + name + '" class="modulegroup" ><div class="head">' + title + '</div><div class="content">' + data + '</div></div>'
  1600. return s
  1601. }
  1602. function mktab() {
  1603. }
  1604. var xx = []
  1605. if (obj._metas.notself) {} else {
  1606. var fff = obj.getStuff("_metas.fields", function(a) {
  1607. return a
  1608. }, "fi");
  1609. fff.map(function(ff) {
  1610. ff.data.map(function(field) {
  1611. xx.push(mkmod(obj, field));
  1612. })
  1613. })
  1614. }
  1615. stash.push([" ", mkmodg("info", " ", [mkmod(obj, {
  1616. "type": "info",
  1617. "title": "Info",
  1618. "data": "Path: " + obj.path
  1619. }), '<div id="editorbuttons" class="buttons"></div>'].join("\n"))]);
  1620. /* var qq = []
  1621. qq.push(mkmod(obj, {
  1622. "title": "Path",
  1623. "data": "<input type=\"text\" class=patheditor data-id=\"" + obj.path + "\" value=\"" + obj.path + '">'
  1624. }));
  1625. qq.push(mkmod(obj, {
  1626. "title": "Parents",
  1627. "data": self.template("{{parents::}}", obj)
  1628. }));
  1629. stash.push([" ", mkmodg("content", " ", qq.join("\n"))]);
  1630. */
  1631. stash.push([" ", mkmodg("content", " ", xx.join("\n"))]);
  1632. var left = [];
  1633. var right = [];
  1634. right.push(mkmod(obj, {
  1635. "type": "children",
  1636. "title": "Children"
  1637. }));
  1638. left.push(mkmod(obj, {
  1639. "type": "inherits",
  1640. "title": "Inherits"
  1641. }));
  1642. left.push(mkmod(obj, {
  1643. "type": "extends",
  1644. "title": "Extends"
  1645. }));
  1646. stash.push([" ", '<div class="dleft">' + mkmodg("x", " ", left.join("\n")) + '</div><div class="dright">' + mkmodg("y", " ", right.join("\n")) + '</div>']);
  1647. stash.push([" ", '<div class="toolsa">' + mkmodg("tools", " ", [mkmod(obj, {
  1648. "type": "upload",
  1649. "title": "Upload"
  1650. }), mkmod(obj, {
  1651. "type": "clone",
  1652. "title": "Clone",
  1653. "data": "<div class=\"status\"></div> <input type=\"text\" class=cloneeditor data-id=\"" + obj.path + "\" value=\"" + '"> '
  1654. }), mkmod(obj, {
  1655. "type": "delete",
  1656. "title": "Delete",
  1657. "data": '<li> <button class="deleteele" data-id="' + obj.path + '">Trash</button> <button class="zapele" data-id="' + obj.path +
  1658. '">Delete Permanently</button></li>'
  1659. })].join("\n")) + '</div>']);
  1660. var left = [];
  1661. var right = [];
  1662. left.push(mkmod(obj, {
  1663. "type": "isas",
  1664. "title": "Is a thing"
  1665. }))
  1666. right.push(mkmod(obj, {
  1667. "type": "hasas",
  1668. "title": "Is thing to something"
  1669. }))
  1670. stash.push([" ", '<div class="dleft">' + mkmodg("xx", " ", left.join("\n")) + '</div><div class="dright">' + mkmodg(",yy", " ", right.join("\n")) + '</div>']);
  1671. var xx = [];
  1672. xx.push(mkmod(obj, {
  1673. "type": "template",
  1674. "title": "Template"
  1675. }))
  1676. xx.push(mkmod(obj, {
  1677. "type": "templatepaths",
  1678. "title": "Paths"
  1679. }))
  1680. stash.push([" ", mkmodg("x", "Template", xx.join("\n"))]);
  1681. stash.push([" ", "<hr>"]);
  1682. /* stash.push(["Icon", "<div class=\"status\"></div> <input type=\"text\" class=iconselecter data-id=\"" + obj.path + "/._data.iconclass\" value=\"" + obj._data.iconclass +
  1683. '"> '
  1684. ]);
  1685. */
  1686. if (obj._data.data && obj._data.data.length > 8192) {
  1687. stash.push(["Data too big", obj._data.data.length + " :" + obj._data.data.substring(0, 200)])
  1688. } else {
  1689. stash.push(["Data", "<div class=\"status\"></div> <textarea class=dataeditor data-id=\"" + obj.path + "/._data\">" + JSON.stringify(obj._data, true, 2) +
  1690. '</textarea>'
  1691. ]);
  1692. }
  1693. stash.push(["Meta", "<div class=\"status\"></div> <textarea class=dataeditor data-id=\"" + obj.path + "/._metas\">" + JSON.stringify(obj._metas, true, 2) +
  1694. '</textarea>'
  1695. ]);
  1696. _.map(_.omit(obj, ignores), function(val, prop) {
  1697. if (typeof(val) === "function") {
  1698. stash.push(["JS " + prop + '<li><button class="deletefunc" data-id="' + obj.path + "/." + prop + '">Delete</button></li>',
  1699. "<div class=\"status\"></div> <textarea class=jseditor data-id=\"" + obj.path + "/." + prop + "\">" + (obj[prop] + "") +
  1700. '</textarea> '
  1701. ]);
  1702. }
  1703. })
  1704. stash.push(["JS ", "<input class=\"createfunc\" data-id=\"" + obj.path + "\"> "]);
  1705. var ss = ('<div class="stash">' + stash.map(function(a) {
  1706. return '<div class="stt"><div class="inn"><div class="st1">' + (a[0] === false ? "" : a[0] + "") + '</div><div class="st2">' + a[1] +
  1707. '</div></div></div>'
  1708. }).join("\n") + '</div>');
  1709. return ss
  1710. }
  1711. Asystem.prototype.renderEditor3 = function(obj) {
  1712. var self = this;
  1713. var stash = [];
  1714. var prot = {}
  1715. var meta = {}
  1716. allchildren(obj).map(function(c) {
  1717. var arr = opath.flatten(c._data, "");
  1718. arr.map(function(a) {
  1719. prot[a[0]] = prot[a[0]] || {}
  1720. prot[a[0]][a[1]] = prot[a[0]][a[1]] || 0
  1721. prot[a[0]][a[1]] += 1;
  1722. })
  1723. var arr = opath.flatten(c._metas, "");
  1724. arr.map(function(a) {
  1725. if (a[0].indexOf('_wp_attachment_backup_sizes') > -1) {
  1726. return;
  1727. }
  1728. meta[a[0]] = meta[a[0]] || {}
  1729. meta[a[0]][a[1]] = meta[a[0]][a[1]] || 0
  1730. meta[a[0]][a[1]] += 1;
  1731. })
  1732. });
  1733. var prota = _.map(prot, function(vala, nama) {
  1734. return nama + " : " + _.size(vala)
  1735. });
  1736. var metas = _.map(meta, function(vala, nama) {
  1737. return nama + " : " + _.size(vala)
  1738. });
  1739. stash.push(["Data Properties", '<pre>' + JSON.stringify(prota, true, 2) + '</pre>'])
  1740. stash.push(["Meta Properties", '<pre>' + JSON.stringify(metas, true, 2) + '</pre>'])
  1741. var ss = ('<div class="stash">' + stash.map(function(a) {
  1742. return '<div class="stt"><div class="st1">' + (a[0] === false ? "" : a[0] + "") + '</div><div class="st2">' + a[1] + '</div></div>'
  1743. }).join("\n") + '</div>');
  1744. return ss
  1745. }
  1746. Asystem.prototype.getRenderTemplate = function(obj) {
  1747. var self = this;
  1748. var stash = [];
  1749. var templates = []
  1750. var temps = obj.getStuff3("_data.template", function(a) {
  1751. return a
  1752. }, "_data.template")
  1753. var myself;
  1754. var x = {};
  1755. temps.map(function(a) {
  1756. x[a.name] = a
  1757. });
  1758. temps = _.map(x, function(a) {
  1759. return a
  1760. });
  1761. return temps
  1762. }
  1763. Asystem.prototype.rendertemplate2 = function(obj) {
  1764. var self = this;
  1765. var stash = [];
  1766. var templates = []
  1767. var temps = obj.getStuff3("_data.template", function(a) {
  1768. return a
  1769. }, "_data.template")
  1770. var myself;
  1771. var x = {};
  1772. temps.map(function(a) {
  1773. x[a.name] = a
  1774. });
  1775. temps = _.map(x, function(a) {
  1776. return a
  1777. });
  1778. var ss = '<div eletemplate="' + obj.path + '"> ' + self.template(obj._data.template, obj) + ' </div>'
  1779. return ss;
  1780. }
  1781. Asystem.prototype.rendertemplate = function(obj) {
  1782. var self = this;
  1783. var stash = [];
  1784. var templates = []
  1785. var temps = obj.getStuff3("_data.template", function(a) {
  1786. return a
  1787. }, "_data.template")
  1788. var myself;
  1789. var x = {};
  1790. temps.map(function(a) {
  1791. x[a.name] = a
  1792. });
  1793. temps = _.map(x, function(a) {
  1794. return a
  1795. });
  1796. if (obj._data.template && obj._data.template.indexOf("{{output}}") > -1) {
  1797. myself = temps.shift();
  1798. }
  1799. var outer = temps.filter(function(a) {
  1800. return a.data.indexOf("{{output}}") > -1
  1801. })
  1802. var otemp = "{{output}}"
  1803. var outera = "";
  1804. if (outer.length) {
  1805. outera = outer[0];
  1806. otemp = outer[0].data;
  1807. }
  1808. var output = temps.filter(function(a) {
  1809. return a.data.indexOf("{{output}}") === -1 && a.name.indexOf("menu") === -1 && a.name.indexOf("header") === -1 && a.from.indexOf("isa_") === -1
  1810. }).map(function(tmp) {
  1811. return '<div eletemplate="' + tmp.name + '"> ' + self.template(tmp.data, obj) + ' </div>';
  1812. }).join("\n")
  1813. var menus = temps.filter(function(a) {
  1814. return a.name.indexOf("menu") > -1
  1815. }).slice(0, 1).map(function(tmp) {
  1816. return '<div eletemplate="' + tmp.name + '"> ' + self.template(tmp.data, obj) + ' </div>';
  1817. }).join("\n")
  1818. var headers = temps.filter(function(a) {
  1819. return a.name.indexOf("header") > -1
  1820. }).slice(0, 1).map(function(tmp) {
  1821. return '<div eletemplate="' + tmp.name + '"> ' + self.template(tmp.data, obj) + ' </div>';
  1822. }).join("\n")
  1823. /*
  1824. var isas = temps.filter(function(a) {
  1825. return a.from.indexOf("isa_") > -1
  1826. }).map(function(tmp) {
  1827. console.log("ISA,",tmp);
  1828. if(tmp.inas.length>2){
  1829. var tma=tmp.inas.pop();
  1830. tma=tmp.inas.pop();
  1831. return '<div eletemplate="' + tmp.name + '">IIS ' + self.template(tmp.data, self.oget(tma)) + ' </div>';
  1832. }else{
  1833. return '<div eletemplate="' + tmp.name + '">IIS ' + self.template(tmp.data, self.oget(tmp.name)) + ' </div>';
  1834. }
  1835. }).join("\n")
  1836. */
  1837. if (myself) {
  1838. var ai = Object.assign({
  1839. "output": output,
  1840. "menu": menus,
  1841. "header": headers,
  1842. "selfie": JSON.stringify(temps, true, 2)
  1843. }, obj);
  1844. var ss = '<div eletemplate="' + myself.name + '"> ' + self.template(myself.data, ai) + ' </div>'
  1845. } else {
  1846. var ai = Object.assign({
  1847. "output": output,
  1848. "menu": menus,
  1849. "header": headers,
  1850. "selfie": JSON.stringify(temps, true, 2)
  1851. }, obj);
  1852. var ss = '<div eletemplate="' + outer.name + '"> ' + self.template(otemp, ai) + ' </div>'
  1853. }
  1854. return ss
  1855. }
  1856. Asystem.prototype.allchildren = function(ronly) {
  1857. var self = this;
  1858. var arr = [];
  1859. if (ronly) {
  1860. return [].concat.apply(arr, allchildren(self.oo[ronly]))
  1861. }
  1862. _.keys(self.oo).filter((k) => typeof(self.oo[k]) === "function").map(function(key) {
  1863. arr = [].concat.apply(arr, allchildren(self.oo[key]))
  1864. })
  1865. return arr;
  1866. }
  1867. Asystem.prototype.allchildpaths = function(ronly) {
  1868. var self = this;
  1869. var arr = [];
  1870. _.keys(self.oo).filter((k) => typeof(self.oo[k]) === "function").map(function(key) {
  1871. ronly ? (ronly === key ? arr = [].concat.apply(arr, allchildpaths(self.oo[key])) : null) : arr = [].concat.apply(arr, allchildpaths(self.oo[key]))
  1872. })
  1873. return arr;
  1874. }
  1875. module.exports = Asystem;