notes.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783
  1. AdminTools.showNotes = function() {
  2. if (!window.userNotesWindow) {
  3. userNotesWindow = new MODx.Window({
  4. height: 640,
  5. minHeight: 600,
  6. width: 1200,
  7. padding: '5px',
  8. title: _("admintools_notes"),
  9. stateful: false,
  10. items: [{
  11. xtype: 'panel',
  12. id: 'admintools-notes-panel',
  13. height: 548,
  14. autoWidth: true,
  15. layout: 'border',
  16. items: [{
  17. region: 'center',
  18. //title: 'Центральная панель',
  19. id: 'admintools-notes-panel1',
  20. autoScroll: true,
  21. unstyled: true,
  22. layout: 'anchor',
  23. bodyStyle: 'background-color:#fff;',
  24. height: 250,
  25. items: [{
  26. xtype: 'admintools-notes-grid',
  27. layout: 'anchor',
  28. anchor: '98%'
  29. }]
  30. //width: 400
  31. }, {
  32. region: 'south',
  33. id: 'admintools-notes-panel2',
  34. split: true,
  35. forceLayout: true,
  36. autoScroll: true,
  37. header: false,
  38. useSplitTips: true,
  39. unstyled: true,
  40. collapsed: false,
  41. collapsible: false,
  42. padding: '5px',
  43. layout: 'anchor',
  44. bodyStyle: 'background-color:#fafafa;',
  45. height: 250,
  46. items: [{
  47. //xtype: Ext.ComponentMgr.types['modx-texteditor'] ? 'modx-texteditor' : 'textarea',
  48. xtype: 'htmleditor',
  49. cls: 'admintools-note text',
  50. id: 'admintool-notes-text',
  51. readOnly: true,
  52. anchor: '100% 97%',
  53. style: 'background-color: #fff',
  54. enableSourceEdit: false,
  55. //enableKeyEvents: true,
  56. listeners: {
  57. render: function () {
  58. this.el.on('keydown', function (e) {
  59. this.fireEvent('sync', this, this.el.getValue());
  60. }, this, {buffer: 500});
  61. },
  62. sync: function (sender, html) {
  63. var e = Ext.EventObject;
  64. if (e.button > 0) {
  65. if (!AdminTools.currentNote.isDirty) AdminTools.currentNote.setDirty();
  66. }
  67. }
  68. }
  69. }]
  70. //width: 400
  71. }]
  72. }],
  73. buttonAlign: 'left',
  74. buttons: [{
  75. text: _("save"),
  76. id: 'admintools_btn_save',
  77. hidden: true,
  78. handler: function () {
  79. MODx.Ajax.request({
  80. url: adminToolsSettings.config.connector_url,
  81. params: {
  82. action: 'mgr/notes/updatetext',
  83. id: AdminTools.currentNote.id,
  84. text: AdminTools.readPanel.getEditor().getValue() //AdminTools.currentNote.text
  85. },
  86. listeners: {
  87. success: {
  88. fn: function (r) {
  89. AdminTools.currentNote.sync().clearDirty(true);
  90. var row = Ext.getCmp('admintools-notes-grid').store.getById(AdminTools.currentNote.id);
  91. row.set('text', AdminTools.readPanel.getEditor().getValue());
  92. row.commit();
  93. }, scope: this
  94. },
  95. failure: {
  96. fn: function (r) {
  97. console.log(r);
  98. }
  99. }
  100. }
  101. });
  102. }
  103. }, {
  104. text: _("cancel"),
  105. id: 'admintools_btn_cancel',
  106. hidden: true,
  107. handler: function () {
  108. AdminTools.currentNote.clearDirty(false);
  109. AdminTools.readPanel.getEditor().setValue(AdminTools.currentNote.text);
  110. }
  111. }, '->', {
  112. text: _("admintools_close"),
  113. id: 'admintools_btn_close',
  114. handler: function () {
  115. userNotesWindow.hide();
  116. },
  117. scope: this
  118. }],
  119. listeners: {
  120. /*hide: {
  121. fn: function () {
  122. setTimeout(function () {
  123. userNotesWindow.destroy()
  124. }, 200);
  125. }
  126. },*/
  127. beforehide: {
  128. fn: function () {
  129. if (AdminTools.currentNote.isDirty) {
  130. Ext.MessageBox.alert(_('admintools_attention'), _("admintools_note_is_dirty"));
  131. return false;
  132. }
  133. }
  134. },
  135. resize: {
  136. fn: function (el, w, h) {
  137. Ext.getCmp('admintools-notes-panel').setHeight(h - 92);
  138. }
  139. }
  140. }
  141. });
  142. }
  143. userNotesWindow.show(Ext.EventObject.target);
  144. };
  145. AdminTools.grid.Notes = function (config) {
  146. config = config || {};
  147. if (!config.id) {
  148. config.id = 'admintools-notes-grid';
  149. }
  150. Ext.applyIf(config, {
  151. url: adminToolsSettings.config.connector_url,
  152. fields: ['id', 'title', 'text', 'private', 'username', 'createdon', 'createdby', 'url', 'tags', 'actions'],
  153. columns: this.getColumns(config),
  154. tbar: this.getTopBar(config),
  155. sm: new Ext.grid.RowSelectionModel(),
  156. baseParams: {
  157. action: 'mgr/notes/getlist'
  158. },
  159. listeners: {
  160. rowDblClick: function (grid, rowIndex, e) {
  161. this.updateNote(null, e, grid.store.getAt(rowIndex));
  162. },
  163. rowClick: function (grid, rowIndex, e) {
  164. if (AdminTools.currentNote.isDirty) {
  165. Ext.MessageBox.alert(_('admintools_attention'), _("admintools_note_is_dirty"));
  166. Ext.getCmp('admintools-notes-grid').selModel.selectRow(AdminTools.currentNote.rowIndex);
  167. return false;
  168. }
  169. var row = grid.store.getAt(rowIndex),
  170. editor = AdminTools.readPanel.getEditor();
  171. AdminTools.currentNote.set({title: row.data.title, text: row.data.text, id: row.data.id, rowIndex: rowIndex, user: row.data.createdby});
  172. editor.setValue(row.data.text);
  173. editor.setReadOnly(false);
  174. },
  175. rowcontextmenu: function (grid, rowIndex, e) {
  176. }
  177. },
  178. viewConfig: {
  179. forceFit: true,
  180. enableRowBody: true,
  181. autoFill: true,
  182. showPreview: true,
  183. scrollOffset: 0,
  184. getRowClass: function (rec, ri, p) {
  185. return !rec.data.private
  186. ? 'admintools-private-note'
  187. : '';
  188. }
  189. },
  190. paging: true,
  191. pageSize: 20,
  192. remoteSort: true
  193. //autoHeight: true
  194. });
  195. AdminTools.grid.Notes.superclass.constructor.call(this, config);
  196. // Clear selection on grid refresh
  197. this.store.on('load', function () {
  198. AdminTools.currentNote.reset();
  199. if (this._getSelectedIds().length) {
  200. this.getSelectionModel().clearSelections();
  201. }
  202. }, this);
  203. this.store.on('beforeload', function (e) {
  204. if (AdminTools.currentNote.isDirty) {
  205. Ext.MessageBox.alert(_('admintools_attention'), _("admintools_note_is_dirty"));
  206. return false;
  207. }
  208. }, this);
  209. };
  210. Ext.extend(AdminTools.grid.Notes, MODx.grid.Grid, {
  211. windows: {},
  212. getMenu: function (grid, rowIndex) {
  213. var ids = this._getSelectedIds();
  214. var row = grid.getStore().getAt(rowIndex);
  215. var menu = AdminTools.utils.getMenu(row.data['actions'], this, ids);
  216. this.addContextMenuItem(menu);
  217. },
  218. createNote: function (btn, e) {
  219. var w = MODx.load({
  220. xtype: 'admintools-note-create-window',
  221. id: Ext.id(),
  222. record: {editedby: '', editedon: ''},
  223. listeners: {
  224. success: {
  225. fn: function () {
  226. this.refresh();
  227. }, scope: this
  228. },
  229. hide: {
  230. fn: function () {
  231. setTimeout(function () {
  232. w.destroy()
  233. }, 200);
  234. }
  235. }
  236. }
  237. });
  238. w.reset();
  239. w.setValues({private: false});
  240. w.show(e.target);
  241. },
  242. updateNote: function (btn, e, row) {
  243. if (AdminTools.currentNote.isDirty) {
  244. Ext.MessageBox.alert(_('admintools_attention'), _("admintools_note_is_dirty"));
  245. return false;
  246. }
  247. if (typeof(row) != 'undefined') {
  248. this.menu.record = row.data;
  249. }
  250. else if (!this.menu.record) {
  251. return false;
  252. }
  253. var id = this.menu.record.id,
  254. editor = AdminTools.readPanel.getEditor();
  255. //TODO: Отражать в заголовке окна title заметки
  256. AdminTools.currentNote.set({title: this.menu.record.title, text: this.menu.record.text, id: id, user: this.menu.record.createdby});
  257. editor.setValue(this.menu.record.text);
  258. editor.setReadOnly(false);
  259. MODx.Ajax.request({
  260. url: this.config.url,
  261. params: {
  262. action: 'mgr/notes/get',
  263. id: id
  264. },
  265. listeners: {
  266. success: {
  267. fn: function (r) {
  268. var w = MODx.load({
  269. xtype: 'admintools-note-update-window',
  270. id: Ext.id(),
  271. record: r.object,
  272. listeners: {
  273. success: {
  274. fn: function (r) {
  275. //this.refresh();
  276. var note = r.a.result.object;
  277. if (AdminTools.currentNote.id && AdminTools.currentNote.id == note.id) {
  278. AdminTools.readPanel.getEditor().setValue(note.text);
  279. AdminTools.currentNote.sync();
  280. }
  281. var row = Ext.getCmp('admintools-notes-grid').store.getById(note.id);
  282. row.set('text', note.text);
  283. if (note.url == 'http://') note.url = '';
  284. if (note.url) {
  285. row.set('url', '<a href="' + note.url + '" target="_blank">' + note.url + '</a>');
  286. } else {
  287. row.set('url', '');
  288. }
  289. row.set('private', note.private);
  290. row.set('title', note.title);
  291. row.set('tags', note.tags);
  292. row.commit();
  293. }, scope: this
  294. },
  295. hide: {
  296. fn: function () {
  297. setTimeout(function () {
  298. w.destroy()
  299. }, 200);
  300. }
  301. }
  302. }
  303. });
  304. w.reset();
  305. w.setValues(r.object);
  306. w.show(e.target);
  307. }, scope: this
  308. }
  309. }
  310. });
  311. },
  312. removeNote: function (act, btn, e) {
  313. var ids = this._getSelectedIds();
  314. if (!ids.length) {
  315. return false;
  316. }
  317. MODx.msg.confirm({
  318. title: ids.length > 1
  319. ? _('admintools_notes_remove')
  320. : _('admintools_note_remove'),
  321. text: ids.length > 1
  322. ? _('admintools_notes_remove_confirm')
  323. : _('admintools_note_remove_confirm'),
  324. url: this.config.url,
  325. params: {
  326. action: 'mgr/notes/remove',
  327. ids: Ext.util.JSON.encode(ids)
  328. },
  329. listeners: {
  330. success: {
  331. fn: function (r) {
  332. this.refresh();
  333. }, scope: this
  334. }
  335. }
  336. });
  337. return true;
  338. },
  339. download:function(){
  340. MODx.Ajax.request({
  341. url: adminToolsSettings.config.connector_url,
  342. params: {
  343. action: 'mgr/notes/export'
  344. },
  345. listeners: {
  346. success: {
  347. fn: function (result) {
  348. location.href = adminToolsSettings.config.connector_url+"?action=mgr/notes/download&HTTP_MODAUTH="+MODx.siteId;
  349. }, scope: this
  350. },
  351. failure: {
  352. fn: function (result) {
  353. //panel.el.unmask();
  354. MODx.msg.alert(_('_error'), result.message);
  355. }, scope: this
  356. }
  357. }
  358. });
  359. },
  360. upload:function(){
  361. var input = document.getElementById('admintool_upload_notes');
  362. if (!input) {
  363. input = document.createElement('input');
  364. input.type = 'file';
  365. input.id = 'admintool_upload_notes';
  366. input.style = 'display:none';
  367. document.body.appendChild(input);
  368. input.addEventListener('change', this.handleFile, false);
  369. }
  370. input.click();
  371. },
  372. handleFile: function(e) {
  373. var grid = this;
  374. var file = e.target.files[0];
  375. var reader = new FileReader();
  376. reader.onload = function(e) {
  377. var content = e.target.result;
  378. MODx.Ajax.request({
  379. url: adminToolsSettings.config.connector_url,
  380. params: {
  381. action: 'mgr/notes/upload',
  382. content: content
  383. },
  384. listeners: {
  385. success: {
  386. fn: function () {
  387. Ext.getCmp('admintools-notes-grid').refresh();
  388. }, scope: this
  389. },
  390. failure: {
  391. fn: function (result) {
  392. //panel.el.unmask();
  393. MODx.msg.alert(_('_error'), result.message);
  394. }, scope: this
  395. }
  396. }
  397. });
  398. };
  399. reader.readAsText(file);
  400. },
  401. getColumns: function (config) {
  402. return [{
  403. header: 'ID',
  404. dataIndex: 'id',
  405. sortable: true,
  406. hidden: true,
  407. fixed: true,
  408. width: 70
  409. }, {
  410. header: _('admintools_notes_title'),
  411. dataIndex: 'title',
  412. sortable: true,
  413. width: 250
  414. }, {
  415. header: _('admintools_notes_url'),
  416. dataIndex: 'url',
  417. sortable: false,
  418. width: 120
  419. }, {
  420. header: _('admintools_notes_tags'),
  421. dataIndex: 'tags',
  422. sortable: false,
  423. width: 120
  424. }, {
  425. header: _('admintools_user'),
  426. dataIndex: 'username',
  427. sortable: true,
  428. width: 90
  429. }, {
  430. header: _('admintools_notes_createdon'),
  431. dataIndex: 'createdon',
  432. sortable: true,
  433. fixed: true,
  434. width: 140
  435. }, {
  436. header: _('admintools_notes_private'),
  437. dataIndex: 'private',
  438. renderer: AdminTools.utils.renderBoolean,
  439. sortable: true,
  440. fixed: true,
  441. width: 70
  442. }, {
  443. header: _('admintools_grid_actions'),
  444. dataIndex: 'actions',
  445. renderer: AdminTools.utils.renderActions,
  446. sortable: false,
  447. width: 70,
  448. fixed: true,
  449. id: 'actions'
  450. }, {
  451. header: _('admintools_notes_text'),
  452. dataIndex: 'text',
  453. sortable: false,
  454. hidden: true,
  455. width: 50
  456. }, {
  457. header: _('admintools_user'),
  458. dataIndex: 'createdby',
  459. sortable: true,
  460. hidden: true,
  461. width: 10
  462. }];
  463. },
  464. getTopBar: function (config) {
  465. return [{
  466. xtype: 'buttongroup',
  467. columns: 3,
  468. items: [{
  469. text: '<i class="icon icon-plus"></i>',
  470. handler: this.createNote,
  471. // style: {marginRight: '5px'},
  472. tooltip: _('admintools_create_note'),
  473. tooltipType: 'title',
  474. scope: this
  475. }, {
  476. text: '<i class="icon icon-download"></i>',
  477. handler: this.download,
  478. tooltip: _('admintools_export_notes'),
  479. tooltipType: 'title',
  480. // style: {marginRight: '5px'},
  481. scope: this
  482. }, {
  483. text: '<i class="icon icon-upload"></i>',
  484. handler: this.upload,
  485. tooltip: _('admintools_import_notes'),
  486. tooltipType: 'title',
  487. scope: this
  488. }]
  489. }, '->', {
  490. xtype: 'admintools-combo-wheresearch',
  491. name: 'wheresearch',
  492. width: 150,
  493. emptyText: _('admintools_search_where'),
  494. style: {marginRight: '20px'},
  495. editable: false,
  496. id: config.id + '-where-search'
  497. }, {
  498. xtype: 'textfield',
  499. name: 'searchQuery',
  500. width: 200,
  501. id: config.id + '-search-field',
  502. emptyText: _('admintools_grid_search'),
  503. style: {backgroundColor:'#fff'},
  504. listeners: {
  505. render: {
  506. fn: function (tf) {
  507. tf.getEl().addKeyListener(Ext.EventObject.ENTER, function () {
  508. this._search();
  509. }, this);
  510. }, scope: this
  511. }
  512. }
  513. }, {
  514. xtype: 'button',
  515. id: config.id + '-search-btn',
  516. text: '<i class="icon icon-search"></i>',
  517. listeners: {
  518. click: {fn: this._search, scope: this}
  519. }
  520. }, {
  521. xtype: 'button',
  522. id: config.id + '-search-clear',
  523. text: '<i class="icon icon-times"></i>',
  524. listeners: {
  525. click: {fn: this._clearSearch, scope: this}
  526. }
  527. }, {
  528. xtype: 'tbspacer', width: 2
  529. }]
  530. },
  531. onClick: function (e) {
  532. var elem = e.getTarget();
  533. if (elem.nodeName == 'BUTTON') {
  534. var row = this.getSelectionModel().getSelected();
  535. if (typeof(row) != 'undefined') {
  536. var action = elem.getAttribute('action');
  537. if (action == 'showMenu') {
  538. var ri = this.getStore().find('id', row.id);
  539. return this._showMenu(this, ri, e);
  540. }
  541. else if (typeof this[action] === 'function') {
  542. this.menu.record = row.data;
  543. return this[action](this, e);
  544. }
  545. }
  546. }
  547. return this.processEvent('click', e);
  548. },
  549. _getSelectedIds: function () {
  550. var ids = [];
  551. var selected = this.getSelectionModel().getSelections();
  552. for (var i in selected) {
  553. if (!selected.hasOwnProperty(i)) {
  554. continue;
  555. }
  556. ids.push(selected[i]['id']);
  557. }
  558. return ids;
  559. },
  560. _search: function (tf, nv, ov) {
  561. this.store.baseParams.searchQuery = Ext.getCmp(this.config.id + '-search-field').getValue();
  562. this.store.baseParams.wheresearch = Ext.getCmp(this.config.id + '-where-search').getValue();
  563. this.getBottomToolbar().changePage(1);
  564. AdminTools.currentNote.reset();
  565. //this.refresh();
  566. },
  567. _clearSearch: function (btn, e) {
  568. this.store.baseParams.searchQuery = '';
  569. Ext.getCmp(this.config.id + '-search-field').setValue('');
  570. AdminTools.currentNote.reset();
  571. this.getBottomToolbar().changePage(1);
  572. //this.refresh();
  573. }
  574. });
  575. Ext.reg('admintools-notes-grid', AdminTools.grid.Notes);
  576. /** ******************* Dialogs ********************** **/
  577. AdminTools.window.CreateNote = function (config) {
  578. config = config || {};
  579. if (!config.id) {
  580. config.id = 'admintools-note-create-window';
  581. }
  582. Ext.applyIf(config, {
  583. title: _('admintools_create_note'),
  584. width: 900,
  585. modal: true,
  586. maximizable: false,
  587. autoHeight: true,
  588. url: adminToolsSettings .config.connector_url,
  589. action: 'mgr/notes/add',
  590. fields: this.getFields(config),
  591. keys: [{
  592. key: Ext.EventObject.ENTER, shift: true, fn: function () {
  593. this.submit()
  594. }, scope: this
  595. }]
  596. });
  597. AdminTools.window.CreateNote.superclass.constructor.call(this, config);
  598. };
  599. Ext.extend(AdminTools.window.CreateNote, MODx.Window, {
  600. getFields: function (config) {
  601. return [{
  602. xtype: 'hidden',
  603. name: 'id',
  604. id: config.id + '-id'
  605. }, {
  606. xtype: 'textfield',
  607. fieldLabel: _('admintools_notes_title'),
  608. name: 'title',
  609. id: config.id + '-title',
  610. anchor: '100%',
  611. allowBlank: false
  612. }, {
  613. xtype: 'textfield',
  614. fieldLabel: _('admintools_notes_url'),
  615. emptyText: 'http://',
  616. name: 'url',
  617. id: config.id + '-url',
  618. anchor: '100%',
  619. allowBlank: true
  620. }, {
  621. xtype: 'textfield',
  622. fieldLabel: _('admintools_notes_tags'),
  623. name: 'tags',
  624. id: config.id + '-tags',
  625. anchor: '100%',
  626. allowBlank: true
  627. }, {
  628. xtype: 'htmleditor',
  629. fieldLabel: _('admintools_notes_text'),
  630. name: 'text',
  631. id: config.id + '-text',
  632. enableSourceEdit: false,
  633. height: 250,
  634. style: 'background-color: #fff',
  635. anchor: '100%'
  636. }, {
  637. layout: 'column'
  638. ,border: false
  639. ,anchor: '100%'
  640. ,items: [{
  641. columnWidth: .5
  642. ,layout: 'form'
  643. ,defaults: { msgTarget: 'qtip' }
  644. ,border:false
  645. ,items: [{
  646. xtype: 'xcheckbox',
  647. boxLabel: _('admintools_notes_private'),
  648. name: 'private',
  649. disabled: adminToolsSettings.currentUser !== AdminTools.currentNote.user && AdminTools.currentNote.id,
  650. id: config.id + '-private'
  651. }]
  652. },{
  653. columnWidth: .5
  654. ,layout: 'form'
  655. ,defaults: { msgTarget: 'qtip' }
  656. ,border:false
  657. ,items: [{
  658. //xtype: '',
  659. //boxLabel: _('admintools_notes_editedby'),
  660. html: _('admintools_notes_editedby') + ': ' + config.record.editedby + '. ' + _('admintools_notes_editedon') + ': ' + config.record.editedon,
  661. style: {marginTop: '20px', textAlign: 'right'}
  662. }]
  663. }]
  664. }];
  665. }
  666. });
  667. Ext.reg('admintools-note-create-window', AdminTools.window.CreateNote);
  668. // Update Dialog
  669. AdminTools.window.UpdateNote = function (config) {
  670. config = config || {};
  671. if (!config.id) {
  672. config.id = 'admintools-note-update-window';
  673. }
  674. Ext.applyIf(config, {
  675. title: _('admintools_note_edit'),
  676. action: 'mgr/notes/update'
  677. });
  678. AdminTools.window.UpdateNote.superclass.constructor.call(this, config);
  679. };
  680. Ext.extend(AdminTools.window.UpdateNote, AdminTools.window.CreateNote);
  681. Ext.reg('admintools-note-update-window', AdminTools.window.UpdateNote);
  682. /** ************************************************* **/
  683. Ext.onReady(function() {
  684. AdminTools.currentNote = {
  685. id: 0,
  686. text: '',
  687. title: '',
  688. isDirty: false,
  689. rowIndex: null,
  690. user: 0,
  691. set: function (data) { //text, id, rowIndex, user
  692. this.text = data.text ? data.text : '';
  693. this.title = data.title ? data.title : '';
  694. this.id = data.id ? data.id : 0;
  695. this.user = data.user ? data.user : 0;
  696. this.rowIndex = data.rowIndex ? data.rowIndex : null;
  697. },
  698. setDirty: function () {
  699. this.isDirty = true;
  700. Ext.getCmp('admintools_btn_save').setVisible(true);
  701. Ext.getCmp('admintools_btn_cancel').setVisible(true);
  702. userNotesWindow.setTitle(userNotesWindow.title + ' (*)');
  703. return this;
  704. },
  705. clearDirty: function (save) {
  706. this.isDirty = false;
  707. Ext.getCmp('admintools_btn_save').setVisible(false);
  708. Ext.getCmp('admintools_btn_cancel').setVisible(false);
  709. userNotesWindow.setTitle(userNotesWindow.title.replace(' (*)', ''));
  710. return this;
  711. },
  712. reset: function () {
  713. var editor = AdminTools.readPanel.getEditor();
  714. editor.setValue('');
  715. editor.setReadOnly(true);
  716. this.id = 0;
  717. this.text = '';
  718. this.isDirty = false;
  719. this.rowIndex = null;
  720. return this;
  721. },
  722. sync: function () {
  723. this.text = AdminTools.readPanel.getEditor().getValue();
  724. return this;
  725. }
  726. };
  727. AdminTools.readPanel = {
  728. editor: null,
  729. getEditor: function () {
  730. if (!this.editor) {
  731. this.editor = Ext.getCmp('admintool-notes-text');
  732. }
  733. return this.editor;
  734. }
  735. /*collapse: function () {
  736. var panel = Ext.getCmp('admintools-notes-panel2'),
  737. that = this;
  738. if (panel.collapsed) {
  739. panel.expand(true);
  740. if (AdminTools.currentNote.id) {
  741. setTimeout(function () {
  742. //this.editor = Ext.getCmp('admintool-notes-text');
  743. that.getEditor().setValue(AdminTools.currentNote.text);
  744. }, 300);
  745. }
  746. } else {
  747. AdminTools.currentNote.set(that.getEditor().getValue());
  748. panel.collapse(true);
  749. //panel.setVisible(false);
  750. }
  751. }*/
  752. };
  753. var userMenuList = document.querySelector('#limenu-user ul.modx-subnav');
  754. var newLi = document.createElement('li');
  755. newLi.id = 'admintools-notes';
  756. newLi.innerHTML = '<a href="javascript:AdminTools.showNotes()">' + _('admintools_notes') + ' <span class="description">' + _('admintools_notes_desc') + '</span></a>';
  757. userMenuList.insertBefore(newLi, userMenuList.lastChild);
  758. });