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