From 64889fd14a9d548fa5bdc6ef28038d27faa89467 Mon Sep 17 00:00:00 2001 From: huang Date: Fri, 8 Jan 2016 20:10:43 +0800 Subject: [PATCH 01/10] =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E8=B5=84=E6=BA=90?= =?UTF-8?q?=E6=8F=90=E4=BE=9B=E6=96=B0=E5=88=86=E9=A1=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/files_controller.rb | 1 + app/views/files/_course_file.html.erb | 2 +- app/views/files/_project_list.html.erb | 15 ++++++++++++--- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb index c6773ef57..06ea15357 100644 --- a/app/controllers/files_controller.rb +++ b/app/controllers/files_controller.rb @@ -230,6 +230,7 @@ class FilesController < ApplicationController @order = "" @is_remote = false if params[:project_id] + @page = params[:page] ? params[:page].to_i + 1 : 2 @container_type = 0 if params[:sort] params[:sort].split(",").each do |sort_type| diff --git a/app/views/files/_course_file.html.erb b/app/views/files/_course_file.html.erb index 5a6ce69ce..9513baab0 100644 --- a/app/views/files/_course_file.html.erb +++ b/app/views/files/_course_file.html.erb @@ -123,7 +123,7 @@
- <%= render :partial => 'course_list',:locals => {course: @course,all_attachments: @all_attachments,sort:@sort,order:@order,curse_attachments:@obj_attachments, :page=>2} %> + <%= render :partial => 'course_list',:locals => {course: @course,all_attachments: @all_attachments,sort:@sort,order:@order,curse_attachments:@obj_attachments} %>
<% html_title(l(:label_attachment_plural)) -%> \ No newline at end of file diff --git a/app/views/files/_project_list.html.erb b/app/views/files/_project_list.html.erb index d84c1cada..0d4b0f35e 100644 --- a/app/views/files/_project_list.html.erb +++ b/app/views/files/_project_list.html.erb @@ -45,8 +45,17 @@ <% end %> <% end %> - +<% if project_attachments.count == 10%> + <% if params[:action] == 'search_project' %> + + + + <%=link_to "点击展开更多", search_project_project_files_path({:project_id => project.id, :page => @obj_pages.nil? ? @feedback_pages.page + 1 : @obj_pages.page + 1}.merge(params)),:id => "show_more_attachments",:remote => "true",:class => "loadMore mt10 f_grey" %> + <%else%> + + <%=link_to "点击展开更多", project_files_path(:project_id => project.id,:page => @page),:id => "show_more_attachments",:remote => "true",:class => "loadMore mt10 f_grey" %> + <%end%> +<% end%> + From f9bc1efd7cdd9f9b7083bb8b47c50959b5d1cfdf Mon Sep 17 00:00:00 2001 From: huang Date: Fri, 8 Jan 2016 21:18:08 +0800 Subject: [PATCH 02/10] =?UTF-8?q?issue=E7=BC=96=E8=BE=91=E7=9A=84=E6=97=B6?= =?UTF-8?q?=E5=80=99ajax=E5=88=B7=E6=96=B0=E9=99=84=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/issues_controller.rb | 1 + app/views/issues/add_journal.js.erb | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index 91a0bc902..4aa959e81 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -412,6 +412,7 @@ class IssuesController < ApplicationController if params[:issue_id] @issue_id = params[:issue_id] end + @priorities = IssuePriority.active respond_to do |format| format.js end diff --git a/app/views/issues/add_journal.js.erb b/app/views/issues/add_journal.js.erb index edc8d257b..eca7685cb 100644 --- a/app/views/issues/add_journal.js.erb +++ b/app/views/issues/add_journal.js.erb @@ -1,6 +1,21 @@ <% if @issue_id %> //issue详情中回复 $("#reply_div_<%= @issue_id %>").html("<%= escape_javascript(render :partial => 'issues/issue_replies', :locals => {:issue => Issue.find( @issue_id),:replies_all_i=>0}) %>"); $("#div_issue_attachment_<%=@issue.id %>").html("<%= escape_javascript(render :partial => 'issues/issue_attachments', :locals => {:issue => Issue.find( @issue_id)}) %>"); + $("#issue_edit").replaceWith('<%= escape_javascript(render :partial => 'issues/edit') %>') + sd_create_editor_from_data(<%= @issue.id%>, null, "100%"); + issue_desc_editor = KindEditor.create('#issue_description', + {"width":"85%", + "resizeType":0, + "no_label":true, + "at_id":<%= @issue.project_id%>, + "at_type":"Project", + "autoHeightMode":true, + "afterCreate":"eval(function(){ if(typeof enablePasteImg ==='function'){enablePasteImg(self);};if(typeof enableAt ==='function'){enableAt(self, \"<%=@issue.project_id %>\", 'Project');}; this.loadPlugin('autoheight')})", + "emotionsBasePath":'<%= Setting.host_name%>', + "height":300, + "allowFileManager":true, + "uploadJson":"/kindeditor/upload", + "fileManagerJson":"/kindeditor/filemanager"}); // $("#issue_test_<%#= @issue.id %>").html("<%#= escape_javascript(render :partial => 'issues/edit', :locals => {:issue => Issue.find( @issue_id)}) %>"); $(".homepagePostReplyBannerCount").html('回复(<%= Issue.find( @issue_id).journals.count %>)') sd_create_editor_from_data(<%= @issue.id %>, null, "100%"); From eab8cc723188db97cc873d095c2b9dc18787be1e Mon Sep 17 00:00:00 2001 From: cxt Date: Fri, 8 Jan 2016 21:22:36 +0800 Subject: [PATCH 03/10] =?UTF-8?q?=E5=A4=8D=E5=88=B6=E5=AD=A6=E6=9C=9F?= =?UTF-8?q?=E7=9A=84=E9=BB=98=E8=AE=A4=E5=9B=BE=E7=89=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/courses/_copy_course.html.erb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/views/courses/_copy_course.html.erb b/app/views/courses/_copy_course.html.erb index d4debb601..a759946f6 100644 --- a/app/views/courses/_copy_course.html.erb +++ b/app/views/courses/_copy_course.html.erb @@ -37,7 +37,10 @@
    <%=labelled_form_for @new_course do |f| %> -
  • 上传图片 +
  • + + <%= image_tag(url_to_avatar(@new_course), id: "avatar_image", :width =>"60", :height =>"60",:alt=>"上传图片")%> +
  • From 5d68d185d5c3929a57b4b9a357d5fc409b9a9854 Mon Sep 17 00:00:00 2001 From: huang Date: Fri, 8 Jan 2016 21:24:25 +0800 Subject: [PATCH 04/10] =?UTF-8?q?=E8=B5=84=E6=BA=90=E6=A0=B7=E5=BC=8F?= =?UTF-8?q?=E5=86=B2=E7=AA=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/stylesheets/public.css | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/public/stylesheets/public.css b/public/stylesheets/public.css index 51e2ffe67..d39e2600d 100644 --- a/public/stylesheets/public.css +++ b/public/stylesheets/public.css @@ -435,6 +435,8 @@ a:hover.search_btn{ background: #0fa9bb;} .searchResourcePopup {border:none; outline:none; background-color:#ffffff; width:184px; height:25px; padding-left:10px; display:inline-block; float:left;} .searchIconPopup{width:31px; height:25px; background-color:#ffffff; background:url(../images/homepage_icon.png) 5px -394px no-repeat; display:inline-block; float:left; cursor: pointer;} .searchIconPopup:hover {background:url(../images/homepage_icon.png) 5px -420px no-repeat;} +.searchIcon2{width:31px; height:25px; background-color:#ffffff; background:url(../images/homepage_icon2.png) -180px -273px no-repeat; display:inline-block; float:left; cursor: pointer;} +.searchIcon2:hover {background:url(../images/homepage_icon2.png) -180px -314px no-repeat;} .courseSend {width:390px; height:15px; line-height:15px; margin-bottom:10px;display:block;white-space:nowrap;} .courseSendCheckbox {padding:0px; margin:0px; width:12px; height:12px; margin-right:10px; display:inline-block; margin-top:2px;} .sendCourseName {font-size:12px; color:#5f6060;display:inline-block} @@ -969,6 +971,12 @@ span.at a{color:#269ac9;text-decoration: none;} .sectionContent span {width:160px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; display:inline-block; height:20px; vertical-align:top;} .orgDirection {width:392px; background-color:#f1f1f1; height:30px; vertical-align:middle; line-height:30px; color:#585858; padding-left:10px;} .orgSendSearch {border:1px solid #dddddd; outline:none; width:262px; height:22px; padding-left:10px; float:left;} +/*新课程、项目资源库*/ +.reCon{ margin:5px; width:710px;} +.reTop{width:710px; height:40px; background:#eaeaea; padding:5px;} +.researchBox { width:240px; height:24px; border:1px solid #dddddd; color:#666666; outline:none;} +.blueBtn{ width:60px; height:26px; color:#FFF; border:none; background-color:#269ac9; cursor:pointer; padding-left:0px; text-align:center;} +.blueBtn:hover {background-color:#298fbd;} /*文本描述展开高度*/ .maxh360 {max-height: 810px;} From a3370b693c99072d3cf4e66666871d21a3372ec0 Mon Sep 17 00:00:00 2001 From: cxt Date: Fri, 8 Jan 2016 21:46:10 +0800 Subject: [PATCH 05/10] =?UTF-8?q?=E8=AF=BE=E7=A8=8B=E5=85=B3=E8=81=94?= =?UTF-8?q?=E7=BB=84=E7=BB=87=E5=88=97=E8=A1=A8=E4=B8=BA=E7=A9=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/courses_controller.rb | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 70794fa71..5c7e8dfc3 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -39,17 +39,17 @@ class CoursesController < ApplicationController end limit = 15 course_org_ids = OrgCourse.find_by_sql("select distinct organization_id from org_courses where course_id = #{params[:id]}").map(&:organization_id) - @orgs_not_in_course = User.current.organizations.where("organizations.id not in (#{course_org_ids.join(',')}) and organizations.name like ?", condition).page(params[:page].to_i || 1).per(limit) - @org_count = User.current.organizations.where("organizations.id not in (#{course_org_ids.join(',')}) and organizations.name like ?", condition).count - # if course_org_ids.empty? - # @orgs_not_in_course = Organization.where("(is_public or creator_id =?) and name like ?",User.current.id, condition).page((params[:page].to_i || 1)).per(limit) - # @org_count = Organization.where("is_public = 1 or creator_id =?", User.current.id).where("name like ?", condition).count - # else - # course_org_ids = "(" + course_org_ids.join(',') + ")" - # @orgs_not_in_course = Organization.where("id not in #{course_org_ids} and (is_public = 1 or creator_id =?) and name like ?", User.current.id, condition).page((params[:page].to_i || 1)).per(limit) - # @org_count = Organization.where("id not in #{course_org_ids} and (is_public = 1 or creator_id =?)", User.current.id).where("name like ?", condition).count - # end - # @course_count = Project.course_entities.visible.like(params[:name]).page(params[:page]).count + #@orgs_not_in_course = User.current.organizations.where("organizations.id not in (#{course_org_ids.join(',')}) and organizations.name like ?", condition).page(params[:page].to_i || 1).per(limit) + #@org_count = User.current.organizations.where("organizations.id not in (#{course_org_ids.join(',')}) and organizations.name like ?", condition).count + if course_org_ids.empty? + @orgs_not_in_course = User.current.organizations.where("name like ?",condition).page((params[:page].to_i || 1)).per(limit) + @org_count = @orgs_not_in_course.count + else + course_org_ids = "(" + course_org_ids.join(',') + ")" + @orgs_not_in_course = User.current.organizations.where("id not in #{course_org_ids} and name like ?", condition).page((params[:page].to_i || 1)).per(limit) + @org_count = @orgs_not_in_course.count + end + @course_count = Project.course_entities.visible.like(params[:name]).page(params[:page]).count @orgs_page = Paginator.new @org_count, limit,params[:page] @hint_flag = params[:hint_flag] #render :json => {:orgs => @orgs_not_in_course, :count => @org_count}.to_json From 8c10ce6feeddc455622447c51fbd2ec2afd6459f Mon Sep 17 00:00:00 2001 From: huang Date: Fri, 8 Jan 2016 21:47:42 +0800 Subject: [PATCH 06/10] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=BB=84=E7=BB=87500?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/application_helper.rb | 13 +++++++++++++ .../organizations/_org_left_subfield_list.html.erb | 6 +++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 56ef460a0..9b7888bf2 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -59,6 +59,19 @@ module ApplicationHelper end end + # 判断组织左侧展开或者隐藏 + def is_hide_org_left obj + if obj.nil? + return true + else + if obj.hide == 0 + return true + else + return false + end + end + end + # Time 2015-03-24 16:38:05 # Author lizanle # Description after save后需要进行资源记录的更新 diff --git a/app/views/organizations/_org_left_subfield_list.html.erb b/app/views/organizations/_org_left_subfield_list.html.erb index 8280a2be7..31d6925db 100644 --- a/app/views/organizations/_org_left_subfield_list.html.erb +++ b/app/views/organizations/_org_left_subfield_list.html.erb @@ -37,10 +37,10 @@ <% org_activity_field = organization.org_subfields.where('field_type="default" and name="activity" and field_type="default"').first %> <% org_course_field = organization.org_subfields.where('field_type="default" and name="course" and field_type="default"').first %> <% org_project_field = organization.org_subfields.where('field_type="default" and name="project" and field_type="default"').first %> -
    +
    <%= link_to "动态",organization_path(organization), :class => "homepageMenuText" %>
    -
    +
    项目 <% if User.current.logged? and User.current.admin_of_org?(organization) %> @@ -54,7 +54,7 @@
-
+
课程 <% if User.current.logged? and User.current.admin_of_org?(organization) %> From bb0a03b3093ae496da29c496b9bf47b8d0d017df Mon Sep 17 00:00:00 2001 From: cxt Date: Fri, 8 Jan 2016 22:02:35 +0800 Subject: [PATCH 07/10] =?UTF-8?q?=E8=8B=A5=E6=97=A0=E4=BB=BB=E4=BD=95?= =?UTF-8?q?=E4=B8=AA=E4=BA=BA=E7=95=99=E8=A8=80=EF=BC=8C=E6=88=96=E8=80=85?= =?UTF-8?q?=E5=BD=93=E5=89=8D=E7=94=A8=E6=88=B7=E6=97=A0=E6=9D=83=E9=99=90?= =?UTF-8?q?=E7=9C=8B=E5=88=B0=E4=BB=BB=E4=BD=95=E4=B8=AA=E4=BA=BA=E7=95=99?= =?UTF-8?q?=E8=A8=80=EF=BC=8C=E4=B8=8D=E8=A6=81=E6=98=BE=E7=A4=BA=E7=99=BD?= =?UTF-8?q?=E6=A1=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/words/destroy.js.erb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/views/words/destroy.js.erb b/app/views/words/destroy.js.erb index 7194a16a4..6a56249a3 100644 --- a/app/views/words/destroy.js.erb +++ b/app/views/words/destroy.js.erb @@ -6,6 +6,9 @@ destroyedItem.fadeOut(600,function(){ destroyedItem.remove(); }); + <% if @jours_count && @jours_count == 0 %> + $("#user_jour_list").css("padding","0px"); + <% end %> <% else %> <% if @bid && @jours_count %> $('#jours_count').html("<%= @jours_count %>"); From c719fd96a3951167f3e27efe6813b9ea83382c87 Mon Sep 17 00:00:00 2001 From: huang Date: Fri, 8 Jan 2016 22:29:57 +0800 Subject: [PATCH 08/10] 0 --- app/controllers/avatar_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/avatar_controller.rb b/app/controllers/avatar_controller.rb index a7c0e7b95..b5c174b0c 100644 --- a/app/controllers/avatar_controller.rb +++ b/app/controllers/avatar_controller.rb @@ -10,7 +10,7 @@ class AvatarController < ApplicationController unless request.content_type == 'application/octet-stream' @source_type = params[:source_type] @source_id = params[:source_id] - @temp_file = params[:avatar][:image] + @temp_file = params[:avatar][:image] @image_file = @temp_file.original_filename else unless request.raw_post.nil? @@ -23,7 +23,7 @@ class AvatarController < ApplicationController #image_file.force_encoding("UTF-8") if filename.respond_to?(:force_encoding) else @image_file=params[:filename] - end + end @temp_file = StringIO.new(@temp_file) end end From 66c3cee3f88d02837dbcc28af2a709848edb901b Mon Sep 17 00:00:00 2001 From: cxt Date: Fri, 8 Jan 2016 22:30:04 +0800 Subject: [PATCH 09/10] =?UTF-8?q?=E8=AF=BE=E7=A8=8B=E5=85=B3=E8=81=94?= =?UTF-8?q?=E7=BB=84=E7=BB=87=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/courses_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 5c7e8dfc3..279975c77 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -46,8 +46,8 @@ class CoursesController < ApplicationController @org_count = @orgs_not_in_course.count else course_org_ids = "(" + course_org_ids.join(',') + ")" - @orgs_not_in_course = User.current.organizations.where("id not in #{course_org_ids} and name like ?", condition).page((params[:page].to_i || 1)).per(limit) - @org_count = @orgs_not_in_course.count + @orgs_not_in_course = User.current.organizations.where("organizations.id not in #{course_org_ids} and organizations.name like ?", condition).page((params[:page].to_i || 1)).per(limit) + @org_count = @orgs_not_in_course.empty? ? 0 : @orgs_not_in_course.count end @course_count = Project.course_entities.visible.like(params[:name]).page(params[:page]).count @orgs_page = Paginator.new @org_count, limit,params[:page] From e96496ddcde78ddecabac6557489fa2366df9d65 Mon Sep 17 00:00:00 2001 From: guange <8863824@gmail.com> Date: Fri, 8 Jan 2016 23:01:16 +0800 Subject: [PATCH 10/10] =?UTF-8?q?avatar.js=E5=92=8Cattachments.js=E5=86=B2?= =?UTF-8?q?=E7=AA=81,=E5=AF=BC=E8=87=B4=E5=A4=B4=E5=83=8F=E4=B8=8D?= =?UTF-8?q?=E8=83=BD=E4=B8=8A=E4=BC=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/javascripts/avatars.js | 395 +++++++++++++++++----------------- 1 file changed, 201 insertions(+), 194 deletions(-) diff --git a/public/javascripts/avatars.js b/public/javascripts/avatars.js index 571ea4982..05b0df2fe 100644 --- a/public/javascripts/avatars.js +++ b/public/javascripts/avatars.js @@ -2,210 +2,217 @@ Copyright (C) 2006-2013 Jean-Philippe Lang Modified by Jianfeng Tao, to upload one avatar for user*/ -function addFile(inputEl, file, eagerUpload) { - - var fileSpan = $('#avatar_file'); - //fileSpan.append( - // $('', { type: 'text', 'class': 'filename readonly', name: 'avatar[filename]', readonly: 'readonly'} ).val(file.name), - // $(' ').attr({ href: "#", 'class': 'remove-upload' }).click(removeFile).toggle(!eagerUpload) - //).appendTo('#avatar_fields'); +(function(){ - if(eagerUpload) { - ajaxUpload(file, fileSpan, inputEl); + function addFile(inputEl, file, eagerUpload) { + + var fileSpan = $('#avatar_file'); + + //fileSpan.append( + // $('', { type: 'text', 'class': 'filename readonly', name: 'avatar[filename]', readonly: 'readonly'} ).val(file.name), + // $(' ').attr({ href: "#", 'class': 'remove-upload' }).click(removeFile).toggle(!eagerUpload) + //).appendTo('#avatar_fields'); + + if(eagerUpload) { + ajaxUpload(file, fileSpan, inputEl); + } + + return 1; } - return 1; -} + function ajaxUpload(file, fileSpan, inputEl) { + + function onLoadstart(e) { + fileSpan.removeClass('ajax-waiting'); + fileSpan.addClass('ajax-loading'); + $('input:submit', $(this).parents('form')).attr('disabled', 'disabled'); + } + + function onProgress(e) { + if(e.lengthComputable) { + this.progressbar( 'value', e.loaded * 100 / e.total ); + } + } + + function actualUpload(file, fileSpan, inputEl) { + + ajaxUpload.uploading++; + + uploadBlob(file, $(inputEl).data('upload-path'),$(inputEl).data('source-type'), $(inputEl).data('source-id'),{ + loadstartEventHandler: onLoadstart.bind(progressSpan), + progressEventHandler: onProgress.bind(progressSpan) + }) + .done(function(result) { + progressSpan.progressbar( 'value', 100 ); + progressSpan.progressbar( 'destroy'); + fileSpan.find('input.description, a').css('display', 'inline-block'); + }) + .fail(function(result) { + progressSpan.text(result.statusText); + }).always(function() { + ajaxUpload.uploading--; + fileSpan.removeClass('ajax-loading'); + var form = fileSpan.parents('form'); + + // if (form.queue('upload').length == 0 && ajaxUpload.uploading == 0) { + // $('input:submit', form).removeAttr('disabled'); + // } + // form.dequeue('upload'); + }); + } + + + var progressSpan = $('#upload_progressbar'); + progressSpan.progressbar(); + fileSpan.addClass('ajax-waiting'); + + var maxSyncUpload = $(inputEl).data('max-concurrent-uploads'); + + if(maxSyncUpload == null || maxSyncUpload <= 0 || ajaxUpload.uploading < maxSyncUpload) + actualUpload(file, fileSpan, inputEl); + else + $(inputEl).parents('form').queue('upload', actualUpload.bind(this, file, fileSpan, inputEl)); + } -function ajaxUpload(file, fileSpan, inputEl) { + ajaxUpload.uploading = 0; - function onLoadstart(e) { - fileSpan.removeClass('ajax-waiting'); - fileSpan.addClass('ajax-loading'); - $('input:submit', $(this).parents('form')).attr('disabled', 'disabled'); - } + function removeFile() { + $(this).parent('span').remove(); + return false; + } - function onProgress(e) { - if(e.lengthComputable) { - this.progressbar( 'value', e.loaded * 100 / e.total ); + function uploadBlob(blob, uploadUrl, source_type,source_id, options) { + + var actualOptions = $.extend({ + loadstartEventHandler: $.noop, + progressEventHandler: $.noop + }, options); + + uploadUrl = uploadUrl + '?source_type=' + source_type + '&source_id=' + source_id; + if (blob instanceof window.File) { + uploadUrl += '&filename=' + encodeURIComponent(blob.name); + } + + return $.ajax(uploadUrl, { + type: 'POST', + contentType: 'application/octet-stream', + beforeSend: function(jqXhr) { + jqXhr.setRequestHeader('Accept', 'application/js'); + }, + xhr: function() { + var xhr = $.ajaxSettings.xhr(); + xhr.upload.onloadstart = actualOptions.loadstartEventHandler; + xhr.upload.onprogress = actualOptions.progressEventHandler; + return xhr; + }, + data: blob, + cache: false, + processData: false + }); } - } - - function actualUpload(file, fileSpan, inputEl) { - - ajaxUpload.uploading++; - - uploadBlob(file, $(inputEl).data('upload-path'),$(inputEl).data('source-type'), $(inputEl).data('source-id'),{ - loadstartEventHandler: onLoadstart.bind(progressSpan), - progressEventHandler: onProgress.bind(progressSpan) - }) - .done(function(result) { - progressSpan.progressbar( 'value', 100 ); - progressSpan.progressbar( 'destroy'); - fileSpan.find('input.description, a').css('display', 'inline-block'); - }) - .fail(function(result) { - progressSpan.text(result.statusText); - }).always(function() { - ajaxUpload.uploading--; - fileSpan.removeClass('ajax-loading'); - var form = fileSpan.parents('form'); - - // if (form.queue('upload').length == 0 && ajaxUpload.uploading == 0) { - // $('input:submit', form).removeAttr('disabled'); - // } - // form.dequeue('upload'); - }); - } - - - var progressSpan = $('#upload_progressbar'); - progressSpan.progressbar(); - fileSpan.addClass('ajax-waiting'); - - var maxSyncUpload = $(inputEl).data('max-concurrent-uploads'); - - if(maxSyncUpload == null || maxSyncUpload <= 0 || ajaxUpload.uploading < maxSyncUpload) - actualUpload(file, fileSpan, inputEl); - else - $(inputEl).parents('form').queue('upload', actualUpload.bind(this, file, fileSpan, inputEl)); -} - -ajaxUpload.uploading = 0; - -function removeFile() { - $(this).parent('span').remove(); - return false; -} - -function uploadBlob(blob, uploadUrl, source_type,source_id, options) { - - var actualOptions = $.extend({ - loadstartEventHandler: $.noop, - progressEventHandler: $.noop - }, options); - - uploadUrl = uploadUrl + '?source_type=' + source_type + '&source_id=' + source_id; - if (blob instanceof window.File) { - uploadUrl += '&filename=' + encodeURIComponent(blob.name); - } - - return $.ajax(uploadUrl, { - type: 'POST', - contentType: 'application/octet-stream', - beforeSend: function(jqXhr) { - jqXhr.setRequestHeader('Accept', 'application/js'); - }, - xhr: function() { - var xhr = $.ajaxSettings.xhr(); - xhr.upload.onloadstart = actualOptions.loadstartEventHandler; - xhr.upload.onprogress = actualOptions.progressEventHandler; - return xhr; - }, - data: blob, - cache: false, - processData: false - }); -} - -function addInputAvatar(inputEl) { + + window.addInputAvatar = function(inputEl) { // var clearedFileInput = $(inputEl).clone().val(''); - if (inputEl.files) { - // upload files using ajax - uploadAndAttachFiles(inputEl.files, inputEl); - // $(inputEl).remove(); - } else { - // browser not supporting the file API, upload on form submission - var avatarId; - var aFilename = inputEl.value.split(/\/|\\/); - avatarId = addFile(inputEl, { name: aFilename[ aFilename.length - 1 ] }, false); - if (avatarId) { - $(inputEl).attr({ name: 'avatar[file]', style: 'display:none;' }).appendTo('#avatar_image'); + if (inputEl.files) { + // upload files using ajax + uploadAndAttachFiles(inputEl.files, inputEl); + // $(inputEl).remove(); + } else { + // browser not supporting the file API, upload on form submission + var avatarId; + var aFilename = inputEl.value.split(/\/|\\/); + avatarId = addFile(inputEl, { name: aFilename[ aFilename.length - 1 ] }, false); + if (avatarId) { + $(inputEl).attr({ name: 'avatar[file]', style: 'display:none;' }).appendTo('#avatar_image'); + } + } + + //clearedFileInput.insertAfter('#avatars_fields'); } - } - - //clearedFileInput.insertAfter('#avatars_fields'); -} - - -function uploadAndAttachFiles(files, inputEl) { - - var maxFileSize = $(inputEl).data('max-file-size'); - var maxFileSizeExceeded = $(inputEl).data('max-file-size-message'); - - var sizeExceeded = false; - $.each(files, function() { - if (this.size && maxFileSize && this.size > parseInt(maxFileSize)) {sizeExceeded=true;} - }); - if (sizeExceeded) { - window.alert(maxFileSizeExceeded); - } else { - uploadAndTypeFiles(files,inputEl); - //$.each(files, function() {addFile(inputEl, this, true);}); - } -} - -function uploadAndTypeFiles(files, inputEl) { - - var enableType = $(inputEl).data('file-type'); - var typeSupportrdMessage = $(inputEl).data('type-support-message'); - if (enableType == null || enableType.trim() == "") - { - $.each(files, function() {addFile(inputEl, this, true);}); - return; + + function uploadAndAttachFiles(files, inputEl) { + + var maxFileSize = $(inputEl).data('max-file-size'); + var maxFileSizeExceeded = $(inputEl).data('max-file-size-message'); + + var sizeExceeded = false; + $.each(files, function() { + if (this.size && maxFileSize && this.size > parseInt(maxFileSize)) {sizeExceeded=true;} + }); + if (sizeExceeded) { + window.alert(maxFileSizeExceeded); + } else { + uploadAndTypeFiles(files,inputEl); + //$.each(files, function() {addFile(inputEl, this, true);}); + } } - var typeSupported = false; - $.each(files, function() { - var a = this.name.split('.'); - var type = a[a.length-1]; - var rs = enableType.indexOf(type); - if(rs >= 0) {typeSupported = true } - }); - if (typeSupported) { - $.each(files, function() {addFile(inputEl, this, true);}); - } else { - window.alert(typeSupportrdMessage + enableType); + + function uploadAndTypeFiles(files, inputEl) { + + var enableType = $(inputEl).data('file-type'); + var typeSupportrdMessage = $(inputEl).data('type-support-message'); + if (enableType == null || enableType.trim() == "") + { + $.each(files, function() {addFile(inputEl, this, true);}); + return; + } + var typeSupported = false; + $.each(files, function() { + var a = this.name.split('.'); + var type = a[a.length-1]; + var rs = enableType.indexOf(type); + if(rs >= 0) {typeSupported = true } + }); + if (typeSupported) { + $.each(files, function() {addFile(inputEl, this, true);}); + } else { + window.alert(typeSupportrdMessage + enableType); + } } -} - -function handleFileDropEvent(e) { - - $(this).removeClass('fileover'); - blockEventPropagation(e); - - if ($.inArray('Files', e.dataTransfer.types) > -1) { - uploadAndAttachFiles(e.dataTransfer.files, $('input:file.file_selector')); - } -} - -function dragOverHandler(e) { - $(this).addClass('fileover'); - blockEventPropagation(e); -} - -function dragOutHandler(e) { - $(this).removeClass('fileover'); - blockEventPropagation(e); -} - -function setupFileDrop() { - $('#avatar_image').on('click', function(){ - console.log("click"); - }); - if (window.File && window.FileList && window.ProgressEvent && window.FormData) { - - $.event.fixHooks.drop = { props: [ 'dataTransfer' ] }; - - $('form div.box').has('input:file').each(function() { - $(this).on({ - dragover: dragOverHandler, - dragleave: dragOutHandler, - drop: handleFileDropEvent - }); - }); - } -} - -$(document).ready(setupFileDrop); + + + + + function handleFileDropEvent(e) { + $(this).removeClass('fileover'); + blockEventPropagation(e); + + if ($.inArray('Files', e.dataTransfer.types) > -1) { + uploadAndAttachFiles(e.dataTransfer.files, $('input:file.file_selector')); + } + } + + function dragOverHandler(e) { + $(this).addClass('fileover'); + blockEventPropagation(e); + } + + function dragOutHandler(e) { + $(this).removeClass('fileover'); + blockEventPropagation(e); + } + + function setupFileDrop() { + console.log("setupFileDrop"); + $('#avatar_image').on('click', function(){ + console.log("click"); + }); + if (window.File && window.FileList && window.ProgressEvent && window.FormData) { + + $.event.fixHooks.drop = { props: [ 'dataTransfer' ] }; + + $('form div.box').has('input:file').each(function() { + $(this).on({ + dragover: dragOverHandler, + dragleave: dragOutHandler, + drop: handleFileDropEvent + }); + }); + } + } + + $(document).ready(setupFileDrop); +})(); +