From 052d293f82769541015d8f2935de8c29498d6dde Mon Sep 17 00:00:00 2001 From: huang Date: Fri, 22 May 2015 16:30:22 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=BB=BA=E9=A1=B9=E7=9B=AE=E6=97=B6?= =?UTF-8?q?=E5=80=99=EF=BC=9A=20=E5=A6=82=E6=9E=9C=E6=88=91=E7=9A=84?= =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E4=B8=AD=E6=9C=89=E9=87=8D=E5=90=8D=E7=9A=84?= =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E4=B8=8D=E5=85=81=E8=AE=B8=E6=96=B0=E5=BB=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/projects_helper.rb | 10 ++++++++++ public/javascripts/project.js | 33 ++++++++++++++++++++++++++++++++- 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb index 508e58ba3..12925b0b1 100644 --- a/app/helpers/projects_helper.rb +++ b/app/helpers/projects_helper.rb @@ -65,6 +65,16 @@ module ProjectsHelper content_tag('div', content, :class => "tabs") end + # 判断我的项目中是否有重名项目 + def judge_same_projectname(user, project_name) + result = false + my_projects = user.projects + my_projects.each do |mp| + result = true if mp.name == project_name + end + return result + end + # Added by young def course_settings_tabs tabs = [{:name => 'info', :action => :edit_project, :partial => 'projects/edit', :label => :label_information_plural, :course=>'1'}, diff --git a/public/javascripts/project.js b/public/javascripts/project.js index 0a04b2a7b..f9f88703d 100644 --- a/public/javascripts/project.js +++ b/public/javascripts/project.js @@ -425,4 +425,35 @@ $(function(){ personalized_init(); }); -//cookie记忆html区块 显示/隐藏 的代码 end \ No newline at end of file +//cookie记忆html区块 显示/隐藏 的代码 end + +// 新建项目的时候判断是否与我已有的项目重复 +function judgeprojectname(){ + $('#new_project').validate({ + errorPlacement: function(error, element){ + alert('error') + }, + success: function(label){ + alert('ok') + }, + onkeyup: false, + rules : { + name:{required : true, + remote : { + url : 'projects/judge_same_projectname', + type:'get', + dataType:'text', + data:{ + name : function(){ return $.trim( $("#name").val() ); } + }, + dataFilter:function( data ){ + if( data=='true')return false; else return true; + } + } + } + }, + messages : { + name:{required : "请填写项目名称!",remote:'您已新建过同名项目,请修改项目名称!'} + } + }); +} \ No newline at end of file