Beta 2 bug fixes. 31243. added agpl license and widget cache feature
[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++ ) {
b3e303a2 7 $('#' + "contribution_page_" + i).parent().parent().before('<div class="crm-wci-pb"><hr></div>');
a8c878ab
J
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 }
b3e303a2 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>');
a8c878ab 14 });
cde51233
J
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 }
e5812687 36 }
cde51233 37 });
e5812687 38
cde51233 39 $('#addmore_link').on('click', function( e ) {
b18480e2
J
40 e.preventDefault();
41 var count = parseInt($('input[name=contrib_count]').val());
42 count++;
43
e5812687 44 var c_page_sel = $('select[name=contribution_page_1]').clone().attr('id', "contribution_page_" + count);
b18480e2
J
45 c_page_sel.attr("name", "contribution_page_" + count);
46
47 var id_section = "crm-section-con-" + count;
b3e303a2 48 var sect_tag = "<div class=\"crm-section crm-wci-pb\" id=" + id_section + "><hr><div class=\"label\"><label>Contribution Page</label>";
b18480e2
J
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>');
c1a7ee1f 55 $('#' + id_section).append("</div>");
b18480e2
J
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 + ">");
e5812687 63 $('#' + id_content).append('<input type="text" size="20" id = percentage_'+ count + ' name="percentage_' + count +'" value="" />');
b18480e2 64 $('#' + id_section).append("</div");
e5812687
J
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 });
b18480e2
J
75
76 $('input[name=contrib_count]').val(count);
e5812687 77
cde51233 78 });
2bf0718d 79
53aa9e75 80 $(document).on('click', '#remove_link', function( e ) {
b18480e2
J
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] + "\"";
b18480e2
J
87 $('#crm-section-con-'+ rem_name_ar[1] +'').remove();
88 $('#crm-section-per-'+ rem_name_ar[1] +'').remove();
abcb1117
J
89 var count = parseInt($('input[name=contrib_count]').val());
90 count--;
91 $('input[name=contrib_count]').val(count);
2bf0718d 92 });
2bf0718d 93});