ClassInfoController.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. Ext.define('school.view.basic.class.ClassInfoController', {
  2. extend: 'Ext.app.ViewController',
  3. alias: 'controller.basic-class-classinfo',
  4. onBeforeRender: function() {
  5. let me = this,
  6. view = me.getView(),
  7. viewModel = me.getViewModel();
  8. Ext.StoreMgr.get('store_grade').load();
  9. Ext.StoreMgr.get('store_class').load();
  10. Ext.StoreMgr.get('store_subject').load();
  11. viewModel.get('store_gradeclass').load();
  12. },
  13. onItemMouseEnter: function(tree, record, item, index, e, eOpts) {
  14. let icons = item.getElementsByClassName('action-icon');
  15. let addIcon = icons[0],
  16. editIcon = icons[1],
  17. deleteIcon = icons[2];
  18. if(record.data.type == 'SCHOOL') {
  19. addIcon.classList.remove('x-hidden');
  20. }else if(record.data.type == 'GRADE') {
  21. addIcon.classList.remove('x-hidden');
  22. editIcon.classList.remove('x-hidden');
  23. deleteIcon.classList.remove('x-hidden');
  24. }else if(record.data.type == 'CLASS') {
  25. // addIcon.classList.remove('x-hidden');
  26. editIcon.classList.remove('x-hidden');
  27. deleteIcon.classList.remove('x-hidden');
  28. }
  29. },
  30. onItemMouseLeave: function(tree, record, item, index, e, eOpts) {
  31. let icons = item.getElementsByClassName('action-icon');
  32. for(let x = 0; x < icons.length; x++) {
  33. icons[x].classList.add('x-hidden');
  34. }
  35. },
  36. onItemClick: function(tree, record, item, index, e, eOpts) {
  37. let me = this,
  38. refs = me.getReferences(),
  39. listCard = refs.listcard;
  40. listCard.showNode(record);
  41. },
  42. onItemBeforeDrop: function(node, data, overModel, dropPosition, dropHandlers) {
  43. let cdata = data.records[0].data;
  44. let tdata = overModel.data;
  45. dropHandlers.wait = true;
  46. if(cdata.type == tdata.type && dropPosition != 'append') {
  47. dropHandlers.processDrop();
  48. }else {
  49. dropHandlers.cancelDrop();
  50. }
  51. },
  52. onItemDrop: function() {
  53. },
  54. onToggleTree: function() {
  55. let me = this,
  56. viewModel = me.getViewModel(),
  57. refs = me.getReferences(),
  58. treeList = refs.treelist,
  59. nwidth,
  60. nToggleIconCls;
  61. if(treeList.nowidth) {
  62. treeList.nowidth = false;
  63. nwidth = treeList.owidth;
  64. nToggleIconCls = 'sa-arrows-left'
  65. }else {
  66. treeList.nowidth = true;
  67. treeList.owidth = treeList.getBox().width;
  68. nwidth = 0;
  69. nToggleIconCls = 'sa-arrows-right'
  70. }
  71. viewModel.set('toggleIconCls', nToggleIconCls);
  72. viewModel.set('treeWidth', nwidth);
  73. },
  74. onTreeUp: function() {
  75. let me = this,
  76. viewModel = me.getViewModel(),
  77. refs = me.getReferences(),
  78. treeList = refs.treelist,
  79. listCard = refs.listcard,
  80. currentNodeData = viewModel.get('currentNodeData'),
  81. rootNode = treeList.getRootNode(),
  82. currentNode;
  83. if(currentNodeData.id !== 'root') {
  84. currentNode = rootNode.findChild('id', currentNodeData.id, true);
  85. if(!!currentNode.parentNode) {
  86. treeList.setSelection(currentNode.parentNode);
  87. listCard.showNode(currentNode.parentNode);
  88. }
  89. }
  90. },
  91. onTreeAddClick: function(tree, row, col, item, e, eOpts, tr) {
  92. let me = this,
  93. store = tree.store,
  94. record = store.getAt(row);
  95. me.showTreeAddWin(record);
  96. },
  97. onTreeEditClick: function(tree, row, col, item, e, eOpts, tr) {
  98. let me = this,
  99. store = tree.store,
  100. record = store.getAt(row);
  101. me.showTreeEditWin(record.data, true);
  102. },
  103. onTreeDeleteClick: function(tree, row, col, item, e, eOpts, tr) {
  104. let me = this,
  105. refs = me.getReferences(),
  106. listCard = refs.listcard,
  107. treeList = refs.treelist,
  108. store = treeList.store,
  109. record = store.getAt(row),
  110. rootNode = treeList.getRootNode(),
  111. _id = record.data._id,
  112. id = record.data.id,
  113. type = record.data.type,
  114. name = record.data.text,
  115. currentNode = rootNode.findChild('id', id, true),
  116. parentNode = currentNode.parentNode;
  117. let url, typeText;
  118. if(type == 'GRADE') {
  119. // url = 'http://10.1.80.180:9520/api/school/grade/delete'
  120. url = '/api/school/grade/delete'
  121. typeText = '年级';
  122. }else {
  123. // url = 'http://10.1.80.180:9520/api/school/grade/deleteClass'
  124. url = '/api/school/grade/deleteClass'
  125. typeText = '班级';
  126. }
  127. if(type == 'GRADE') {
  128. if(currentNode.childNodes.length > 0) {
  129. school.util.BaseUtil.showErrorToast('该年级下存在班级信息,无法删除');
  130. return;
  131. }
  132. }
  133. school.util.BaseUtil.showConfirm('确认删除', '确定要删除' + typeText + ' ' + name + ' ?').then(function(yes) {
  134. if(yes == 'yes') {
  135. school.util.BaseUtil.request({
  136. url: url + '/' + _id,
  137. method: 'POST'
  138. }).then(function(res) {
  139. treeList.setSelection(parentNode);
  140. currentNode.remove();
  141. listCard.showNode(parentNode);
  142. }).catch(function(e) {
  143. school.util.BaseUtil.showErrorToast(e.message);
  144. });
  145. }
  146. });
  147. },
  148. showTreeAddWin: function(record, count) {
  149. let me = this,
  150. view = me.getView(),
  151. refs = me.getReferences(),
  152. treeList = refs.treelist,
  153. listCard = refs.listcard,
  154. win = refs.treeaddwin,
  155. data = record.data,
  156. id = data.id,
  157. _id = data._id,
  158. type = data.type,
  159. childCount = count >= 0 ? count : record.childNodes.length;
  160. let title = type == 'SCHOOL' ? '新增年级' : '新增班级';
  161. let sumType = type == 'SCHOOL' ? 'GRADE' : 'CLASS';
  162. if(!win) {
  163. win = Ext.create('Ext.window.Window', {
  164. width: 300,
  165. height: 180,
  166. constrain: true,
  167. references: 'treeaddwin',
  168. modal: true,
  169. bodyPadding: 10,
  170. layout: 'fit',
  171. items: [{
  172. xtype: 'form',
  173. layout: 'column',
  174. defaults: {
  175. columnWidth: 1
  176. },
  177. items: [{
  178. xtype: 'textfield',
  179. name: 'text',
  180. emptyText: '名称',
  181. allowBlank: false,
  182. maxLength: 20
  183. }],
  184. buttonAlign: 'center',
  185. buttons: [{
  186. text: '确定',
  187. formBind: true,
  188. handler: function() {
  189. let form = this.up('form');
  190. let text = form.getValues().text;
  191. let rootNode = treeList.getRootNode();
  192. let currentNode;
  193. let childNode = {
  194. text: text,
  195. type: sumType
  196. };
  197. let url, params, headers;
  198. if(type == 'SCHOOL') {
  199. currentNode = rootNode;
  200. childNode.leaf = true;
  201. childNode.children = [];
  202. // url = 'http://10.1.80.180:9520/api/school/grade/save';
  203. url = '/api/school/grade/save';
  204. params = {
  205. grade: text,
  206. no: childCount
  207. };
  208. headers = {
  209. "Content-Type": 'application/x-www-form-urlencoded; charset=UTF-8'
  210. }
  211. }else {
  212. currentNode = rootNode.findChild('id', id, true);
  213. childNode.leaf = true;
  214. // url = 'http://10.1.80.180:9520/api/school/grade/addClass';
  215. url = '/api/school/grade/addClass';
  216. params = JSON.stringify({
  217. grade_id: _id,
  218. clazz_name: text,
  219. no: childCount
  220. });
  221. }
  222. view.setLoading(true);
  223. school.util.BaseUtil.request({
  224. url: url,
  225. method: 'POST',
  226. params: params,
  227. headers: headers
  228. }).then(function(res) {
  229. view.setLoading(false);
  230. childNode._id = res.data.id;
  231. currentNode.appendChild(childNode);
  232. listCard.showNode(currentNode);
  233. win.close();
  234. }).catch(function(e) {
  235. view.setLoading(false);
  236. school.util.BaseUtil.showErrorToast(e.message);
  237. });
  238. }
  239. }]
  240. }]
  241. });
  242. view.add(win);
  243. }
  244. win.setTitle(title);
  245. win.show();
  246. },
  247. showTreeEditWin: function(data) {
  248. let me = this,
  249. view = me.getView(),
  250. refs = me.getReferences(),
  251. treeList = refs.treelist,
  252. listCard = refs.listcard,
  253. win = refs.treeaddwin,
  254. _id = data._id,
  255. id = data.id,
  256. type = data.type;
  257. let title = type == 'GRADE' ? '修改年级' : '修改班级';
  258. if(!win) {
  259. win = Ext.create('Ext.window.Window', {
  260. width: 300,
  261. height: 180,
  262. references: 'treeaddwin',
  263. constrain: true,
  264. modal: true,
  265. bodyPadding: 10,
  266. layout: 'fit',
  267. items: [{
  268. xtype: 'form',
  269. layout: 'column',
  270. defaults: {
  271. columnWidth: 1
  272. },
  273. items: [{
  274. xtype: 'textfield',
  275. name: 'text',
  276. emptyText: '名称',
  277. value: data.text,
  278. allowBlank: false,
  279. maxLength: 20
  280. }],
  281. buttonAlign: 'center',
  282. buttons: [{
  283. text: '确定',
  284. formBind: true,
  285. handler: function() {
  286. let form = this.up('form');
  287. let text = form.getValues().text;
  288. let rootNode = treeList.getRootNode();
  289. let currentNode = rootNode.findChild('id', id, true);
  290. let url, params, headers;
  291. if(type == 'GRADE') {
  292. // url = 'http://10.1.80.180:9520/api/school/grade/update';
  293. url = '/api/school/grade/update';
  294. params = JSON.stringify({
  295. grade_id: _id,
  296. grade_name: text
  297. });
  298. }else {
  299. // url = 'http://10.1.80.180:9520/api/school/grade/updateClass';
  300. url = '/api/school/grade/updateClass';
  301. params = JSON.stringify({
  302. clazz_id: _id,
  303. clazz_name: text
  304. });
  305. }
  306. view.setLoading(true);
  307. school.util.BaseUtil.request({
  308. url: url,
  309. method: 'POST',
  310. params: params,
  311. headers: headers
  312. }).then(function(res) {
  313. view.setLoading(false);
  314. currentNode.set('text', text);
  315. currentNode.set('pathText', text);
  316. currentNode.commit();
  317. win.close();
  318. listCard.showNode(currentNode);
  319. }).then(function() {
  320. Ext.StoreMgr.get('store_grade').load();
  321. Ext.StoreMgr.get('store_class').load();
  322. }).catch(function(e) {
  323. view.setLoading(false);
  324. school.util.BaseUtil.showErrorToast(e.message);
  325. });
  326. }
  327. }]
  328. }]
  329. });
  330. view.add(win);
  331. }
  332. win.setTitle(title);
  333. win.show();
  334. },
  335. });