公共题库
diff --git a/app/views/users/_user_homework_form.html.erb b/app/views/users/_user_homework_form.html.erb
index cc7e4bb8e..7a5bd8f27 100644
--- a/app/views/users/_user_homework_form.html.erb
+++ b/app/views/users/_user_homework_form.html.erb
@@ -23,6 +23,119 @@
$("#anonymous_comment").val(0);
}
}
+ function nh_reset_homework_form(params){
+ if(params.textarea.html() != "") {
+ cancel_edit();
+ } else {
+ params.form[0].reset();
+ params.textarea.empty();
+ if(params.editor != undefined){
+ params.editor.html(params.textarea.html());
+ }
+ }
+ }
+ function init_homework_form(params){
+ params.form.submit(function(){
+ var flag = false;
+ if(params.form.attr('data-remote') != undefined ){
+ flag = true
+ }
+ var is_checked = false;
+ checked_val();
+ if(!regex_homework_name()){
+ $("#homework_name").focus();
+ }
+ else if(!regex_homework_end_time()){
+ $("#homework_end_time").focus();
+ }
+ else if(!regex_homework_end_publish_time()){
+ $("#homework_end_time").focus();
+ }
+ else if(!regex_course_id()){
+ $("#course_id").focus();
+ }
+ else{
+ params.textarea.html(params.editor.html());
+ params.editor.sync();
+ is_checked = true;
+ }
+ /*var is_checked = nh_check_field({
+ issubmit:true,
+ content:params.editor,
+ contentmsg:params.contentmsg,
+ textarea:params.textarea
+ });*/
+ if(is_checked){
+ if(flag){
+ return true;
+ }else{
+ $(this)[0].submit();
+ return false;
+ }
+ }
+ return false;
+ });
+ }
+ function init_homework_editor(params){
+ params.textarea.removeAttr('placeholder');
+ var editor = params.kindutil.create(params.textarea, {
+ resizeType : 1,minWidth:"1px",width:"100%",minHeight:"30px",height:"30px",
+ items : ['code','emoticons','fontname',
+ 'forecolor', 'hilitecolor', 'bold', '|', 'justifyleft', 'justifycenter', 'insertorderedlist','insertunorderedlist', '|',
+ 'formatblock', 'fontsize', '|','indent', 'outdent',
+ '|','imagedirectupload','table', 'media', 'preview',"more"
+ ],
+ afterChange:function(){//按键事件
+ var edit = this.edit;
+ var body = edit.doc.body;
+ //paramsHeight = params.kindutil.removeUnit(this.height);
+ edit.iframe.height(150);
+ this.resize(null, Math.max((params.kindutil.IE ? body.scrollHeight : body.offsetHeight) + 33, 150));
+ },
+ afterCreate:function(){
+ //init
+ var edit = this.edit;
+ var body = edit.doc.body;
+ edit.iframe[0].scroll = 'no';
+ body.style.overflowY = 'hidden';
+ //reset height
+ var edit = this.edit;
+ var body = edit.doc.body;
+ edit.html(params.textarea.innerHTML);
+ //paramsHeight = params.kindutil.removeUnit(this.height);
+ edit.iframe.height(150);
+ this.resize(null, Math.max((params.kindutil.IE ? body.scrollHeight : body.offsetHeight) , 150));
+
+ }
+ }).loadPlugin('paste');
+ return editor;
+ }
+ KindEditor.ready(function(K){
+ $("div[nhname='homework_common_form']").each(function(){
+ var params = {};
+ params.kindutil = K;
+ params.div_form = $(this);
+ params.form = $("form",params.div_form);
+ if(params.form==undefined || params.form.length==0){
+ return;
+ }
+ params.textarea = $("textarea[nhname='homework_textarea']",params.div_form);
+ params.cancel_btn = $("#new_message_cancel_btn");
+ params.submit_btn = $("#new_message_submit_btn");
+ if(params.textarea.data('init') == undefined) {
+ params.editor = init_homework_editor(params);
+ init_homework_form(params);
+ params.submit_btn.click(function () {
+ params.form.submit();
+ });
+ params.cancel_btn.click(function () {
+ reset_homework();
+ nh_reset_homework_form(params);
+ });
+ params.textarea.data('init', 1);
+ }
+ });
+ });
<% end %>
@@ -70,10 +183,12 @@
<% if edit_mode %>
- <%= f.kindeditor :description, :editor_id => 'homework_description_editor', :height => "150px", :owner_id => homework.id, :owner_type => OwnerTypeHelper::HOMEWORKCOMMON, at_id: homework.id, at_type: homework.class.to_s %>
+
+ <%#= f.kindeditor :description, :editor_id => 'homework_description_editor', :height => "150px", :owner_id => homework.id, :owner_type => OwnerTypeHelper::HOMEWORKCOMMON, at_id: homework.id, at_type: homework.class.to_s %>
<% else %>
<%= hidden_field_tag :asset_id, params[:asset_id], :required => false, :style => 'display:none' %>
- <%= f.kindeditor :description, :editor_id => 'homework_description_editor', :height => "150px",at_id: homework.id, at_type: homework.class.to_s %>
+
+ <%#= f.kindeditor :description, :editor_id => 'homework_description_editor', :height => "150px",at_id: homework.id, at_type: homework.class.to_s %>
<% end %>
@@ -89,17 +204,16 @@
<%= render :partial => 'users/user_homework_attachment', :locals => {:container => homework, :has_program=>!(edit_mode && homework.homework_type != 2), :has_group=>(!(edit_mode && homework.homework_type != 3))&& homework.student_works.empty?,:show_member => true} %>
-
<% if edit_mode %>
-
确定
+
确定
或
<%#= link_to "取消",user_homeworks_user_path(User.current.id),:class => "fr mr10 mt3"%>
-
取消
+
取消
<% else %>
-
发送
+
发送
或
-
取消
+
取消
<% end %>
diff --git a/app/views/users/user_homeworks.html.erb b/app/views/users/user_homeworks.html.erb
index 7be803720..d0adb291f 100644
--- a/app/views/users/user_homeworks.html.erb
+++ b/app/views/users/user_homeworks.html.erb
@@ -5,7 +5,11 @@
$("#homework_end_time").val("");
$("#course_id").val($("#option_select").val());
$("#homework_attachments").html("<%= escape_javascript(render :partial => 'users/user_homework_attachment', :locals => { :container => HomeworkCommon.new,:has_program => true,:has_group => true })%>");
- homework_description_editor.html("");
+ //homework_description_editor.html("");
+ $("#homework_name_span").text("");
+ $("#homework_end_time_span").text("");
+ $("#homework_end_time_span").text("");
+ $("#homework_course_id_span").text("");
$("#homework_editor").toggle();
}
@@ -29,7 +33,7 @@
<% if @is_teacher%>
-
+
<% homework = HomeworkCommon.new %>
<% homework.homework_detail_manual = HomeworkDetailManual.new%>
<%= labelled_form_for homework,:url => user_new_homework_users_path,:method => "post" do |f| %>
diff --git a/app/views/users/user_import_homeworks.js.erb b/app/views/users/user_import_homeworks.js.erb
index 3be46e119..d1cb29faa 100644
--- a/app/views/users/user_import_homeworks.js.erb
+++ b/app/views/users/user_import_homeworks.js.erb
@@ -1,4 +1,5 @@
$('#ajax-modal').html('<%= escape_javascript(render :partial => 'users/show_user_homeworks') %>');
showModal('ajax-modal', '1040px');
$('#ajax-modal').siblings().remove();
-$('#ajax-modal').parent().css("top","20%").css("left","25%").css("position","fixed").css("border","3px solid #269ac9");
\ No newline at end of file
+$('#ajax-modal').parent().css("top","20%").css("left","25%").css("position","fixed").css("border","3px solid #269ac9");
+$('#ajax-modal').css("margin","15px");
diff --git a/config/routes.rb b/config/routes.rb
index f4d8daf4f..3157c50a1 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -55,6 +55,7 @@ RedmineApp::Application.routes.draw do
end
end
member do
+ get 'edit'
get 'setting'#, :action => 'settings', :as => 'settings'
get 'clear_org_avatar_temp'
put 'set_homepage'
diff --git a/public/javascripts/des_kindEditor.js b/public/javascripts/des_kindEditor.js
new file mode 100644
index 000000000..1b952672a
--- /dev/null
+++ b/public/javascripts/des_kindEditor.js
@@ -0,0 +1,136 @@
+function init_des_editor(params){
+ // var minHeight; //最小高度
+ var paramsHeight = params.height; //设定的高度
+ var paramsWidth = params.width == undefined ? "100%" : params.width;
+
+ var editor = params.kindutil.create(params.textarea, {
+ resizeType : 1,minWidth:"1px",width:paramsWidth,
+ height:"30px",// paramsHeight == undefined ? "30px":paramsHeight+"px",
+ minHeight:"30px",// paramsHeight == undefined ? "30px":paramsHeight+"px",
+ items : ['code','emoticons','fontname',
+ 'forecolor', 'hilitecolor', 'bold', '|', 'justifyleft', 'justifycenter', 'insertorderedlist','insertunorderedlist', '|',
+ 'formatblock', 'fontsize', '|','indent', 'outdent',
+ '|','imagedirectupload','table', 'media', 'preview',"more"
+ ],
+ afterChange:function(){//按键事件
+ //nh_check_field({content:this,contentmsg:params.contentmsg,textarea:params.textarea});
+ var edit = this.edit;
+ var body = edit.doc.body;
+ edit.iframe.height(paramsHeight);
+ this.resize(null, Math.max((params.kindutil.IE ? body.scrollHeight : body.offsetHeight) + 33, paramsHeight));
+ },
+ afterCreate:function(){
+ //init
+ var edit = this.edit;
+ var body = edit.doc.body;
+ edit.iframe[0].scroll = 'no';
+ body.style.overflowY = 'hidden';
+ //reset height
+ var edit = this.edit;
+ edit.html(params.textarea.innerHTML);
+ var body = edit.doc.body;
+ paramsHeight = paramsHeight == undefined ? params.kindutil.removeUnit(this.height) : paramsHeight;
+ edit.iframe.height(paramsHeight);
+ this.resize(null, Math.max((params.kindutil.IE ? body.scrollHeight : body.offsetHeight), paramsHeight));
+
+ }
+ }).loadPlugin('paste');
+ return editor;
+}
+
+function nh_check_field(params){
+ var result=true;
+ if(!check_org_title()) {
+ result=false;
+ return result;
+ }
+ if(params.content!=undefined){
+ if(params.content.isEmpty()){
+ result=false;
+ }
+ if(params.content.html()!=params.textarea.html() || params.issubmit==true){
+ params.textarea.html(params.content.html());
+ params.content.sync();
+
+ if(params.content.isEmpty()){
+ params.contentmsg.html('内容不能为空');
+ params.contentmsg.css({color:'#ff0000'});
+ }else{
+ params.contentmsg.html('填写正确');
+ params.contentmsg.css({color:'#008000'});
+ }
+ }
+ }
+ return result;
+}
+function init_form(params){
+ params.form.submit(function(){
+ var flag = false;
+ if(params.form.attr('data-remote') != undefined ){
+ flag = true
+ }
+ var is_checked = nh_check_field({
+ issubmit:true,
+ //title:params.texttitle,
+ content:params.editor,
+ //titlemsg:params.titlemsg,
+ contentmsg:params.contentmsg,
+ textarea:params.textarea
+ });
+ if(is_checked){
+ if(flag){
+ return true;
+ }else{
+ $(this)[0].submit();
+ return false;
+ }
+ }
+ return false;
+ });
+}
+function nh_reset_form(params){
+ params.form[0].reset();
+ params.texttitle.empty();
+ params.textarea.empty();
+ if(params.editor != undefined){
+ params.editor.html(params.textarea.html());
+ }
+ params.contentmsg.hide();
+ params.titlemsg.html("");
+}
+//第二个参数是高度,可以传,可以不传
+function init_des_data(){
+ var height = arguments[0] ? arguments[0] : undefined;
+ var width = arguments[1] ? arguments[1] : undefined;
+ KindEditor.ready(function (K) {
+ $("div[nhname='new_topic_form']").each(function () {
+ var params = {};
+ params.kindutil = K;
+ params.div_form = $(this);
+ params.form = $("form", params.div_form);
+ if (params.form == undefined || params.form.length == 0) {
+ return;
+ }
+ //params.texttitle = $("#document_title", params.div_form);
+ params.textarea = $("textarea[nhname='description_textarea']", params.div_form);
+ //params.titlemsg = $("#doc_title_hint", params.div_form);
+ params.contentmsg = $("#homework_course_id_span", params.div_form);
+ params.cancel_btn = $("#new_topic_cancel_btn");
+ params.submit_btn = $("#new_topic_submit_btn");
+ params.height = height;
+ params.width = width;
+ if (params.textarea.data('init') == undefined) {
+ params.editor = init_des_editor(params);
+ init_form(params);
+ params.cancel_btn.click(function () {
+ nh_reset_form(params);
+ });
+ params.submit_btn.click(function () {
+ params.form.submit();
+ });
+ params.textarea.data('init', 1);
+ $(this).show();
+ }
+ });
+ });
+}
\ No newline at end of file