Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

添加成绩班级更新添加功能

  • Loading branch information...
commit 0dd0696e9d9c1fc35f735bf9221a32fdeb43f8ef 1 parent 04736f6
@mouse-lin authored
View
39 app/controllers/settings_controller.rb
@@ -1,5 +1,44 @@
class SettingsController < ApplicationController
+
def index
end
+ #班别科目主档
+ def classes
+ respond_to do |wants|
+ wants.html
+ wants.json do
+ classes = Classes.all.collect &fields_provider
+ render_json classes
+ end
+ end
+ end
+
+ def get_course
+ course = Course.all.collect &fields_provider
+ render_json course
+ end
+
+ #删除班级
+ def destroy_classes
+ Classes.find(params[:id]).delete
+ render_json "success"
+ end
+
+ #删除科目
+ def destroy_course
+ Course.find(params[:id]).delete
+ render_json "success"
+ end
+
+ #保存更新班级科目信息
+ def ajax_request
+ if params[:action_type] == "create"
+ params[:object_type].constantize.create(params[:form_data])
+ else
+ params[:object_type].constantize.find(params[:id]).update_attributes(params[:form_data])
+ end
+ render_json "success"
+ end
+
end
View
1  app/controllers/students_controller.rb
@@ -59,4 +59,5 @@ def update_score
def print
@student = Student.find(params[:id])
end
+
end
View
2  app/views/layouts/application.html.erb
@@ -56,7 +56,7 @@
<a class="dock-item2" href="#"><span>Video</span><img src="../images/video.png" alt="video" /></a>
<a class="dock-item2" href="#"><span>History</span><img src="../images/history.png" alt="history" /></a>
<a class="dock-item2" href="#"><span>Calendar</span><img src="/images/calendar.png" alt="calendar" /></a>
- <a class="dock-item2" href="#"><span>Links</span><img src="/images/link.png" alt="links" /></a>
+ <a class="dock-item2" href="/settings/classes"><span>班别科目主档</span><img src="/images/link.png" alt="links" /></a>
<a class="dock-item2" href="/settings"><span>主档设置</span><img src="/images/rss.png" alt="rss" /></a>
<a class="dock-item2" href="logout"><span>退出</span><img src="/images/rss2.png" alt="rss" /></a>
</div>
View
6 app/views/settings/classes.html.erb
@@ -0,0 +1,6 @@
+<%= javascript_include_tag '/javascripts/PF/pages/classes.js' %>
+<script language="javascript" type="text/javascript">
+ Ext.onReady(function() {
+ Pf.pages.currentInstance = Pf.settings.classes.panel();
+ });
+</script>
View
7 config/routes.rb
@@ -15,11 +15,18 @@
get 'commets_by_type'
end
end
+
resources :settings do
collection do
get "index"
+ get "classes"
+ get "get_course"
+ post "destroy_classes"
+ post "destroy_course"
+ post "ajax_request"
end
end
+
resources :students do
collection do
get "get_all_students"
View
334 public/javascripts/PF/pages/classes.js
@@ -0,0 +1,334 @@
+Pf.settings.classes = {
+ panel: function(){
+ var _this = this;
+ var classesGrid = this.createClassesGrid();
+ var classesFormPanel = this.createClassesFormPanel();
+ var courseGrid = this.createCourseGrid();
+ var courseFormPanel = this.createCourseFormPanel();
+
+ classesGrid.on('cellclick', function(grid, rowIndex){
+ var record = classesGrid.store.getAt(rowIndex);
+ classesFormPanel.getForm().loadRecord(record);
+ });
+
+ courseGrid.on('cellclick', function(grid, rowIndex){
+ var record = courseGrid.store.getAt(rowIndex);
+ courseFormPanel.getForm().loadRecord(record);
+ });
+
+ classesGrid.store.load();
+ courseGrid.store.load();
+
+ var panel = new Ext.Panel({
+ title: "班别科目主档",
+ autoScroll: true,
+ layout: "border",
+ items: [
+ {
+ region: "center",
+ layout: "border",
+ items:[{
+ region: "center",
+ layout: "border",
+ items: [classesGrid]
+ },{
+ region: "east",
+ layout: "border",
+ tbar:[{ text:"添加", iconCls: "add", handler: function(){
+ Ext.Msg.confirm('提示', "是否确定保存?", function(button){
+ if(button != "no"){
+ if(Ext.getCmp("classesName").getValue() != "")
+ {
+ _this.ajaxRequest("Classes","create");
+ }
+ else
+ Ext.Msg.alert("提示","班别名称不能为空!")
+ }
+ })
+ }}],
+ width: 350,
+ items: [classesFormPanel]
+ }]
+ },{
+ region: "south",
+ layout: "border",
+ height: 300,
+ items: [{
+ region: "center",
+ layout: "border",
+ items: [courseGrid]
+ },{
+ region: "east",
+ layout: "border",
+ tbar:[{ text: "添加", iconCls: "add", handler: function(){
+ Ext.Msg.confirm('提示', "是否确定保存?", function(button){
+ if(button != "no"){
+ if(Ext.getCmp("courseName").getValue() != "")
+ {
+ _this.ajaxRequest("Course","create");
+ }
+ else
+ Ext.Msg.alert("提示","科目名称不能为空!")
+ }
+ })
+ }}],
+ width: 350,
+ items: [courseFormPanel]
+ }]
+ }]
+ })
+ return panel;
+ },
+
+ ajaxRequest: function(objectType,action,id){
+ if(!id)
+ id = "null";
+ var formName = objectType == "Classes" ? "classesFormPanel" : "courseFormPanel";
+ var formData = Ext.getCmp(formName).getForm().getValues();
+ var data = { object_type: objectType, action_type: action, form_data: formData, id: id}
+ Ext.Ajax.request({
+ url: "/settings/ajax_request.json",
+ method: "POST",
+ jsonData: data ,
+ success: function(response, opts){
+ objectType == "Classes" ? Ext.getCmp("classesGrid").store.reload(): Ext.getCmp("courseGrid").store.reload();
+ Ext.Msg.alert("提示","保存成功");
+ },
+ failure: function(response, opts){
+ Ext.Msg.alert("提示","保存失败");
+ }
+ })
+ },
+
+ createCourseFormPanel: function(){
+ var _this = this;
+ var panel = new Ext.form.FormPanel({
+ region: "center",
+ id: "courseFormPanel",
+ autoScroll : true,
+ frame: true,
+ buttonAlign: "center",
+ bodyStyle: 'padding:40px 10px',
+ buttons: [{
+ text: "更新", handler: function(){
+ var grid = Ext.getCmp("courseGrid");
+ var record = grid.getSelectionModel().getSelected();
+ if(!record){ Ext.Msg.alert("提示","请选择科目") }
+ else{
+ Ext.Msg.confirm("提示","是否确定保存更改",function(button){
+ if(button != "no"){
+ _this.ajaxRequest("Course","update",record.id);
+ }
+ })
+ };
+ }
+ },{
+ text: "重置", handler: function(){ Ext.getCmp("courseFormPanel").getForm().reset() }
+ }],
+ items: [{
+ layout: "column",
+ items:[{
+ defaults: { anchor: "95%" },
+ columnWidth: 1,
+ labelWidth: 50,
+ defaultType: "textfield",
+ layout: "form",
+ items:[{
+ fieldLabel: "名称",
+ name: "name",
+ id: "courseName",
+ allowBlank: false,
+ },{
+ fieldLabel: "备注",
+ name: "remark",
+ xtype: "textarea",
+ }]
+ }]
+ }]
+ });
+ return panel;
+ },
+
+ createCourseGrid: function(){
+ var courseGridStore = new Pf.util.FieldsJsonStore({
+ fields: [
+ "id",
+ "name",
+ "remark",
+ "created_at",
+ "updated_at",
+ ],
+ root: 'root',
+ url: '/settings/get_course.json',
+ totalProperty:'total',
+ method:'GET',
+ });
+
+ var cm = new Ext.grid.ColumnModel([
+ new Ext.grid.RowNumberer(),
+ { header: '名称', sortable: true, dataIndex: 'name'},
+ { header: '备注', sortable: true, dataIndex: 'remark'},
+ { header: '创建时间', sortable: true, dataIndex: 'created_at'},
+ { header: '更新时间', sortable: true, dataIndex: 'updated_at'},
+ ]);
+
+ var tbar = [
+ { iconCls: 'delete', text: '删除', handler: function(){
+ var grid = Ext.getCmp("courseGrid");
+ var record = grid.getSelectionModel().getSelected();
+ if(!record){ Ext.Msg.alert("提示","请选择班别") }
+ else{
+ Ext.Msg.confirm('提示', "是否确定删除?", function(button){
+ if(button != "no"){
+ Pf.util.loadMask.show();
+ Ext.Ajax.request({
+ url: "/settings/destroy_course.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();
+ }
+ })
+ }
+ })
+ }
+ }},
+ ];
+
+ var courseGrid = new Ext.grid.EditorGridPanel({
+ loadMask: true,
+ id: "courseGrid",
+ sm: new Ext.grid.RowSelectionModel({
+ singleSelect: true
+ }),
+ viewConfig: { forceFit: true },
+ store: courseGridStore,
+ region: "center",
+ cm: cm,
+ tbar: tbar,
+ bbar: new Pf.util.Bbar({ store: courseGridStore })
+ });
+ return courseGrid;
+ },
+
+ createClassesFormPanel: function(){
+ var _this = this;
+ var panel = new Ext.form.FormPanel({
+ //title: "班级信息",
+ region: "center",
+ id: "classesFormPanel",
+ autoScroll : true,
+ frame: true,
+ buttonAlign: "center",
+ bodyStyle: 'padding:40px 10px',
+ buttons: [{
+ text: "更新", handler: function(){
+ var grid = Ext.getCmp("classesGrid");
+ var record = grid.getSelectionModel().getSelected();
+ if(!record){ Ext.Msg.alert("提示","请选择班级") }
+ else{
+ Ext.Msg.confirm("提示","是否确定保存更改",function(button){
+ if(button != "no"){
+ _this.ajaxRequest("Classes","update",record.id);
+ }
+ })
+ };
+ }
+ },{
+ text: "重置", handler: function(){ Ext.getCmp("classesFormPanel").getForm().reset() }
+ }],
+ items: [{
+ layout: "column",
+ items:[{
+ defaults: { anchor: "95%" },
+ columnWidth: 1,
+ labelWidth: 50,
+ defaultType: "textfield",
+ layout: "form",
+ items:[{
+ fieldLabel: "班别",
+ name: "name",
+ id: "classesName",
+ allowBlank: false,
+ },{
+ fieldLabel: "备注",
+ name: "remark",
+ xtype: "textarea",
+ }]
+ }]
+ }]
+ });
+ return panel;
+ },
+
+ createClassesGrid: function(){
+ var classesGridStore = new Pf.util.FieldsJsonStore({
+ fields: [
+ "name",
+ "id",
+ "created_at",
+ "updated_at",
+ "remark",
+ "students/count",
+ ],
+ root: 'root',
+ url: '/settings/classes.json',
+ totalProperty:'total',
+ method:'GET',
+ });
+ var cm = new Ext.grid.ColumnModel([
+ new Ext.grid.RowNumberer(),
+ { header: '班别', sortable: true, dataIndex: 'name'},
+ { header: '备注', sortable: true, dataIndex: 'remark'},
+ { header: '班人数', sortable: true, dataIndex: 'students/count'},
+ { header: '创建时间', sortable: true, dataIndex: 'created_at'},
+ { header: '更新时间', sortable: true, dataIndex: 'updated_at'},
+ ]);
+ var tbar = [
+ { iconCls: 'delete', text: '删除', handler: function(){
+ var grid = Ext.getCmp("classesGrid");
+ var record = grid.getSelectionModel().getSelected();
+ if(!record){ Ext.Msg.alert("提示","请选择班别") }
+ else{
+ Ext.Msg.confirm('提示', "是否确定删除?", function(button){
+ if(button != "no"){
+ Pf.util.loadMask.show();
+ Ext.Ajax.request({
+ url: "/settings/destroy_classes.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();
+ }
+ })
+ }
+ })
+ }
+ }},
+ ];
+ var classesGrid = new Ext.grid.EditorGridPanel({
+ loadMask: true,
+ id: "classesGrid",
+ sm: new Ext.grid.RowSelectionModel({
+ singleSelect: true
+ }),
+ region: "center",
+ viewConfig: { forceFit: true },
+ store: classesGridStore,
+ cm: cm,
+ tbar: tbar,
+ bbar: new Pf.util.Bbar({ store: classesGridStore })
+ });
+ return classesGrid;
+ }
+}
View
82 public/javascripts/PF/pages/settings_index.js
@@ -16,39 +16,38 @@ Pf.settings.homeIndex = {
Ext.getCmp("identityType").disable();
});
- var panel = new Ext.TabPanel({
+ //tabPanel更换为Panel
+ var panel = new Ext.Panel({
autoScroll : true,
- activeTab: 0,
- frame: true,
- items: [
- { title: "学生主档",
- layout: "border",
- items: [
- {region: "center",layout: "border", items: grid },
- {region:"east",width: 500,layout: "border", items:new Ext.Panel({
- layout: "border",
- region: "center",
- tbar: [{
- iconCls: "add",
- text: "添加",
- handler: function(){
- Ext.Msg.confirm('提示', "是否确定保存?", function(button){
- if(button != "no"){
- if(Ext.getCmp("studentNumber").getValue() != "" && Ext.getCmp("studentName") != "" )
- {
- _this.studentUpdateOrSave("create");
- }
- else
- Ext.Msg.alert("提示"," 姓名和学号不能为空!")
+ layout: "border",
+ items: [{
+ region: "center",
+ title: "学生(成绩)主档",
+ layout: "border",
+ items: [
+ {region: "center",layout: "border", items: grid },
+ {region:"east",width: 500,layout: "border", items:new Ext.Panel({
+ layout: "border",
+ region: "center",
+ tbar: [{
+ iconCls: "add",
+ text: "添加",
+ handler: function(){
+ Ext.Msg.confirm('提示', "是否确定保存?", function(button){
+ if(button != "no"){
+ if(Ext.getCmp("studentNumber").getValue() != "" && Ext.getCmp("studentName") != "" )
+ {
+ _this.studentUpdateOrSave("create");
}
- })
- }
- }],
- items: [ studentDetailFormPanel, studentScoreGrid]
- })}
- ]
- },
- { title: "学生主档", html: "mouse" },
+ else
+ Ext.Msg.alert("提示"," 姓名和学号不能为空!")
+ }
+ })
+ }
+ }],
+ items: [ studentDetailFormPanel, studentScoreGrid]
+ })}
+ ]},
]
});
return panel;
@@ -67,12 +66,18 @@ Pf.settings.homeIndex = {
root : 'root',
url : '/homes/student_score.json',
});
+
+ function disableRender(value,metaData){
+ metaData.attr = 'style="background-color: #e1e2e4"';
+ return value;
+ };
+
var cm = new Ext.grid.ColumnModel([
new Ext.grid.RowNumberer(),
- { header: '学期', sortable: true, dataIndex: 'grade'},
- { header: '科目', sortable: true, dataIndex: 'course/name'},
+ { header: '学期', sortable: true, dataIndex: 'grade', renderer: disableRender},
+ { header: '科目', sortable: true, dataIndex: 'course/name', renderer: disableRender},
{ header: '成绩', sortable: true, dataIndex: 'score',editor:new Ext.form.NumberField() },
- { header: '备注', width: 150,sortable: true, dataIndex: 'remark'},
+ { header: '备注', width: 150,sortable: true, dataIndex: 'remark', renderer: disableRender},
]);
var grid = new Ext.grid.EditorGridPanel({
id: "studentCourseScore",
@@ -106,7 +111,6 @@ Pf.settings.homeIndex = {
}
}
}],
- //bbar : new Pf.util.Bbar({ store : studentScoreStore }),
});
return grid;
},
@@ -233,11 +237,7 @@ Pf.settings.homeIndex = {
allowBlank: false,
},
classCombox,
- // {
- // fieldLabel: "班级",
- // name: "classes/name"
- // },
- sexCombo,
+ sexCombo,
{
fieldLabel: "联系电话",
name: "phone"
@@ -265,8 +265,8 @@ Pf.settings.homeIndex = {
return formPanel;
},
+ //学生保存或者更新触发函数
studentUpdateOrSave: function(type){
- //保存更新按钮
function request(record,grid){
if(record == undefined)
record = { data:{ id: "save" } };
Please sign in to comment.
Something went wrong with that request. Please try again.