buildDom.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555
  1. (function (global, p5VendorJs) {
  2. if (!p5VendorJs.React) throw "Missing React"
  3. if (!p5VendorJs.ReactDOM) throw "Missing ReactDOM"
  4. if (!p5VendorJs.createReactClass) throw "Missing createReactClass"
  5. var React = p5VendorJs.React
  6. var ReactDOM = p5VendorJs.ReactDOM
  7. var createReactClass = p5VendorJs.createReactClass
  8. var h = React.createElement
  9. var DBG = 0
  10. var P5UI__RawHtml = createReactClass({
  11. componentDidMount: function () {
  12. if (this.props.rawHtml) {
  13. this.rootNode.innerHTML = this.props.rawHtml
  14. }
  15. },
  16. render: function () {
  17. return h('div', {
  18. ref: function (node) { this.rootNode = node; }.bind(this),
  19. })
  20. }
  21. })
  22. global.p5VendorJs['P5UI__RawHtml'] = P5UI__RawHtml
  23. var P5UI__FeatureEditForm = createReactClass({
  24. componentDidMount: function () {
  25. if(DBG)console.warn('P5UI__FeatureEditForm::componentDidMount this.rootNode', this.rootNode)
  26. jQuery(this.rootNode).find('textarea').autosize();
  27. jQuery(this.rootNode).find('.frm-help').popover({trigger:'hover'});
  28. jQuery(this.rootNode).find('.show-last-value input').on('input', function(e) {
  29. var input, btn, btnIco;
  30. input = jQuery(e.target);
  31. btn = input.next('.button-appendBack');
  32. btnIco = btn.find('.glyphicon');
  33. if (btn.attr('title') != input.val()) {
  34. btnIco.show();
  35. } else {
  36. btnIco.hide();
  37. }
  38. });
  39. jQuery(this.rootNode).find('.show-last-value').find('.button-appendBack').on('click', function(e) {
  40. var input, btn, btnIco;
  41. btn = jQuery(this);
  42. btnIco = btn.find('.glyphicon');
  43. input = btn.prev();
  44. if (input.is('input')) {
  45. if (btn.attr('title') != input.val()) {
  46. input.val(btn.attr('title'));
  47. btnIco.hide();
  48. }
  49. }
  50. });
  51. },
  52. submit: function (e) {
  53. if(DBG)console.warn('P5UI__FeatureEditForm::submit this.rootNode', this.rootNode)
  54. e.preventDefault()
  55. var formData = {};
  56. jQuery(this.rootNode).serializeArray().map(function(i) { formData[i.name] = i.value; });// TODO: edit Widget - send only updated fields
  57. // TODO: change Edit btn to return to edit record with fields -> show form
  58. var taskCont = jQuery(this.rootNode).parents('.AjaxTableTaskCnt').parent(); // jQuery('#{$this->_htmlID}_task').parent();
  59. //taskCont.empty();
  60. taskCont.children().fadeOut('slow');
  61. var alertCntWrap = jQuery('<div class="AjaxTableAlert AjaxTable-loading"></div>').prependTo(taskCont)
  62. , alertCnt = jQuery('<div class="container"></div>').prependTo(alertCntWrap);
  63. jQuery('<div class="alert alert-info"><div style="padding:0 0 0 20px; background:url(./icon/loading.gif) no-repeat left top;"> zapisywanie ... </div></div>').appendTo(alertCnt);
  64. function notifyAjaxCallback(data) {
  65. var notify = {}, outMsg = '';
  66. notify.type = (data && data.type)? data.type : '';
  67. notify.msg = (data && data.msg)? data.msg : '';
  68. switch (notify.type) {
  69. case 'success':
  70. if (!notify.msg) notify.msg = 'Dane poprawnie zaktualizowane';
  71. break;
  72. case 'info':
  73. if (!notify.msg) notify.msg = 'Nie wprowadzono żadnych zmian';
  74. break;
  75. case 'error':
  76. if (!notify.msg) notify.msg = 'Wystąpiły błędy';
  77. break;
  78. case 'warning':
  79. notify.type = 'warn';
  80. if (!notify.msg) notify.msg = 'Wystąpiły błędy';
  81. break;
  82. default:
  83. notify.msg = 'Nieznany błąd';
  84. if (data && data.errorCode) notify.msg += ' ' + data.errorCode;
  85. notify.type = '';
  86. }
  87. jQuery.notify(notify.msg, notify.type);
  88. var alertType = ('error' == data.type) ? 'danger' : data.type;
  89. outMsg = '<div class="alert alert-' + alertType + '">' + notify.msg + '</div>';
  90. return outMsg;
  91. }
  92. var idRecord = this.props.idRecord
  93. var tableLabelHtml = this.props.tableLabelHtml
  94. superagent
  95. .post(this.props.ajaxSaveUrl)
  96. .type('json') // header ĺapplication/x-www-form-urlencoded' requires type('form');
  97. .send({
  98. namespace: this.props.namespace,
  99. primaryKey: this.props.idRecord,
  100. form: formData
  101. })
  102. .set('Accept', 'application/json')
  103. .end(function(err, res) {
  104. var payload;
  105. if (err || !res.ok || 'application/json' !== res.type) {
  106. payload = {type: 'warning', msg: res.body.msg || 'Wystąpiły błędy', body: res.body};
  107. } else {
  108. payload = {type: 'success', msg: res.body.msg || '', body: res.body};
  109. }
  110. var data = res.body;
  111. alertCntWrap.removeClass('AjaxTable-loading');
  112. alertCnt.empty();
  113. if (false === ['success', 'info'].indexOf(payload.type)) {
  114. jQuery(errorTxt).appendTo(alertCnt);
  115. var errLinks = jQuery('<div class="breadcrumb"></div>').appendTo(alertCnt);
  116. jQuery('<a href="#" onclick="return tableAjaxBackToTable();"> <i class="icon-arrow-left"></i> Wróć do tabeli '+tableLabelHtml+'</a>').appendTo(errLinks);
  117. var backToEditBtn = jQuery('<a href="#EDIT/'+idRecord+'/' + Math.random(1).toString().substr(2) + '" class="btn btn-link btn-small"> <i class="icon-pencil"></i> Popraw dane '+idRecord+'</a>').appendTo(errLinks);
  118. backToEditBtn.on('click', function(){
  119. alertCnt.remove();
  120. taskCont.children().fadeIn('slow');
  121. return false;
  122. });
  123. } else {
  124. var outMsg = notifyAjaxCallback(payload);
  125. var out = '';
  126. out += outMsg;
  127. out += '<div class="breadcrumb">' +
  128. ' <a href="#" onclick="return tableAjaxBackToTable();" class="btn btn-link btn-sm"> <i class="glyphicon glyphicon-arrow-left"></i> Wróć do tabeli '+tableLabelHtml+'</a>' +
  129. ' <a href="#EDIT/'+idRecord+'/' + Math.random(1).toString().substr(2) + '" class="btn btn-link btn-sm"> <i class="glyphicon glyphicon-pencil"></i> Edytuj rekord '+idRecord+'</a>' +
  130. '</div>';
  131. jQuery(out).appendTo(alertCnt);
  132. // add rowFunctions from response
  133. if (data && data.rowFunctions && data.primaryKey) {
  134. var rowFunWrapNode = $('<div class="container"></div>').insertAfter(alertCnt);
  135. var rowFunListNode = $('<ul></ul>').appendTo(rowFunWrapNode);
  136. var keys = Object.keys(data.rowFunctions),
  137. total = keys.length,
  138. moreFuncBtnNode,
  139. moreFunctions = [],
  140. idx
  141. ;
  142. moreFunctions = keys.splice(3);
  143. keys.forEach(function(key) {
  144. var cellNode = $('<li></li>');
  145. var funObj = data.rowFunctions[key],
  146. funcNode = p5UI_TableAjax_generateFunctionNode(funObj, data.primaryKey, {ico: true, label: true})
  147. ;
  148. funcNode.appendTo(cellNode);
  149. cellNode.appendTo(rowFunListNode);
  150. });
  151. }
  152. }
  153. })
  154. },
  155. render: function () {
  156. if(DBG)console.warn('P5UI__FeatureEditForm::render this.props', this.props)
  157. var formProps = Object.assign({}, this.props)
  158. delete formProps.children
  159. return h('form', Object.assign(formProps, {
  160. ref: function (node) { this.rootNode = node; }.bind(this),
  161. onSubmit: this.submit.bind(this)
  162. }), this.props.children)
  163. }
  164. })
  165. global.p5VendorJs['P5UI__FeatureEditForm'] = P5UI__FeatureEditForm
  166. var P5UI__Typespecial = createReactClass({
  167. componentDidMount: function () {
  168. if(DBG)console.log('TS::componentDidMount (['+this.props.idField+'] '+this.props.fieldNamespace+') ...')
  169. // console.log('TS::componentDidMount (['+this.props.idField+'] '+this.props.fieldNamespace+') this.rootNode', this.rootNode) // OK
  170. var fldNode = jQuery(document.getElementById(this.props.fieldName)) // jQuery('#{$fName}')
  171. var tsNode = jQuery(this.rootNode) // jQuery('#ts-{$fName}')
  172. var ajaxDataUrlBase = this.props.ajaxDataUrlBase
  173. if (!fldNode && !tsNode) {
  174. console.log("BUG Missing fldNode or tsNode in P5UI__Typespecial")
  175. return;
  176. }
  177. if (!ajaxDataUrlBase) {
  178. console.log("BUG Missing ajaxDataUrlBase in P5UI__Typespecial")
  179. return;
  180. }
  181. fldNode.attr('name', '');
  182. fldNode.hide();
  183. if (fldNode.parent().hasClass('show-last-value')) {
  184. fldNode.parent().hide();
  185. }
  186. tsNode.attr('name', this.props.frmFldName)
  187. tsNode.attr('tabindex', fldNode.attr('tabindex'))
  188. var getFetchCallback = ('TypespecialVariable' === this.props.type)
  189. ? function (query, callback) {
  190. return function(res) {
  191. for (var i in res) {
  192. if (!res[i].name || res[i].id != res[i].name) {
  193. res[i].name = res[i].id + ': ' + res[i].name;
  194. }
  195. }
  196. callback(res);
  197. }
  198. }
  199. : function (query, callback) {
  200. return function(res) {
  201. var i, prefix, prefixLen;
  202. for (i in res) {
  203. prefix = '' + res[i].id;
  204. prefixLen = prefix.length;
  205. if (prefixLen > 0 && prefix !== res[i].name.substr(0, prefixLen)) {
  206. res[i].name = res[i].id + ': ' + res[i].name;
  207. }
  208. res[i]['\$order'] = 1 + (parseInt(i) || 0); // set order from request
  209. }
  210. callback(res);
  211. }
  212. }
  213. ;
  214. var scoreCallback = ('TypespecialVariable' === this.props.type)
  215. ? function(search) {
  216. var score = this.getScoreFunction(search);
  217. return function(item) {
  218. // console.log('score:item:', item, ', score:', score(item));
  219. if (search && search == item.id) {
  220. return 1;
  221. } else {
  222. return score(item);// score(item) * (1 + Math.min(item.watchers / 100, 1));
  223. }
  224. };
  225. }
  226. : function(query) {
  227. // console.log('Typespecial({$fName})::score: q(', query, ')');
  228. var score = this.getScoreFunction(query);
  229. return function(item) {
  230. var retScore = 0, lName = ('' + item.name).toLowerCase(), lQuery = query.toLowerCase();
  231. if (query.search(' ') > -1) {
  232. retScore = score(item);
  233. }
  234. else {
  235. if (lQuery + ':' == lName.substr(0, lQuery.length + 1)) {
  236. retScore = 100;
  237. } else if (lName.search(lQuery) > -1) {
  238. retScore = 90 - lName.search(lQuery);
  239. } else {
  240. retScore = 0;
  241. }
  242. }
  243. // console.log('Typespecial({$fName})::score: q(', lQuery, ') , retScore(', retScore, '), score(', score(item), '), item.name(', item.name, ') item.id:', item.id);
  244. return retScore;
  245. };
  246. }
  247. ;
  248. tsNode.selectize({
  249. theme: 'typespecial',
  250. valueField: 'id',
  251. labelField: 'id',
  252. searchField: 'name',
  253. sortField: ('TypespecialVariable' === this.props.type) ? 'name' : '$order', // TODO: skip in Typespecial - default sort field is '$order'
  254. create: this.props.create,
  255. delimiter: ';',
  256. dataAttr: 'typespecial',
  257. preload: this.props.preload || false,
  258. options: this.props.options,
  259. render: {
  260. item: function(item, escape) {
  261. return '<div>' +
  262. '<span class=\"name\">' + escape(item.name || item.id) + '</span>' +
  263. '</div>';
  264. },
  265. option: function(item, escape) {
  266. return '<div>' +
  267. '<span class=\"title\">' +
  268. escape(item.name || item.id) +
  269. '</span>' +
  270. '</div>';
  271. }
  272. },
  273. onItemAdd: function(value, item) {// Invoked when an item is selected.
  274. var curSel = this.options[value] || null, fieldExport;
  275. if (curSel && curSel.exports) {
  276. for (var i in curSel.exports) {
  277. fieldExport = jQuery('#ts-f' + i);
  278. if (fieldExport.length) {
  279. //console.log('--- onItemAdd fieldExport.selectize(',fieldExport.selectize,')', fieldExport);
  280. if (fieldExport.get(0).selectize) {
  281. fieldExport.get(0).selectize.addOption({id:curSel.exports[i], name:curSel.exports[i]});
  282. fieldExport.get(0).selectize.setValue(curSel.exports[i]);
  283. } else {
  284. //jQuery('#f' + i).val(curSel.exports[i]);
  285. }
  286. } else {
  287. fieldExport = jQuery('#f' + i);
  288. if (fieldExport.is('input')) {
  289. jQuery('#f' + i).val(curSel.exports[i]);
  290. } else if (fieldExport.is('select')) {
  291. //TODO: add option and select //jQuery('#f' + i).val(curSel.exports[i]);
  292. }
  293. }
  294. }
  295. }
  296. },
  297. score: scoreCallback,
  298. load: function(query, callback) {
  299. // if (!query.length) return callback(); // empty query at preload action
  300. $.ajax({
  301. url: ajaxDataUrlBase,
  302. data: 'q=' + encodeURIComponent(query),
  303. type: 'POST',
  304. error: function() {
  305. callback();
  306. },
  307. success: getFetchCallback(query, callback),
  308. });
  309. }
  310. });
  311. },
  312. render: function () {
  313. if(DBG)console.log('TS::render (['+this.props.idField+'] '+this.props.fieldNamespace+') props', this.props)
  314. return h('div', {
  315. 'className': "typespecial",
  316. 'style': { 'max-width': '366px' }
  317. }, [
  318. h('select', {
  319. 'ref': function (node) { this.rootNode = node; }.bind(this),
  320. }, this.props.children)
  321. ])
  322. }
  323. })
  324. global.p5VendorJs['P5UI__Typespecial'] = P5UI__Typespecial
  325. var P5UI__FeatureRowFunctions = createReactClass({
  326. componentDidMount: function () {
  327. if(DBG)console.warn('P5UI__FeatureRowFunctions::componentDidMount this.rootNode', this.rootNode)
  328. if (this.props.rawHtml) {
  329. if(DBG)console.warn('P5UI__FeatureRowFunctions::componentDidMount this.props.rawHtml', this.props.rawHtml)
  330. this.rootNode.innerHTML = this.props.rawHtml
  331. }
  332. },
  333. render: function () {
  334. var showLabels = this.props.showLabels || false
  335. var functions = this.props.functions || {}
  336. if (!this.props.id) return h('div', { 'className': 'alert alert-danger' }, "Missing ID")
  337. if(DBG)console.warn('P5UI__FeatureRowFunctions::render this.props', this.props)
  338. return h('div', {
  339. ref: function (node) { this.rootNode = node; }.bind(this),
  340. }, [
  341. ('hist' in functions)
  342. ? h('a', { className: "btn btn-xs btn-link", href: functions.hist.href.replace("{0}", this.props.id), title: functions.hist.title }, [ h('span', { className: functions.hist.ico }), h('span', { style: {'padding': '0 6px'} }, functions.hist.title) ])
  343. : null
  344. ,
  345. ('files' in functions)
  346. ? h('a', { className: "btn btn-xs btn-link", href: functions.files.href.replace("{0}", this.props.id), title: functions.files.title }, [ h('span', { className: functions.files.ico }), h('span', { style: {'padding': '0 6px'} }, functions.files.title) ])
  347. : null
  348. ,
  349. ('msgs' in functions)
  350. ? h('a', { className: "btn btn-xs btn-link", href: functions.msgs.href.replace("{0}", this.props.id), title: functions.msgs.title }, [ h('span', { className: functions.msgs.ico }), h('span', { style: {'padding': '0 6px'} }, functions.msgs.title) ])
  351. : null
  352. ,
  353. (this.props.viewMoreDropdown)
  354. ? h(P5UI__MoreFunctionsDropdownAjax, this.props.viewMoreDropdown)
  355. : null
  356. ,
  357. ])
  358. }
  359. })
  360. global.p5VendorJs['P5UI__FeatureRowFunctions'] = P5UI__FeatureRowFunctions
  361. var P5UI__MoreFunctionsDropdownAjax = createReactClass({
  362. componentDidMount: function () {
  363. jQuery(this.rootNode).popover({
  364. container: 'body',
  365. placement: 'bottom',
  366. trigger: 'click',
  367. // title: e.data.col + '<a href="#" class="glyphicon glyphicon-remove pull-right" onclick="return hidePopover();"></a>',
  368. title: 'Więcej funkcji dla rekordu nr ' + this.props.primaryKey, // '<div style="display:block;position:relative;padding:0 20px 0 0;">' + (this.props.friendly || colName) + ' <button type="button" class="close" onclick="return hidePopover();" style="position:absolute;right:0;top:0;">&times;</button>' + '</div>',
  369. html: true,
  370. content: 'TODO: list...', // this.renderListToString.bind(this),
  371. template: '' +
  372. '<div class="popover" role="tooltip" style="max-width:600px;width:400px;">' +
  373. '<div class="arrow"></div>' +
  374. '<div style="display:block;position:relative;">' +
  375. '<div class="popover-title">' +
  376. '</div>' +
  377. '</div>' +
  378. '<div class="popover-content"></div>' +
  379. '</div>'
  380. })
  381. this.setState({ 'isOpen': false })
  382. },
  383. componentWillUnmount: function () {
  384. if(DBG)console.warn("P5UI__MoreFunctionsDropdownAjax::componentWillUnmount")
  385. jQuery(this.rootNode).popover('destroy')
  386. },
  387. componentWillMount: function() {
  388. this._closeDropdownIfClickedOutside = function (event) {
  389. if (!this.state.isOpen) return;
  390. var idHtmlPopover = jQuery(this.rootNode).attr('aria-describedby')
  391. if(DBG)console.warn("P5UI__MoreFunctionsDropdownAjax::_closeDropdownIfClickedOutside idHtmlPopover:", idHtmlPopover)
  392. if (!idHtmlPopover) return;
  393. var popoverNode = document.getElementById(idHtmlPopover)
  394. var isClickedOutside = p5UI__clickedOutsideElement(popoverNode, event)
  395. if(DBG)console.warn("P5UI__MoreFunctionsDropdownAjax::_closeDropdownIfClickedOutside isClickedOutside:", isClickedOutside, 'this.rootNode', this.rootNode)
  396. if (isClickedOutside) {
  397. if (jQuery(this.rootNode).data("bs.popover")) {
  398. jQuery(this.rootNode).popover('hide')
  399. } else {
  400. popoverNode.parentNode.removeChild(popoverNode) // DOM removed before 'hide'
  401. }
  402. this.setState({
  403. isOpen: false
  404. }, this._unbindCloseDropdownIfClickedOutside.bind(this));
  405. }
  406. }.bind(this);
  407. this._bindCloseDropdownIfClickedOutside = function () {
  408. if(DBG)console.warn("P5UI__MoreFunctionsDropdownAjax::_bindCloseDropdownIfClickedOutside", this._closeDropdownIfClickedOutside)
  409. if (!document.addEventListener && document.attachEvent) {
  410. document.attachEvent('onclick', this._closeDropdownIfClickedOutside);
  411. } else {
  412. document.addEventListener('click', this._closeDropdownIfClickedOutside);
  413. }
  414. }.bind(this);
  415. this._unbindCloseDropdownIfClickedOutside = function () {
  416. if(DBG)console.warn("P5UI__MoreFunctionsDropdownAjax::_unbindCloseDropdownIfClickedOutside", this._closeDropdownIfClickedOutside)
  417. if (!document.removeEventListener && document.detachEvent) {
  418. document.detachEvent('onclick', this._closeDropdownIfClickedOutside);
  419. } else {
  420. document.removeEventListener('click', this._closeDropdownIfClickedOutside);
  421. }
  422. }.bind(this);
  423. },
  424. shouldComponentUpdate: function (nextProps, nextState) {
  425. if (!nextState) return false
  426. if (!this.state) return false
  427. if (this.state.rowFunctions !== nextState.rowFunctions) {
  428. var idHtmlPopover = jQuery(this.rootNode).attr('aria-describedby')
  429. if(DBG)console.warn("P5UI__MoreFunctionsDropdownAjax::shouldComponentUpdate idHtmlPopover:", idHtmlPopover, 'nextState.rowFunctions', nextState.rowFunctions)
  430. if (idHtmlPopover && nextState.rowFunctions && nextState.rowFunctions.length) {
  431. jQuery(document.getElementById(idHtmlPopover)).find('.popover-content').html(this.renderListToString(nextState.rowFunctions))
  432. } else {
  433. jQuery(document.getElementById(idHtmlPopover)).find('.popover-content').html('<p class="text-muted">Brak dodatkowych funkcji</p>')
  434. }
  435. }
  436. return false
  437. },
  438. renderListToString: function (list) {
  439. if(DBG)console.warn('P5UI__MoreFunctionsDropdownAjax::renderListToString - this.state:', this.state)
  440. var primaryKey = this.props.id
  441. var out = '<ul class="list-unstyled">' + list.map(function (fun) {
  442. return '<li><a href="'+fun.href.replace('{0}', primaryKey)+'" style="margin:0 2px;" title="'+fun.title+'">' +
  443. (fun.ico ? '<span class="'+fun.ico+'"></span> ' : '') +
  444. (fun.label || fun.title) +
  445. '</a></li>'
  446. }).join('') + '</ul>'
  447. if(DBG)console.warn('P5UI__MoreFunctionsDropdownAjax::renderListToString - out:', out)
  448. return out
  449. },
  450. onAjaxFetch: function (data) {
  451. this.setState({ rowFunctions: data.rowFunctions })
  452. },
  453. handleClick: function (e) {
  454. e.preventDefault()
  455. if (!this.props.uri) throw "Missing uri in P5UI__MoreFunctionsDropdownAjax"
  456. if (this.state.isOpen) {
  457. jQuery(this.rootNode).popover('hide')
  458. } else {
  459. jQuery(this.rootNode).popover('show')
  460. var idHtmlPopover = jQuery(this.rootNode).attr('aria-describedby')
  461. if (idHtmlPopover) {
  462. jQuery(document.getElementById(idHtmlPopover)).find('.popover-content').html('<p>Loading...</p>')
  463. }
  464. // global.fetch()
  465. // setTimeout(this.onAjaxFetch.bind(this, { msg: "Funkcje", type: "success", rowFunctions: [
  466. // { id: "msgs", ico: "glyphicon glyphicon-envelope", href: "index.php?_route=TableMsgs&_task=tableRow&idTable=13051&idRow=83", label: 'Wiadomości <span class="badge">0</badge>', title: "Wiadomości (0)" },
  467. // { ico: "glyphicon glyphicon-file", href: "https://biuro.biall-net.pl/dev-pl/se-master/index.php?_route=UrlAction_Ant&typeName=default_db:TEST_PERMS&primaryKey=83", label: 'Druki', title: "Druki" },
  468. // ] }), 1000)
  469. _popoverCellAjaxXhr = jQuery.ajax({
  470. type: 'GET',
  471. url: this.props.uri,
  472. dataType: 'json',
  473. contentType: "application/json; charset=utf-8",
  474. })
  475. .done(function(data, textStatus, jqXHR){
  476. if (data && 'success' === data.type) {
  477. var rowFunctions = (data.rowFunctions && data.rowFunctions.length > 0)
  478. ? data.rowFunctions
  479. : [];
  480. this.setState({ rowFunctions: data.rowFunctions })
  481. }
  482. }.bind(this))
  483. if (this.state.isOpen) this.setState({ 'isOpen': false })
  484. else this.setState({ 'isOpen': true }, this._bindCloseDropdownIfClickedOutside)
  485. }
  486. },
  487. render: function () {
  488. if(DBG)console.warn('P5UI__MoreFunctionsDropdownAjax::render this.props', this.props)
  489. return h('button', {
  490. className: 'btn btn-xs btn-link',
  491. ref: function (node) { this.rootNode = node; }.bind(this),
  492. onClick: this.handleClick.bind(this)
  493. }, [
  494. h('span', {'className':"glyphicon glyphicon-menu-hamburger"}),
  495. " Więcej "
  496. ]);
  497. }
  498. })
  499. global.p5VendorJs['P5UI__MoreFunctionsDropdownAjax'] = P5UI__MoreFunctionsDropdownAjax
  500. function buildDom(dom, target) {
  501. ReactDOM.render(buildReactNodeRec(dom), target)
  502. }
  503. function buildReactNodeRec(dom) {
  504. if (null === dom) return null
  505. if ('string' === typeof dom) return dom
  506. var nodeReactType = dom[0]
  507. if ('P5UI__' === nodeReactType.substr(0, 'P5UI__'.length)) {
  508. if (nodeReactType in global.p5VendorJs) nodeReactType = global.p5VendorJs[nodeReactType]
  509. }
  510. return h(nodeReactType,
  511. convertAttrsToReact(dom[0], dom[1]),
  512. (dom[2] && 'function' === typeof dom[2].map)
  513. ? dom[2].map(buildReactNodeRec)
  514. : dom[2]
  515. )
  516. }
  517. function convertAttrsToReact(tagName, attrs) {
  518. if (!attrs) return null
  519. if(DBG)console.log('todo convertAttrsToReact typeof attrs ('+ typeof attrs +') toString('+ attrs.toString() +')');
  520. if (!attrs.toString()) return null
  521. if ('class' in attrs) {
  522. attrs['className'] = attrs['class']
  523. delete attrs['class']
  524. }
  525. if ('input' === tagName && 'value' in attrs) { // fix input to uncontrolled
  526. attrs['defaultValue'] = attrs['value']
  527. delete attrs['value']
  528. }
  529. if ('input' === tagName && 'maxlength' in attrs) { // fix input to uncontrolled
  530. attrs['maxLength'] = attrs['maxlength']
  531. delete attrs['maxlength']
  532. }
  533. return attrs
  534. }
  535. global.p5UI__buildDom = buildDom
  536. })(window, window.p5VendorJs);