ClassInfoController.js 14 KB

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