Extdefine (& 039; JCYappcontrollerUserController & 039;, {extend: & 039; ExtappController & 039;, alias: & 039; widgetuserController & 039;, init: function () {thiscontrol ({& 039; gri
Ext. define ('jcy. app. controller. userController ', {extend: 'ext. app. controller ', alias: 'widget. userController ', init: function () {this. control ({'gridview ': {beforerender: this. beforerender }}) ;}, beforerender: function (comment, obj) {var store = comment. getStore (); // get the storevar selModel = comment of the grid. getSelectionModel (); // get the selected model/*** add */comment. down ('button [id = add] '). on ('click', function () {var addUser = Ext. cr Eate ('jcy. app. view. addUserForm '). show (); var form = addUser. down ('form'); // obtain the form var model = store. model; // obtain modelform. down ('button '). on ('click', function () {form. submit ({url: '/Extjs4/gridAction! SaveUser. action ', method: 'post', success: function (form, action) {var num = form. findField ('num '). getValue (); // obtain the value var name = form in the form. findField ('name '). getValue (); var email = form. findField ('email '). getValue (); // var data = action. response. responseText; // var json = eval ("(" + data + ")"); addUser. close (); var m = new model ({num: num, name: name, email: email}); store. add (m); // add to the end by default});/*** modify * to obtain the model first, and then create the mode with data. L **/comment. down ('button [id = edit] '). on ('click', function () {var record = selModel. getSelection (); // obtain the selected data if (record. length = 1) {var editUser = Ext. create ('jcy. app. view. addUserForm '); editUser. setTitle ('modify user information'); editUser. setIconCls ('table _ edit'); editUser. down ('form '). loadRecord (record [0]); // load information var text = editUser. down ('form '). down ('textfield'); text. readOnly = true; editUser. show (); var form = editUser. down (' M'); editUser. down ('click'). on ('click', function () {form. submit ({url: '/Extjs4/gridAction! EditUser. action ', method: 'post', success: function (form, action) {var num = form. findField ('num '). getValue (); // obtain the value var name = form in the form. findField ('name '). getValue (); var email = form. findField ('email '). getValue (); editUser. close (); var model = store. model; // obtain modelvar m = new model ({num: num, name: name, email: email}); store. add (m); // add to the end by default // store. insert (0, m); // The first is the insert position});} else {Ext. msg. alert ("prompt", "select a piece of data! "). SetIcon ("ext-mb-info") ;}});/*** Delete */comment. down ('button [id = del] '). on ('click', function () {if (selModel. hasSelection () {var selected = selModel. getSelection (); var ids = []; Ext. each (selected, function (item) {ids. push (item. data ['num']); // alert (item. get ('num') ;}); Ext. msg. confirm ('hint ', 'Are you sure you want to delete', function (B) {if (B = 'yes') {Ext. ajax. request ({url: '/Extjs4/gridAction! DelUser. action ', params: {ids: ids}, method: 'post', success: function (response) {Ext. array. each (selected, function (record) {store. remove (record); // Delete the data in the grid}) ;}}}) ;}} else {Ext. msg. alert ("prompt", "You have not selected the data to be modified! "). SetIcon ("ext-mb-info "). setWidth (200) ;}}) ;}, models: ['jcy. app. model. gridModel '], stores: ['jcy. app. store. gridstore'], views: ['jcy. app. view. gridView ', 'jcy. app. view. gridview2', 'jcy. app. view. addUserForm ']});