From ca20e904be115a6c5fd996a94828540cf73c5644 Mon Sep 17 00:00:00 2001 From: Hanyoung Cho Date: Wed, 28 Nov 2012 14:54:24 +0900 Subject: [PATCH] Refactoring coffee --- root/static/scripts/list.coffee | 69 +++++----------------------- root/static/scripts/list.js | 80 +++++---------------------------- 2 files changed, 22 insertions(+), 127 deletions(-) diff --git a/root/static/scripts/list.coffee b/root/static/scripts/list.coffee index 1fbf546..68754df 100644 --- a/root/static/scripts/list.coffee +++ b/root/static/scripts/list.coffee @@ -1,68 +1,19 @@ $ -> - $('#head_checkbox').click -> - cbs = $(":checkbox") - for cb,i in cbs - if cbs[i].type is "checkbox" - cbs[i].checked = $(@).is(':checked') - - $('#do_delete').click -> - selected_charges = [] - - $('#charge_list tr').filter(':has(:checkbox:checked)').each -> - if $(@).attr('id') isnt undefined - selected_charges.push($(@).attr('id')) - - location.href = '/list/delete/' + selected_charges - - $('#do_approval').click -> - selected_charges = [] - - $('#charge_list tr').filter(':has(:checkbox:checked)').each -> - if $(@).attr('id') isnt undefined - selected_charges.push($(@).attr('id')) - - location.href = '/list/approval/' + selected_charges - - $('#do_refuse').click -> - selected_charges = [] - - $('#charge_list tr').filter(':has(:checkbox:checked)').each -> - if $(@).attr('id') isnt undefined - selected_charges.push($(@).attr('id')) - - location.href = '/list/refuse/' + selected_charges - - $('#do_deposit').click -> - selected_charges = [] - - $('#charge_list tr').filter(':has(:checkbox:checked)').each -> - if $(@).attr('id') isnt undefined - selected_charges.push($(@).attr('id')) - - location.href = '/list/deposit/' + selected_charges - - $('#do_export').click -> - selected_charges = [] - - $('#charge_list tr').filter(':has(:checkbox:checked)').each -> - if $(@).attr('id') isnt undefined - selected_charges.push($(@).attr('id')) - - location.href = '/list/export/' + selected_charges - - $('#do_cancel').click -> + $('#head_checkobx').click -> + flag = $(@).is(':checked') + $(':checkbox').each -> + if flag then $(@).attr('checked', 'checked') + else $(@).removeAttr('checked') + + $('.btn').click -> + select_id = $(@).attr("id").substring(3) selected_charges = [] $('#charge_list tr').filter(':has(:checkbox:checked)').each -> if $(@).attr('id') isnt undefined selected_charges.push($(@).attr('id')) - - location.href = '/list/cancel/' + selected_charges - - window.prettyPrint and prettyPrint() - $('#start_date').datepicker - format: 'yyyy-mm-dd' + location.href = "/list/#{select_id}/#{selected_charges}" window.prettyPrint and prettyPrint() - $('#end_date').datepicker + $('#start_date, #end_date').datepicker format: 'yyyy-mm-dd' diff --git a/root/static/scripts/list.js b/root/static/scripts/list.js index 1385a7c..80911c6 100644 --- a/root/static/scripts/list.js +++ b/root/static/scripts/list.js @@ -2,86 +2,30 @@ (function() { $(function() { - $('#head_checkbox').click(function() { - var cb, cbs, i, _i, _len, _results; - cbs = $(":checkbox"); - _results = []; - for (i = _i = 0, _len = cbs.length; _i < _len; i = ++_i) { - cb = cbs[i]; - if (cbs[i].type === "checkbox") { - _results.push(cbs[i].checked = $(this).is(':checked')); + $('#head_checkobx').click(function() { + var flag; + flag = $(this).is(':checked'); + return $(':checkbox').each(function() { + if (flag) { + return $(this).attr('checked', 'checked'); } else { - _results.push(void 0); - } - } - return _results; - }); - $('#do_delete').click(function() { - var selected_charges; - selected_charges = []; - $('#charge_list tr').filter(':has(:checkbox:checked)').each(function() { - if ($(this).attr('id') !== void 0) { - return selected_charges.push($(this).attr('id')); + return $(this).removeAttr('checked'); } }); - return location.href = '/list/delete/' + selected_charges; }); - $('#do_approval').click(function() { - var selected_charges; + $('.btn').click(function() { + var select_id, selected_charges; + select_id = $(this).attr("id").substring(3); selected_charges = []; $('#charge_list tr').filter(':has(:checkbox:checked)').each(function() { if ($(this).attr('id') !== void 0) { return selected_charges.push($(this).attr('id')); } }); - return location.href = '/list/approval/' + selected_charges; - }); - $('#do_refuse').click(function() { - var selected_charges; - selected_charges = []; - $('#charge_list tr').filter(':has(:checkbox:checked)').each(function() { - if ($(this).attr('id') !== void 0) { - return selected_charges.push($(this).attr('id')); - } - }); - return location.href = '/list/refuse/' + selected_charges; - }); - $('#do_deposit').click(function() { - var selected_charges; - selected_charges = []; - $('#charge_list tr').filter(':has(:checkbox:checked)').each(function() { - if ($(this).attr('id') !== void 0) { - return selected_charges.push($(this).attr('id')); - } - }); - return location.href = '/list/deposit/' + selected_charges; - }); - $('#do_export').click(function() { - var selected_charges; - selected_charges = []; - $('#charge_list tr').filter(':has(:checkbox:checked)').each(function() { - if ($(this).attr('id') !== void 0) { - return selected_charges.push($(this).attr('id')); - } - }); - return location.href = '/list/export/' + selected_charges; - }); - $('#do_cancel').click(function() { - var selected_charges; - selected_charges = []; - $('#charge_list tr').filter(':has(:checkbox:checked)').each(function() { - if ($(this).attr('id') !== void 0) { - return selected_charges.push($(this).attr('id')); - } - }); - return location.href = '/list/cancel/' + selected_charges; - }); - window.prettyPrint && prettyPrint(); - $('#start_date').datepicker({ - format: 'yyyy-mm-dd' + return location.href = "/list/" + select_id + "/" + selected_charges; }); window.prettyPrint && prettyPrint(); - return $('#end_date').datepicker({ + return $('#start_date, #end_date').datepicker({ format: 'yyyy-mm-dd' }); });