PageRenderTime 46ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/tine20/Admin/js/Tags.js

https://gitlab.com/rsilveira1987/Expresso
JavaScript | 333 lines | 255 code | 41 blank | 37 comment | 16 complexity | c15d91d90b49897eab76609195be1026 MD5 | raw file
  1. /*
  2. * Tine 2.0
  3. *
  4. * @license http://www.gnu.org/licenses/agpl.html AGPL Version 3
  5. * @author Cornelius Weiss <c.weiss@metaways.de>
  6. * @copyright Copyright (c) 2007-2011 Metaways Infosystems GmbH (http://www.metaways.de)
  7. *
  8. * TODO split into two files (grid & edit dlg)
  9. * TODO fix autoheight in edit dlg (use border layout?)
  10. */
  11. /*global Ext, Tine, Locale*/
  12. Ext.ns('Tine.Admin.Tags');
  13. Tine.Admin.Tags.Main = {
  14. // references to created toolbar and grid panel
  15. tagsToolbar: null,
  16. gridPanel: null,
  17. actions: {
  18. addTag: null,
  19. editTag: null,
  20. deleteTag: null
  21. },
  22. handlers: {
  23. /**
  24. * onclick handler for addBtn
  25. */
  26. addTag: function (button, event) {
  27. Tine.Admin.Tags.EditDialog.openWindow({
  28. tag: null,
  29. listeners: {
  30. scope: this,
  31. 'update': function (record) {
  32. this.reload();
  33. }
  34. }
  35. });
  36. },
  37. /**
  38. * onclick handler for editBtn
  39. */
  40. editTag: function (button, event) {
  41. var selectedRows = Ext.getCmp('AdminTagsGrid').getSelectionModel().getSelections();
  42. Tine.Admin.Tags.EditDialog.openWindow({
  43. tag: selectedRows[0],
  44. listeners: {
  45. scope: this,
  46. 'update': function (record) {
  47. this.reload();
  48. }
  49. }
  50. });
  51. },
  52. /**
  53. * onclick handler for deleteBtn
  54. */
  55. deleteTag: function (button, event) {
  56. Ext.MessageBox.confirm(this.translation.gettext('Confirm'), this.translation.gettext('Do you really want to delete the selected tags?'), function (button) {
  57. if (button === 'yes') {
  58. var tagIds = [],
  59. selectedRows = Ext.getCmp('AdminTagsGrid').getSelectionModel().getSelections();
  60. for (var i = 0; i < selectedRows.length; ++i) {
  61. tagIds.push(selectedRows[i].id);
  62. }
  63. tagIds = tagIds;
  64. Ext.Ajax.request({
  65. url: 'index.php',
  66. params: {
  67. method: 'Admin.deleteTags',
  68. tagIds: tagIds
  69. },
  70. text: this.translation.gettext('Deleting tag(s)...'),
  71. success: function (result, request) {
  72. Ext.getCmp('AdminTagsGrid').getStore().reload();
  73. }
  74. });
  75. }
  76. }, this);
  77. }
  78. },
  79. initComponent: function () {
  80. this.translation = new Locale.Gettext();
  81. this.translation.textdomain('Admin');
  82. this.actions.addTag = new Ext.Action({
  83. text: this.translation.gettext('Add Tag'),
  84. handler: this.handlers.addTag,
  85. iconCls: 'action_tag',
  86. scope: this,
  87. disabled: !(Tine.Tinebase.common.hasRight('manage', 'Admin', 'shared_tags'))
  88. });
  89. this.actions.editTag = new Ext.Action({
  90. text: this.translation.gettext('Edit Tag'),
  91. disabled: true,
  92. handler: this.handlers.editTag,
  93. iconCls: 'action_edit',
  94. scope: this
  95. });
  96. this.actions.deleteTag = new Ext.Action({
  97. text: this.translation.gettext('Delete Tag'),
  98. disabled: true,
  99. handler: this.handlers.deleteTag,
  100. iconCls: 'action_delete',
  101. scope: this
  102. });
  103. },
  104. displayTagsToolbar: function () {
  105. // if toolbar was allready created set active toolbar and return
  106. if (this.tagsToolbar) {
  107. Tine.Tinebase.MainScreen.setActiveToolbar(this.tagsToolbar, true);
  108. return;
  109. }
  110. var TagsQuickSearchField = new Ext.ux.SearchField({
  111. id: 'TagsQuickSearchField',
  112. width: 240,
  113. emptyText: Tine.Tinebase.translation._hidden('enter searchfilter')
  114. });
  115. TagsQuickSearchField.on('change', function () {
  116. Ext.getCmp('AdminTagsGrid').getStore().load({
  117. params: {
  118. start: 0,
  119. limit: 50
  120. }
  121. });
  122. }, this);
  123. this.tagsToolbar = new Ext.Toolbar({
  124. id: 'AdminTagsToolbar',
  125. split: false,
  126. //height: 26,
  127. items: [{
  128. xtype: 'buttongroup',
  129. columns: 5,
  130. items: [
  131. Ext.apply(new Ext.Button(this.actions.addTag), {
  132. scale: 'medium',
  133. rowspan: 2,
  134. iconAlign: 'top'
  135. }), {xtype: 'tbspacer', width: 10},
  136. Ext.apply(new Ext.Button(this.actions.editTag), {
  137. scale: 'medium',
  138. rowspan: 2,
  139. iconAlign: 'top'
  140. }), {xtype: 'tbspacer', width: 10},
  141. Ext.apply(new Ext.Button(this.actions.deleteTag), {
  142. scale: 'medium',
  143. rowspan: 2,
  144. iconAlign: 'top'
  145. })
  146. ]
  147. }, '->',
  148. this.translation.gettext('Search:'),
  149. ' ',
  150. TagsQuickSearchField
  151. ]
  152. });
  153. Tine.Tinebase.MainScreen.setActiveToolbar(this.tagsToolbar, true);
  154. },
  155. displayTagsGrid: function () {
  156. // if grid panel was allready created set active content panel and return
  157. if (this.gridPanel) {
  158. Tine.Tinebase.MainScreen.setActiveContentPanel(this.gridPanel, true);
  159. return;
  160. }
  161. // the datastore
  162. var dataStore = new Ext.data.JsonStore({
  163. baseParams: {
  164. method: 'Admin.getTags'
  165. },
  166. root: 'results',
  167. totalProperty: 'totalcount',
  168. id: 'id',
  169. fields: Tine.Tinebase.Model.Tag,
  170. // turn on remote sorting
  171. remoteSort: true
  172. });
  173. dataStore.setDefaultSort('name', 'asc');
  174. dataStore.on('beforeload', function (dataStore, options) {
  175. options = options || {};
  176. options.params = options.params || {};
  177. options.params.query = Ext.getCmp('TagsQuickSearchField').getValue();
  178. }, this);
  179. // the paging toolbar
  180. var pagingToolbar = new Ext.PagingToolbar({
  181. pageSize: 50,
  182. store: dataStore,
  183. displayInfo: true,
  184. displayMsg: this.translation.gettext('Displaying tags {0} - {1} of {2}'),
  185. emptyMsg: this.translation.gettext("No tags to display")
  186. });
  187. // the columnmodel
  188. var columnModel = new Ext.grid.ColumnModel({
  189. defaults: {
  190. sortable: true,
  191. resizable: true
  192. },
  193. columns: [
  194. { id: 'color', header: this.translation.gettext('Color'), dataIndex: 'color', width: 25, renderer: function (color,meta,record) {
  195. return '<div style="margin-top:1px;width: 8px; height: 8px; background-color:' + color + '; border-radius:5px;border: 1px solid black;" title="' + record.get('name') + ' (' + _('Usage:&#160;') + record.get('occurrence') + ')">&#160;</div>';
  196. }},
  197. { id: 'name', header: this.translation.gettext('Name'), dataIndex: 'name', width: 200 },
  198. { id: 'description', header: this.translation.gettext('Description'), dataIndex: 'description', width: 500}
  199. ]
  200. });
  201. // the rowselection model
  202. var rowSelectionModel = new Ext.grid.RowSelectionModel({multiSelect: true});
  203. rowSelectionModel.on('selectionchange', function (selectionModel) {
  204. var rowCount = selectionModel.getCount();
  205. if (Tine.Tinebase.common.hasRight('manage', 'Admin', 'shared_tags')) {
  206. if (rowCount < 1) {
  207. // no row selected
  208. this.actions.deleteTag.setDisabled(true);
  209. this.actions.editTag.setDisabled(true);
  210. } else if (rowCount > 1) {
  211. // more than one row selected
  212. this.actions.deleteTag.setDisabled(false);
  213. this.actions.editTag.setDisabled(true);
  214. } else {
  215. // only one row selected
  216. this.actions.deleteTag.setDisabled(false);
  217. this.actions.editTag.setDisabled(false);
  218. }
  219. }
  220. }, this);
  221. // the gridpanel
  222. this.gridPanel = new Ext.grid.GridPanel({
  223. id: 'AdminTagsGrid',
  224. store: dataStore,
  225. cm: columnModel,
  226. tbar: pagingToolbar,
  227. autoSizeColumns: false,
  228. selModel: rowSelectionModel,
  229. enableColLock: false,
  230. autoExpandColumn: 'description',
  231. border: false,
  232. view: new Ext.grid.GridView({
  233. autoFill: true,
  234. forceFit: true,
  235. ignoreAdd: true,
  236. emptyText: this.translation.gettext('No tags to display')
  237. })
  238. });
  239. this.gridPanel.on('rowcontextmenu', function (grid, rowIndex, eventObject) {
  240. eventObject.stopEvent();
  241. if (! grid.getSelectionModel().isSelected(rowIndex)) {
  242. grid.getSelectionModel().selectRow(rowIndex);
  243. }
  244. if (! this.contextMenu) {
  245. this.contextMenu = new Ext.menu.Menu({
  246. id: 'ctxMenuTags',
  247. items: [
  248. this.actions.editTag,
  249. this.actions.deleteTag,
  250. '-',
  251. this.actions.addTag
  252. ]
  253. });
  254. }
  255. this.contextMenu.showAt(eventObject.getXY());
  256. }, this);
  257. this.gridPanel.on('rowdblclick', function (gridPar, rowIndexPar, ePar) {
  258. var record = gridPar.getStore().getAt(rowIndexPar);
  259. Tine.Admin.Tags.EditDialog.openWindow({
  260. tag: record,
  261. listeners: {
  262. scope: this,
  263. 'update': function (record) {
  264. this.reload();
  265. }
  266. }
  267. });
  268. }, this);
  269. // add the grid to the layout
  270. Tine.Tinebase.MainScreen.setActiveContentPanel(this.gridPanel, true);
  271. },
  272. /**
  273. * update datastore with node values and load datastore
  274. */
  275. loadData: function () {
  276. var dataStore = Ext.getCmp('AdminTagsGrid').getStore();
  277. dataStore.load({ params: { start: 0, limit: 50 } });
  278. },
  279. show: function () {
  280. if (this.tagsToolbar === null || this.gridPanel) {
  281. this.initComponent();
  282. }
  283. this.displayTagsToolbar();
  284. this.displayTagsGrid();
  285. this.loadData();
  286. },
  287. reload: function () {
  288. if (Ext.ComponentMgr.all.containsKey('AdminTagsGrid')) {
  289. setTimeout("Ext.getCmp('AdminTagsGrid').getStore().reload()", 200);
  290. }
  291. }
  292. };