fixed beta 1 bugs: 31069 divider between contrib pages. removed direct use of request var
[com.zyxware.civiwci.git] / addmore.js
1 // Updated to wait until the document is loaded. addmore_link
2
3 cj(function ( $ ) {
4 $(document).ready(function(){
5 var count = parseInt($('input[name=contrib_count]').val());
6 for ( var i = 2; i <= count; i++ ) {
7 $('#' + "contribution_page_" + i).parent().parent().before('<div class="crm-wci-pb"><hr></div>');
8 $('#' + "contribution_page_" + i).after(
9 '<a id=\"remove_link\" class=\"form-link\" href=\"remove\" name=\"remove_link-' + i + '\"> Remove</a>');
10 $('#' + "contribution_page_" + i).parent().parent().attr("id", "crm-section-con-" + i);
11 $('#' + "percentage_" + i).parent().parent().attr("id", 'crm-section-per-' + i);
12 }
13 $('#goal_amount').parent().after('<div class="crm-wci-pb"><hr></div><label><SMALL>Progressbar shows the sum of each percentage of contributions done on each selected contribution page</SMALL></label>');
14 });
15 $("#ProgressBar").validate({
16 rules: {
17 starting_amount: {
18 required: true,
19 number: true
20 },
21 progressbar_name: {
22 required: true
23 },
24 goal_amount: {
25 required: true,
26 number: true
27 },
28 contribution_page_1: {
29 required: true
30 },
31 percentage_1: {
32 required: true,
33 max: 100,
34 number: true
35 }
36 }
37 });
38
39 $('#addmore_link').on('click', function( e ) {
40 e.preventDefault();
41 var count = parseInt($('input[name=contrib_count]').val());
42 count++;
43
44 var c_page_sel = $('select[name=contribution_page_1]').clone().attr('id', "contribution_page_" + count);
45 c_page_sel.attr("name", "contribution_page_" + count);
46
47 var id_section = "crm-section-con-" + count;
48 var sect_tag = "<div class=\"crm-section crm-wci-pb\" id=" + id_section + "><hr><div class=\"label\"><label>Contribution Page</label>";
49 $('#addmore_link').parent().parent().before(sect_tag);
50
51 var id_content = "content_con-" + count;
52 $('#' + id_section).append("<div class=\"content\" id="+ id_content + ">");
53 $('#' + id_content).append(c_page_sel);
54 $('#' + id_content).append('<a id=\"remove_link\" class=\"form-link\" href=\"remove\" name=\"remove_link-' + count + '\"> Remove</a>');
55 $('#' + id_section).append("</div>");
56
57 id_section = "crm-section-per-" + count;
58 sect_tag = "<div class=\"crm-section\" id=" + id_section + "> <div class=\"label\"><label>Percentage</label>";
59 $('#addmore_link').parent().parent().before(sect_tag);
60
61 id_content = "content_per-" + count;
62 $('#' + id_section).append("<div class=\"content\" id="+ id_content + ">");
63 $('#' + id_content).append('<input type="text" size="20" id = percentage_'+ count + ' name="percentage_' + count +'" value="" />');
64 $('#' + id_section).append("</div");
65
66 $( "#contribution_page_" + count).rules( "add", {
67 required: true
68 });
69
70 $( "#percentage_" + count).rules( "add", {
71 required: true,
72 max: 100,
73 number: true
74 });
75
76 $('input[name=contrib_count]').val(count);
77
78 });
79
80 $(document).on('click', '#remove_link', function( e ) {
81 e.preventDefault();
82
83 var rem_name = e.target.name;
84 //assuming that - is the delimiter. second string will be the count
85 var rem_name_ar = rem_name.split('-');
86 var contri_page = "\"#percentage_" + rem_name_ar[1] + "\"";
87 $('#crm-section-con-'+ rem_name_ar[1] +'').remove();
88 $('#crm-section-per-'+ rem_name_ar[1] +'').remove();
89 var count = parseInt($('input[name=contrib_count]').val());
90 count--;
91 $('input[name=contrib_count]').val(count);
92 });
93 });