From bfebed7cb8eb3e85763a8150ea0fae0ae44c7467 Mon Sep 17 00:00:00 2001 From: Spen Date: Mon, 10 Feb 2014 15:18:47 +0800 Subject: [PATCH] Fix list check issue --- app/assets/javascripts/lib/list-check.js | 192 +++++++++--------- app/assets/stylesheets/lib/list-check.css | 4 +- app/views/admin/sites/system_info.html.erb | 49 +---- .../admin/users_new_interface/show.html.erb | 2 +- .../personal_book/plugin/_profile.html.erb | 2 +- .../plugin/_profile.html.erb | 2 +- .../personal_diploma/plugin/_profile.html.erb | 2 +- .../plugin/_profile.html.erb | 2 +- .../personal_honor/plugin/_profile.html.erb | 2 +- .../personal_journal/plugin/_profile.html.erb | 2 +- .../personal_lab/plugin/_profile.html.erb | 2 +- .../personal_patent/plugin/_profile.html.erb | 2 +- .../personal_project/plugin/_profile.html.erb | 2 +- .../plugin/_profile.html.erb | 2 +- 14 files changed, 122 insertions(+), 145 deletions(-) diff --git a/app/assets/javascripts/lib/list-check.js b/app/assets/javascripts/lib/list-check.js index 202e2d53..50423c56 100644 --- a/app/assets/javascripts/lib/list-check.js +++ b/app/assets/javascripts/lib/list-check.js @@ -1,98 +1,108 @@ -var ListCheck = function(element) { - this.element = $(element); - this.element.data('exists', true); - if(this.element.context.parentNode.tagName == "TD") { - this.elementWrap = $(this.element.context.parentNode); - this.elementWrap.addClass('listCheck'); - } else if(this.element.context.parentNode.tagName == "TH") { - this.elementWrap = $(this.element.context.parentNode); - this.elementWrap.addClass('listCheckHead'); - } - this.element.before(''); -}; - -$.fn.listCheck = function (callback) { - this.each(function (i) { - if(!$(this).data('exists')) { - new ListCheck(this); - }; - }); - this.on(clickEvent, function(e) { - if($(this).prop('checked')) { - $(this).siblings('i').addClass('icon-check').removeClass('icon-check-empty').closest('tr').addClass('checkHit'); - } else { - $(this).siblings('i').addClass('icon-check-empty').removeClass('icon-check').closest('tr').removeClass('checkHit'); - }; - if ($(this).closest('.listCheckHead').length) { - $('.listCheck .list-check').prop('checked', $(this).prop('checked')); - if($(this).prop('checked')) { - $('.listCheck i').addClass('icon-check').removeClass('icon-check-empty').closest('tr').addClass('checkHit'); - } else { - $('.listCheck i').addClass('icon-check-empty').removeClass('icon-check').closest('tr').removeClass('checkHit'); - } - }; - - var _isCheck = $('tbody .list-check').filter(':checked').length, - _defaultLength = $('tbody .list-check').length; - - if(_isCheck > 0 && _isCheck < _defaultLength) { - $('.listCheckHead i').removeClass('icon-check-empty icon-check').addClass('icon-minus'); - } else if(!_isCheck) { - $('.listCheckHead i').removeClass('icon-minus icon-check').addClass('icon-check-empty'); - } else { - $('.listCheckHead i').removeClass('icon-check-empty icon-minus').addClass('icon-check'); - } - _isCheck ? $('.list-active-btn').removeClass('disabled').data('actionable', true) : $('.list-active-btn').addClass('disabled').data('actionable', false); - }); -}; -function clearCheck() { - $('.list-check').each(function() { - $(this).prop('checked', false); - }) -} -function actionSuccess(e) { - $("tbody .list-check").each(function() { - switch(e) { - case 'list-be-hide': - $(this).filter(':checked').closest('tr').addClass('checkHide'); - break; - case 'list-be-show': - $(this).filter(':checked').closest('tr').removeClass('checkHide'); - break; - case 'list-be-remove': - $(this).filter(':checked').closest('tr').fadeOut(300, function() { - $(this).remove(); - }); - break; - }; - $('.list-check').siblings('i').removeAttr('class').addClass('icon-check-empty').closest('tr').removeClass('checkHit'); - }); - clearCheck(); -} $(function() { - var $t = null, - _data = null; - clearCheck(); - $('.list-check').listCheck(); - $('.list-active-btn').data('actionable', false).on(clickEvent, function(e) { - $t = $(this) - _data = $(this).data() - _data.actionable ? $('#dialog').modal('show') : ""; - e.preventDefault(); - }); - $('.delete-item').on(clickEvent, function() { - var _v = []; - $("tbody .list-check").each(function() { - this.checked && _v.push("ids[]="+this.value) + var ListCheckData = {}, + ListCheck = function(element) { + this.element = $(element); + this.element.data('exists', true); + if(this.element.context.parentNode.tagName == "TD") { + this.elementWrap = $(this.element.context.parentNode); + this.elementWrap.addClass('listCheck'); + } else if(this.element.context.parentNode.tagName == "TH") { + this.elementWrap = $(this.element.context.parentNode); + this.elementWrap.addClass('listCheckHead'); + } + this.element.before(''); + }; + + $.fn.listCheck = function () { + $(this).each(function() { + var $this = $(this), + $el = $this.find('input[type="checkbox"]'); + $el.each(function (i) { + if(!$(this).data('exists')) { + new ListCheck(this); + }; + }); + $this.on(clickEvent, $el, function(e) { + if($(e.target).prop('checked')) { + $(e.target).siblings('i').addClass('icon-check').removeClass('icon-check-empty').closest('tr').addClass('checkHit'); + } else { + $(e.target).siblings('i').addClass('icon-check-empty').removeClass('icon-check').closest('tr').removeClass('checkHit'); + }; + if($(e.target).closest('th').hasClass('listCheckHead')) { + $this.find('.listCheck input[type="checkbox"]').prop('checked', $(e.target).prop('checked')); + if($(e.target).prop('checked')) { + $this.find('.listCheck i').addClass('icon-check').removeClass('icon-check-empty').closest('tr').addClass('checkHit'); + } else { + $this.find('.listCheck i').addClass('icon-check-empty').removeClass('icon-check').closest('tr').removeClass('checkHit'); + } + }; + + var _isCheck = $this.find('tbody').find($el).filter(':checked').length, + _defaultLength = $this.find('tbody').find($el).length; + + if(_isCheck > 0 && _isCheck < _defaultLength) { + $this.find('.listCheckHead i').removeClass('icon-check-empty icon-check').addClass('icon-minus'); + } else if(!_isCheck) { + $this.find('.listCheckHead i').removeClass('icon-minus icon-check').addClass('icon-check-empty'); + } else { + $this.find('.listCheckHead i').removeClass('icon-check-empty icon-minus').addClass('icon-check'); + } + _isCheck ? $this.find('.list-active-btn').removeClass('disabled').data('actionable', true) : $this.find('.list-active-btn').addClass('disabled').data('actionable', false); + }); + $this.on(clickEvent, '.list-active-btn', function(e) { + if(!$(this).hasClass('disabled')) { + ListCheckData.url = $(this).attr('rel'); + ListCheckData.name = $this.find('tbody').find('input[type="checkbox"]').attr('name'); + ListCheckData.action = $(this).data('checkAction'); + ListCheckData.values = []; + ListCheckData.element = $this + $this.find('tbody').find('input[type="checkbox"]').each(function (i) { + this.checked && ListCheckData.values.push("ids[]=" + this.value); + }); + console.log(ListCheckData.values.join("&")); + $('#dialog').modal('show'); + return false; + } + }); }); - var _t = $t.attr("rel"); - if(_t.indexOf("?") > -1) { - $.ajax(_t + "&" + _v.join("&")).done(function() { - actionSuccess(_data.checkAction) + clearCheck($(this)); + }; + + function clearCheck(element) { + element.find('input[type="checkbox"]').each(function() { + $(this).prop('checked', false).siblings('i').addClass('icon-check-empty').removeClass('icon-check').closest('tr').removeClass('checkHit'); + }); + element.find('.list-active-btn').addClass('disabled'); + }; + + function actionSuccess(e) { + ListCheckData.element.find('tbody').find('input[type="checkbox"]').each(function() { + switch(e) { + case 'list-be-hide': + $(this).filter(':checked').closest('tr').addClass('checkHide'); + break; + case 'list-be-show': + $(this).filter(':checked').closest('tr').removeClass('checkHide'); + break; + case 'list-be-remove': + $(this).filter(':checked').closest('tr').fadeOut(300, function() { + $(this).remove(); + }); + break; + }; + $('.list-check').siblings('i').removeAttr('class').addClass('icon-check-empty').closest('tr').removeClass('checkHit'); + }); + clearCheck(ListCheckData.element); + } + $('.list-check').listCheck(); + $('.delete-item').on(clickEvent, function() { + if(ListCheckData.url.indexOf("?") > -1) { + $.ajax(ListCheckData.url + "&" + ListCheckData.values.join("&")).done(function() { + actionSuccess(ListCheckData.action); }); } else { - $.ajax(_t + "?" + _v.join("&")).done(function() { - actionSuccess(_data.checkAction) + $.ajax(ListCheckData.url + "?" + ListCheckData.values.join("&")).done(function() { + actionSuccess(ListCheckData.action); }); } $('#dialog').modal('hide'); diff --git a/app/assets/stylesheets/lib/list-check.css b/app/assets/stylesheets/lib/list-check.css index 5e5e05b5..d702fd37 100644 --- a/app/assets/stylesheets/lib/list-check.css +++ b/app/assets/stylesheets/lib/list-check.css @@ -4,8 +4,8 @@ vertical-align: middle; padding: 0 0 0 10px!important; } -.listCheckHead .list-check, -.listCheck .list-check { +.listCheckHead input[type="checkbox"], +.listCheck input[type="checkbox"] { position: absolute; margin: -12px 0 0 -1px; -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=0)"; diff --git a/app/views/admin/sites/system_info.html.erb b/app/views/admin/sites/system_info.html.erb index 60ef9b1b..7dce7b31 100644 --- a/app/views/admin/sites/system_info.html.erb +++ b/app/views/admin/sites/system_info.html.erb @@ -63,7 +63,7 @@
-
+

@@ -71,7 +71,7 @@ - + <%= t(:sent_date) %> <%= t(:subject) %> @@ -81,26 +81,10 @@ - - - - - 2014-01-16 17:57 - 【轉知】國家教育研究院辦理普通高級中學語文及社會領域課綱微調分區公聽會 - - - alluser@tea.ntue.edu.tw - 蔣 欣潔 - er_email -
-
+

@@ -108,32 +92,15 @@ - + - Sentdate - Subject - Mail To - Mail User - Mail From App + <%= t(:sent_date) %> + <%= t(:subject) %> + <%= t(:mail_to) %> + <%= t(:mail_from_app) %> - - - - - 2014-01-16 17:57 - 【轉知】國家教育研究院辦理普通高級中學語文及社會領域課綱微調分區公聽會 - - - alluser@tea.ntue.edu.tw - 蔣 欣潔 - er_email -
diff --git a/app/views/admin/users_new_interface/show.html.erb b/app/views/admin/users_new_interface/show.html.erb index a87e4ee2..00f4b191 100644 --- a/app/views/admin/users_new_interface/show.html.erb +++ b/app/views/admin/users_new_interface/show.html.erb @@ -66,7 +66,7 @@
-
+
<%=render :partial => @right_partial %>
diff --git a/vendor/built_in_modules/personal_book/app/views/panel/personal_book/plugin/_profile.html.erb b/vendor/built_in_modules/personal_book/app/views/panel/personal_book/plugin/_profile.html.erb index d9df9f31..5982c5d9 100644 --- a/vendor/built_in_modules/personal_book/app/views/panel/personal_book/plugin/_profile.html.erb +++ b/vendor/built_in_modules/personal_book/app/views/panel/personal_book/plugin/_profile.html.erb @@ -45,7 +45,7 @@ <% if is_admin? %> - + <% end -%> <%= t('personal_book.year') %> <%= t('personal_book.book_title') %> diff --git a/vendor/built_in_modules/personal_conference/app/views/panel/personal_conference/plugin/_profile.html.erb b/vendor/built_in_modules/personal_conference/app/views/panel/personal_conference/plugin/_profile.html.erb index 081a3c58..787ba0ff 100644 --- a/vendor/built_in_modules/personal_conference/app/views/panel/personal_conference/plugin/_profile.html.erb +++ b/vendor/built_in_modules/personal_conference/app/views/panel/personal_conference/plugin/_profile.html.erb @@ -45,7 +45,7 @@ <% if is_admin? %> - + <% end -%> <%= t('personal_conference.year') %> <%= t('module_name.personal_conference') %> diff --git a/vendor/built_in_modules/personal_diploma/app/views/panel/personal_diploma/plugin/_profile.html.erb b/vendor/built_in_modules/personal_diploma/app/views/panel/personal_diploma/plugin/_profile.html.erb index edae638a..593001bc 100644 --- a/vendor/built_in_modules/personal_diploma/app/views/panel/personal_diploma/plugin/_profile.html.erb +++ b/vendor/built_in_modules/personal_diploma/app/views/panel/personal_diploma/plugin/_profile.html.erb @@ -45,7 +45,7 @@ <% if is_admin? %> - + <% end -%> <%= t('date_') %> <%= t('personal_diploma.school_name') %> diff --git a/vendor/built_in_modules/personal_experience/app/views/panel/personal_experience/plugin/_profile.html.erb b/vendor/built_in_modules/personal_experience/app/views/panel/personal_experience/plugin/_profile.html.erb index 90da957b..9a9134b3 100644 --- a/vendor/built_in_modules/personal_experience/app/views/panel/personal_experience/plugin/_profile.html.erb +++ b/vendor/built_in_modules/personal_experience/app/views/panel/personal_experience/plugin/_profile.html.erb @@ -45,7 +45,7 @@ <% if is_admin? %> - + <% end -%> <%= t('date_') %> <%= t('personal_experience.organizationt_title') %> diff --git a/vendor/built_in_modules/personal_honor/app/views/panel/personal_honor/plugin/_profile.html.erb b/vendor/built_in_modules/personal_honor/app/views/panel/personal_honor/plugin/_profile.html.erb index 28e8658b..55fdda13 100644 --- a/vendor/built_in_modules/personal_honor/app/views/panel/personal_honor/plugin/_profile.html.erb +++ b/vendor/built_in_modules/personal_honor/app/views/panel/personal_honor/plugin/_profile.html.erb @@ -45,7 +45,7 @@ <% if is_admin? %> - + <% end -%> <%= t('personal_honor.year') %> <%= t('personal_honor.award_name') %> diff --git a/vendor/built_in_modules/personal_journal/app/views/panel/personal_journal/plugin/_profile.html.erb b/vendor/built_in_modules/personal_journal/app/views/panel/personal_journal/plugin/_profile.html.erb index 124439f2..9fa216dd 100644 --- a/vendor/built_in_modules/personal_journal/app/views/panel/personal_journal/plugin/_profile.html.erb +++ b/vendor/built_in_modules/personal_journal/app/views/panel/personal_journal/plugin/_profile.html.erb @@ -44,7 +44,7 @@ <% if is_admin? %> - + <% end -%> <%= t('personal_journal.year') %> <%= t('module_name.personal_journal') %> diff --git a/vendor/built_in_modules/personal_lab/app/views/panel/personal_lab/plugin/_profile.html.erb b/vendor/built_in_modules/personal_lab/app/views/panel/personal_lab/plugin/_profile.html.erb index 6bbc9176..f6d5a029 100644 --- a/vendor/built_in_modules/personal_lab/app/views/panel/personal_lab/plugin/_profile.html.erb +++ b/vendor/built_in_modules/personal_lab/app/views/panel/personal_lab/plugin/_profile.html.erb @@ -45,7 +45,7 @@ <% if is_admin? %> - + <% end -%> <%= t('personal_lab.year') %> <%= t('personal_lab.lab_title') %> diff --git a/vendor/built_in_modules/personal_patent/app/views/panel/personal_patent/plugin/_profile.html.erb b/vendor/built_in_modules/personal_patent/app/views/panel/personal_patent/plugin/_profile.html.erb index fd79473b..818ebb15 100644 --- a/vendor/built_in_modules/personal_patent/app/views/panel/personal_patent/plugin/_profile.html.erb +++ b/vendor/built_in_modules/personal_patent/app/views/panel/personal_patent/plugin/_profile.html.erb @@ -45,7 +45,7 @@ <% if is_admin? %> - + <% end -%> <%= t('personal_patent.publication_date') %> <%= t('personal_patent.patent_title') %> diff --git a/vendor/built_in_modules/personal_project/app/views/panel/personal_project/plugin/_profile.html.erb b/vendor/built_in_modules/personal_project/app/views/panel/personal_project/plugin/_profile.html.erb index 36084706..f4594469 100644 --- a/vendor/built_in_modules/personal_project/app/views/panel/personal_project/plugin/_profile.html.erb +++ b/vendor/built_in_modules/personal_project/app/views/panel/personal_project/plugin/_profile.html.erb @@ -45,7 +45,7 @@ <% if is_admin? %> - + <% end -%> <%= t('personal_project.period') %> <%= t('personal_project.project_title') %> diff --git a/vendor/built_in_modules/personal_research/app/views/panel/personal_research/plugin/_profile.html.erb b/vendor/built_in_modules/personal_research/app/views/panel/personal_research/plugin/_profile.html.erb index f4458489..16891f5f 100644 --- a/vendor/built_in_modules/personal_research/app/views/panel/personal_research/plugin/_profile.html.erb +++ b/vendor/built_in_modules/personal_research/app/views/panel/personal_research/plugin/_profile.html.erb @@ -45,7 +45,7 @@ <% if is_admin? %> - + <% end -%> <%= t('personal_research.publication_date') %> <%= t('personal_research.research_title') %>