Skip to content
Browse files

学生评价 Done

  • Loading branch information...
1 parent 4801e6e commit f08d5049a339e0820d77077f3ceec837754fc648 @xEasy xEasy committed Mar 23, 2012
View
4 app/controllers/homes_controller.rb
@@ -3,7 +3,7 @@ def index
end
def get_classes_students
- render_json Classes.find(params[:c_id]).students.order("#{params[:sort]} #{params[:dir]}").collect &fields_provider
+ render_json Classes.find(params[:c_id]).students.number_like(params[:query]).order("#{params[:sort]} #{params[:dir]}").collect &fields_provider
end
def get_classes
@@ -26,7 +26,7 @@ def comment_type_tree_nodes
end
def commets_by_type
- render_json CommentType.find(params[:ct_id]).comments.collect &fields_provider
+ render_json CommentType.find(params[:ct_id]).comments.content_like(params[:query]).collect &fields_provider
end
end
View
10 app/controllers/students_controller.rb
@@ -9,4 +9,14 @@ def get_all_students
#end
render_json students
end
+
+
+ def update_student_comment
+ s = Student.find(params[:id])
+ if s.update_attribute(:comment, params[:comment])
+ render_json "success"
+ else
+ render_error s.errors
+ end
+ end
end
View
4 app/models/student.rb
@@ -4,6 +4,10 @@ class Student < Person
belongs_to :classes
has_many :course_scores
+ def total_score
+ course_scores.sum(:score)
+ end
+
def grade
'优秀'
end
View
2 app/views/layouts/application.html.erb
@@ -6,6 +6,8 @@
<%= javascript_include_tag 'Extjs/ext-all-debug.js' %>
<%= javascript_include_tag 'Extjs/ext-lang-zh_CN.js' %>
+ <%= javascript_include_tag 'Extjs/ux/SearchField.js' %>
+
<%= javascript_include_tag 'PF/public/init.js' %>
<%= javascript_include_tag 'PF/util/util.js' %>
<%= javascript_include_tag 'Jquery/jquery.js' %>
View
3 config/routes.rb
@@ -20,6 +20,9 @@
collection do
get "get_all_students"
end
+ member do
+ post "update_student_comment"
+ end
end
View
53 public/javascripts/Extjs/ux/SearchField.js
@@ -0,0 +1,53 @@
+/*!
+ * Ext JS Library 3.2.1
+ * Copyright(c) 2006-2010 Ext JS, Inc.
+ * licensing@extjs.com
+ * http://www.extjs.com/license
+ */
+Ext.ns('Ext.ux.form');
+
+Ext.ux.form.SearchField = Ext.extend(Ext.form.TwinTriggerField, {
+ initComponent : function(){
+ Ext.ux.form.SearchField.superclass.initComponent.call(this);
+ this.on('specialkey', function(f, e){
+ if(e.getKey() == e.ENTER){
+ this.onTrigger2Click();
+ }
+ }, this);
+ },
+
+ validationEvent:false,
+ validateOnBlur:false,
+ trigger1Class:'x-form-clear-trigger',
+ trigger2Class:'x-form-search-trigger',
+ hideTrigger1:true,
+ width:180,
+ hasSearch : false,
+ paramName : 'query',
+
+ onTrigger1Click : function(){
+ if(this.hasSearch){
+ this.el.dom.value = '';
+ var o = {start: 0};
+ this.store.baseParams = this.store.baseParams || {};
+ this.store.baseParams[this.paramName] = '';
+ this.store.reload({params:o});
+ this.triggers[0].hide();
+ this.hasSearch = false;
+ }
+ },
+
+ onTrigger2Click : function(){
+ var v = this.getRawValue();
+ if(v.length < 1){
+ this.onTrigger1Click();
+ return;
+ }
+ var o = {start: 0};
+ this.store.baseParams = this.store.baseParams || {};
+ this.store.baseParams[this.paramName] = v;
+ this.store.reload({params:o});
+ this.hasSearch = true;
+ this.triggers[0].show();
+ }
+});
View
206 public/javascripts/PF/pages/comment_student.js
@@ -11,6 +11,8 @@ Pf.classes.commentStudent.MainPanel = Ext.extend(Ext.Panel, {
layout : 'border',
initComponent : function () {
+ currentClasses = undefined;
+ currentStu = undefined;
this.addDefaultComponents();
Pf.classes.commentStudent.MainPanel.superclass.initComponent.call(this);
},
@@ -25,17 +27,19 @@ Pf.classes.commentStudent.MainPanel = Ext.extend(Ext.Panel, {
items : [
this.tree,
this.commentGrid,
- new Ext.FormPanel({
+ new Ext.FormPanel({
region: 'south',
frame : true,
height : 180,
labelAlign : 'top',
items: [ { xtype : 'textarea',fieldLabel: "评语", id : 's-comment', width : "100%", height : 145 } ],
- }),
+ })
]},
this.studentForm
]
-
+
+ this.studentGrid = this.createStudentGrid();
+ this.studentWin = this.createStudentWin();
},
createTree : function () {
@@ -56,7 +60,8 @@ Pf.classes.commentStudent.MainPanel = Ext.extend(Ext.Panel, {
if(node.isLeaf){
var store = Ext.getCmp('comment-grid').getStore();
store.removeAll();
- store.load({ params : { ct_id : node.attributes.id } });
+ store.setBaseParam('ct_id', node.attributes.id);
+ store.load();
}
}
}
@@ -77,17 +82,19 @@ Pf.classes.commentStudent.MainPanel = Ext.extend(Ext.Panel, {
],
defaults: { menuDisabled : true, sortable : true }
});
+
var grid = new Ext.grid.EditorGridPanel({
id : 'comment-grid',
region : 'center',
store: store,
+ cm : cm,
border: false,
title : '评价详细',
stripeRows: true,
loadMask : true,
viewConfig: { forceFit: true },
bbar : new Pf.util.Bbar({ store : store }),
- cm : cm,
+ tbar: [' ','查询: ', ' ', new Ext.ux.form.SearchField({ store: store, width: 320 })],
sm : new Ext.grid.RowSelectionModel({ }),
listeners: {
celldblclick : function(grid,rowIndex,columnIndex) {
@@ -99,24 +106,35 @@ Pf.classes.commentStudent.MainPanel = Ext.extend(Ext.Panel, {
return grid;
},
+ createStudentWin : function () {
+ var studentWin = new Ext.Window({
+ title : '请选择学生',
+ closeAction: 'hide',
+ width: 700,
+ height: 400,
+ modal: true,
+ constrainHeader: true,
+ layout: 'fit',
+ items: this.studentGrid,
+ buttons: [
+ { text: '关闭', handler:function(){ studentWin.hide(); } },
+ ]
+ });
+ return studentWin;
+ },
+
createForm : function () {
var scope = this;
- var classCombox = new Ext.form.ComboBox({
- fieldLabel : '班级',
- triggerAction : 'all',
- displayField : 'name',
- mode : 'remote',
- autoSelect : true,
- width : 130,
- forceSelection : true,
- store : new Pf.util.FieldsJsonStore({
- url : '/homes/get_classes.json',
- fields : ["id", "name"],
- autoLoad: false
- }),
- listeners : {
- select : function(combo, record, index) {
- }
+
+ var studentField = new Ext.ux.form.SearchField({
+ id : 'fbillerid',
+ name : 'name',
+ fieldLabel : '学生',
+ emptyText : '请选择学生',
+ editable : false,
+ onTrigger2Click : function() {
+ if (currentClasses != undefined) { scope.studentGrid.getStore().reload(); };
+ scope.studentWin.show();
}
});
@@ -126,12 +144,11 @@ Pf.classes.commentStudent.MainPanel = Ext.extend(Ext.Panel, {
frame : true,
autoScroll : true,
width : 280,
- lableWidth: 55,
- labelAlign : 'top',
+ labelWidth: 40,
+ labelAlign: 'left',
bodyStyle: 'padding:5px 15px 0',
- defaults : { anchor : '95%' },
+ defaults : { anchor : '95%', width : 200 },
defaultType : 'textfield',
- layout: 'form',
items: [
new Ext.form.FieldSet({
title : '头像',
@@ -141,25 +158,31 @@ Pf.classes.commentStudent.MainPanel = Ext.extend(Ext.Panel, {
html : '<span id="image"><img src="/images/Temp.png" height=110px width=120px alt="图片" /></span>'
}]
}),
- classCombox
+ studentField
,{
fieldLabel: '学号',
name: 'number',
- },{
- fieldLabel: '姓名',
- name: 'name',
- },{
- fieldLabel: '性别',
- name: 'sex',
+ readOnly: true
},{
fieldLabel: '班级',
name: 'classes/name',
+ readOnly: true
}, {
+ fieldLabel: '性别',
+ name: 'sex',
+ readOnly: true
+ },{
fieldLabel: '总分',
name: 'total_score',
+ readOnly: true
}, {
fieldLabel: '评级',
name: 'grade',
+ readOnly: true
+ }, {
+ fieldLabel: '备注',
+ name: 'remark',
+ readOnly: true
}
],
buttonAlign: 'center',
@@ -172,6 +195,101 @@ Pf.classes.commentStudent.MainPanel = Ext.extend(Ext.Panel, {
return form;
},
+
+ createStudentGrid : function() {
+ var scope = this;
+ var store = new Pf.util.FieldsJsonStore({
+ root : 'root',
+ url : '/homes/get_classes_students.json',
+ fields : [
+ "id",
+ 'name',
+ 'number',
+ 'phone',
+ 'home',
+ 'remark' ,
+ 'sex',
+ 'classes/name',
+ 'comment',
+ 'image/url',
+ 'grade',
+ 'total_score'
+ ]
+ });
+
+ var cm = new Ext.grid.ColumnModel({
+ columns: [
+ { header: '学号' , dataIndex: 'number' },
+ { header: '姓名' , dataIndex: 'name' },
+ { header: '电话' , dataIndex: 'phone' },
+ { header: '住址' , dataIndex: 'home' },
+ { header: '性别' , dataIndex: 'sex' },
+ { header: '总分' , dataIndex: 'total_score' },
+ { header: '备注' , dataIndex: 'remark' },
+ ],
+ defaults: { menuDisabled : true, sortable : true }
+ });
+
+ var classCombox = new Ext.form.ComboBox({
+ triggerAction : 'all',
+ displayField : 'name',
+ mode : 'remote',
+ autoSelect : true,
+ width : 130,
+ forceSelection : true,
+ store : new Pf.util.FieldsJsonStore({
+ url : '/homes/get_classes.json',
+ fields : ["id", "name"],
+ autoLoad: false
+ }),
+ listeners : {
+ select : function(combo, record, index) {
+ var store = Ext.getCmp("student-grid").getStore();
+ store.removeAll();
+ store.setBaseParam("c_id",record.get("id"));
+ currentClasses = record;
+ store.load();
+ }
+ }
+ });
+
+ var grid = new Ext.grid.EditorGridPanel({
+ id : 'student-grid',
+ store: store,
+ cm : cm,
+ border: false,
+ containerScroll: true,
+ loadMask : true,
+ width: 200,
+ region: 'west',
+ split: true,
+ title : "学生列表",
+ stripeRows: true,
+ viewConfig: { forceFit: true },
+ tbar: new Ext.Toolbar({
+ items : [
+ '班级:',classCombox,'->',
+ '学号查询: ', ' ', new Ext.ux.form.SearchField({ store: store, width: 220 })
+ ]
+ }),
+ sm : new Ext.grid.RowSelectionModel({ }),
+ listeners: {
+ celldblclick : function(grid,rowIndex,columnIndex) {
+ var record = grid.getStore().getAt(rowIndex);
+ var form = scope.studentForm.getForm()
+ form.reset();
+ form.loadRecord(record);
+ //加载头像
+ //$("#image img").attr("src", record.get('image/url'));
+ currentStu = record;
+ scope.addComment(currentStu.get('comment'), true);
+ scope.studentWin.hide();
+ }
+ }
+ });
+ return grid;
+ },
+
addComment : function (content, clear) {
var commentArea = Ext.getCmp('s-comment');
if (clear) {
@@ -181,8 +299,28 @@ Pf.classes.commentStudent.MainPanel = Ext.extend(Ext.Panel, {
};
},
- saveComment : function () {
-
+ saveComment : function() {
+ if (currentStu == undefined) {return;};
+ Ext.Msg.confirm("系统提示","确认保存学生'"+currentStu.get("name")+"'的评价信息?",function (button,text) {
+ if (button == "yes") {
+ saveHandler.call(this);
+ };
+ },this);
+
+ function saveHandler () {
+ Ext.Ajax.request({
+ url: '/students/' + currentStu.get("id") + '/update_student_comment.json',
+ method : "POST",
+ jsonData: { comment : Ext.getCmp('s-comment').getValue() },
+ success: function (response,onpts) {
+ Ext.Msg.alert("提示","保存成功。");
+ },
+ failure: function (response, onpts) {
+ var msg = Ext.decode(response.responseText).root.error_msg;
+ Ext.Msg.alert("", msg);
+ }
+ });
+ }
}
});
View
12 public/javascripts/PF/pages/home_index.js
@@ -61,8 +61,9 @@ Pf.classes.homeIndex.MainPanel = Ext.extend(Ext.Panel, {
displayField : 'name',
mode : 'remote',
autoSelect : true,
- width : 130,
+ width : 180,
forceSelection : true,
+ emptyText : '请选择班级',
store : new Pf.util.FieldsJsonStore({
url : '/homes/get_classes.json',
fields : ["id", "name"],
@@ -72,7 +73,8 @@ Pf.classes.homeIndex.MainPanel = Ext.extend(Ext.Panel, {
select : function(combo, record, index) {
var store = Ext.getCmp("student-grid").getStore();
store.removeAll();
- store.load({ params : { c_id : record.get("id") } });
+ store.setBaseParam("c_id", record.get("id"));
+ store.load();
}
}
});
@@ -91,7 +93,9 @@ Pf.classes.homeIndex.MainPanel = Ext.extend(Ext.Panel, {
stripeRows: true,
viewConfig: { forceFit: true },
tbar: new Ext.Toolbar({
- items : ['班级:',classCombox ]
+ layout : 'form',
+ labelWidth : 1,
+ items : ['班级:',classCombox, '学号查询:',new Ext.ux.form.SearchField({ emptyText : '请输入学号' ,store: store, width: 180 }) ]
}),
sm : new Ext.grid.RowSelectionModel({
listeners : {
@@ -145,7 +149,7 @@ Pf.classes.homeIndex.MainPanel = Ext.extend(Ext.Panel, {
region : 'center',
frame : true,
autoScroll : true,
- lableWidth: 55,
+ labelWidth: 60,
labelAlign : 'right',
bodyStyle: 'padding:5px 5px 0',
items: [{
View
2 public/javascripts/PF/util/util.js
@@ -24,7 +24,7 @@ Pf.util.FieldsJsonStore = Ext.extend(Ext.data.JsonStore, {
Pf.util.Bbar = Ext.extend(Ext.PagingToolbar,{
config : {
- pageSize : 25,
+ pageSize : 20,
emptyMsg : '没有记录',
displayInfo : true,
displayMsg : "显示 {0} - {1} 总 {2} 条记录 ",

0 comments on commit f08d504

Please sign in to comment.
Something went wrong with that request. Please try again.