Permalink
Browse files

添加两个新的扩展方法,详细查看util,完成学生信息添加部分功能

  • Loading branch information...
1 parent 3bed891 commit a4c28e264d785ab8a5326f0110c4b2853d4a219e @mouse-lin committed Mar 22, 2012
View
11 app/controllers/students_controller.rb
@@ -2,11 +2,6 @@ class StudentsController < ApplicationController
#获取学生信息
def get_all_students
students = Student.all.collect &fields_provider
- #Student.all.each do |s|
- # students.push(s.attributes.merge!({
- # :class_name => s.classes.try(:name)
- # }))
- #end
render_json students
end
@@ -22,4 +17,10 @@ def update_student_comment
def student_total_score
render_json Student.find(params[:s_id]).total_score_by_grade
end
+
+ def destroy_student
+ Student.find(params[:id]).delete
+ render_json "success"
+ end
+
end
View
1 config/routes.rb
@@ -20,6 +20,7 @@
collection do
get "get_all_students"
get "student_total_score"
+ post "destroy_student"
end
member do
post "update_student_comment"
View
72 public/javascripts/PF/pages/settings_index.js
@@ -1,30 +1,85 @@
Pf.settings.homeIndex = {
panel: function(){
var grid = new Pf.classes.student();
- var studentDetailFormPanel = this.createStuentDetail();
+ var studentScoreGrid = this.createStudentScoreGrid();
+ var studentDetailFormPanel = this.createStudentDetail();
grid.store.load();
+ grid.on('cellclick', function(grid, rowIndex){
+ studentDetailFormPanel.getForm().setValues(grid.store.getAt(rowIndex).data);
+ $("#image img").attr("src", '/images/Temp.png');
+ });
+
var panel = new Ext.TabPanel({
autoScroll : true,
activeTab: 0,
frame: true,
items: [
{ title: "学生主档",
layout: "border",
- items: [{region: "center",width: 900, items: grid },{ region:"east",width: 500, layout: "anchor", items:studentDetailFormPanel }]
+ items: [
+ {region: "center",layout: "border", width: 900, items: grid },
+ {region:"east",width: 500, layout: "border", items:[ studentDetailFormPanel, studentScoreGrid]}]
},
{ title: "学生主档", html: "mouse" },
]
});
return panel;
},
- createStuentDetail: function(){
+ createStudentScoreGrid: function(){
+ var studentScoreStore = new Pf.util.FieldsJsonStore({
+ fields: [
+ ],
+ root : 'root',
+ url : '/homes/get_classes_students.json',
+ });
+ var cm = new Ext.grid.ColumnModel([
+ { header: '初一第一学期', sortable: true, dataIndex: ''},
+ { header: '初一第二学期', sortable: true, dataIndex: ''},
+ { header: '初二第一学期', sortable: true, dataIndex: ''},
+ { header: '初二第二学期', sortable: true, dataIndex: ''},
+ { header: '初三第一学期', sortable: true, dataIndex: ''},
+ { header: '初三第二学期', sortable: true, dataIndex: ''},
+ ]);
+ var grid_name = new Ext.grid.EditorGridPanel({
+ viewConfig: { forceFit: true },
+ store: studentScoreStore,
+ loadMask: true,
+ cm: cm,
+ height: 300,
+ region: "south",
+ bbar : new Pf.util.Bbar({ store : studentScoreStore }),
+ });
+ return grid_name;
+ },
+
+ createStudentDetail: function(){
+ var sexData = [['',''],['','']];
+ var sexCombo = new Ext.form.ComboBox({
+ //id: 'targetCombo',
+ valueField: 'sex',
+ fieldLabel: "性别",
+ triggerAction: 'all',
+ name: 'sex',
+ displayField: 'sexName',
+ width: 180,
+ mode: 'local',
+ editable : false,
+ store: new Ext.data.SimpleStore({
+ fields: ['sex', 'sexName'],
+ data: sexData,
+ //autoLoad: true,
+ })
+ });
+
var formPanel = new Ext.form.FormPanel({
title: "test",
- anchor: "100% 100%",
+ region: "center",
autoScroll : true,
frame: true,
labelAlign : 'right',
+ buttonAlign: 'center',
+ buttons: [{ text: "更新", handler: function(){ alert("nihai") } }],
items: [{
layout: 'column',
items:[
@@ -56,12 +111,11 @@ Pf.settings.homeIndex = {
},
{
fieldLabel: "班级",
- name: "classes"
- },
- {
- fieldLabel: "性别",
- name: "sex"
+ name: "classes/name"
},
+ sexCombo,
+ // fieldLabel: "性别",
+ // name: "sex"
{
fieldLabel: "联系电话",
name: "phone"
View
63 public/javascripts/PF/pages/student.js
@@ -2,14 +2,17 @@ Ext.ns("Pf.classes.student");
Pf.classes.student = Ext.extend(Ext.grid.EditorGridPanel,{
viewConfig: { forceFit: true },
- height: 600,
+ region: "center",
+ loadMask: true,
+ id: "studentShowGrid",
sm: new Ext.grid.RowSelectionModel({
singleSelect: true
}),
initComponent : function () {
this.store = this.initStore();
this.cm = this.initCm();
this.tbar = this.initStudentTbar();
+ this.bbar = new Pf.util.Bbar({ store: this.store });
Pf.classes.student.superclass.initComponent.call(this);
},
initStudentEditor: function(){
@@ -21,6 +24,7 @@ Pf.classes.student = Ext.extend(Ext.grid.EditorGridPanel,{
initStore: function(){
var store = new Pf.util.FieldsJsonStore({
fields: [
+ "id",
"name",
"number",
"sex",
@@ -33,6 +37,7 @@ Pf.classes.student = Ext.extend(Ext.grid.EditorGridPanel,{
});
return store;
},
+
initCm: function(){
var cm = new Ext.grid.ColumnModel([
new Ext.grid.RowNumberer(),
@@ -45,18 +50,64 @@ Pf.classes.student = Ext.extend(Ext.grid.EditorGridPanel,{
]);
return cm;
},
+
initStudentTbar: function(){
var _this = this;
var tbar = [
{
iconCls: "add",
text: "添加",
- handler: function(){ alert("niha")}
+ handler: function(){ _this.addSingleStudent().show() }
},
- { iconCls: "delete", text: "删除" },
- { iconCls: "table_edit", text: "编辑" },
- { iconCls: "table_edit", text: "详细" },
+ {
+ iconCls: "delete",
+ text: "删除",
+ handler: function(){
+ var grid = Ext.getCmp("studentShowGrid");
+ var record = grid.getSelectionModel().getSelected();
+ if(!record){ Ext.Msg.alert("提示","请选择学生") }
+ else{
+ Ext.Msg.confirm('提示', "是否确定保存?", function(button){
+ if(button != "no"){
+ Pf.util.loadMask.show();
+ var studentId = record.id;
+ Ext.Ajax.request({
+ url: "/students/destroy_student.json",
+ method: "POST",
+ jsonData: { id: record.id } ,
+ success: function(response, opts){
+ Pf.util.callback.success();
+ Ext.Msg.alert("提示","删除成功");
+ grid.store.reload();
+ },
+ failure: function(response, opts){
+ Pf.util.callback.failure();
+ }
+ })
+ }
+ })
+ }
+ }
+ },
];
return tbar;
- }
+ },
+
+ addSingleStudent: function(){
+ var win = new Ext.Window({
+ title: "添加学生",
+ width: 650,
+ height: 400,
+ id: "addSingleStudentWin",
+ modal: true,
+ constrain: true,
+ layout: 'anchor',
+ buttonAlign: 'center',
+ buttons: [
+ { text: "保存" },
+ { text: "取消", handler: function(){ Ext.getCmp("addSingleStudentWin").close() } }
+ ]
+ });
+ return win;
+ },
})
View
36 public/javascripts/PF/util/util.js
@@ -36,3 +36,39 @@ Pf.util.Bbar = Ext.extend(Ext.PagingToolbar,{
}
});
+Pf.util.loadMask = {
+ show: function(msg) {
+ if(!Ext.isString(msg)) msg = "处理中...";
+ (new Ext.LoadMask(Ext.getBody(), { msg: msg })).show();
+ // From Van on 2011-10-06 => 用于修改 loadMask 显示 bug
+ Ext.get(Ext.DomQuery.jsSelect(".ext-el-mask:last")).applyStyles("z-index: 10000;");
+ },
+
+ hide: function() {
+ (new Ext.LoadMask(Ext.getBody())).hide();
+ }
+};
+
+Pf.util.callback = {
+ success: function() {
+ Pf.util.loadMask.hide();
+ Ext.Msg.alert( '提示', '操作成功');
+ },
+
+ failure: function(response, opts) {
+ Pf.util.loadMask.hide();
+ if(response.status == -1)
+ var error_message = '操作超时,网络异常,检查后请重试...';
+ else
+ var error_message = Ext.decode(response.responseText).root.error_msg;
+ Ext.Msg.alert(
+ '提示',
+ error_message
+ );
+ },
+
+ formFailure: function(form, action) {
+ Pf.util.loadMask.hide();
+ Ext.Msg.alert('提示', Ext.decode(action.response.responseText).root.error_msg);
+ }
+};

0 comments on commit a4c28e2

Please sign in to comment.