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