// Updated to wait until the document is loaded. addmore_link
-jQuery(document).ready(function () {
-// var text = jQuery('h1').text();
-// alert(text);
-
-});
-
cj(function ( $ ) {
+ $(document).ready(function(){
+ var count = parseInt($('input[name=contrib_count]').val());
+ for ( var i = 2; i <= count; i++ ) {
+ $('#' + "contribution_page_" + i).after(
+ '<a id=\"remove_link\" class=\"form-link\" href=\"remove\" name=\"remove_link-' + i + '\"> Remove</a>');
+ $('#' + "contribution_page_" + i).parent().parent().attr("id", "crm-section-con-" + i);
+ $('#' + "percentage_" + i).parent().parent().attr("id", 'crm-section-per-' + i);
+ }
+ $('#percentage_1').after('<label><br><SMALL>Progressbar shows the sum of each percentage of contributions done on each selected contribution page</SMALL></label>');
+ });
+ $("#ProgressBar").validate({
+ rules: {
+ starting_amount: {
+ required: true,
+ number: true
+ },
+ progressbar_name: {
+ required: true
+ },
+ goal_amount: {
+ required: true,
+ number: true
+ },
+ contribution_page_1: {
+ required: true
+ },
+ percentage_1: {
+ required: true,
+ max: 100,
+ number: true
+ }
+ }
+ });
+
+ $('#addmore_link').on('click', function( e ) {
+ e.preventDefault();
+ var count = parseInt($('input[name=contrib_count]').val());
+ count++;
-// var text = jQuery('h1').text();
-// alert(text);
+ var c_page_sel = $('select[name=contribution_page_1]').clone().attr('id', "contribution_page_" + count);
+ c_page_sel.attr("name", "contribution_page_" + count);
- $('#addmore_link').on('click', function( e ) {
- e.preventDefault();
-// $('#addmore_link').click(function () {
- var count = parseInt($('input[name=contrib_count]').val());
- count++;
-
- //$('#myDiv').append('<input type="text" id="p_scnt" size="20" name="p_scnt_' + count +'" value="" placeholder="Input Value" /><br>');
+ var id_section = "crm-section-con-" + count;
+ var sect_tag = "<div class=\"crm-section\" id=" + id_section + "> <hr width='50%' size='1'> <div class=\"label\"><label>Contribution Page</label>";
+ $('#addmore_link').parent().parent().before(sect_tag);
- //$('#myDiv').append('<select id=\"selectId\" name=\"selectName\" />');
-// $('select[name=contribution_page_1]').parent('div').append('<select name="selectName" />');
-// var contr_name = "contribution_page_" + count.toString();
- //$('input[name=percentage_1]').parent('div').parent('div').parent('div').append('<label>Contribution page</label>');
-// $('#crm-container').append('<label>Contribution page</label>');
-
- var c_page = $('select[name=contribution_page_1]').clone().attr('id', 'choices_' + $(this).index());
- c_page.attr("id", "contribution_page_" + count);
- c_page.attr("name", "contribution_page_" + count);
- //.insertAfter("select[name=contribution_page_1]");
+ var id_content = "content_con-" + count;
+ $('#' + id_section).append("<div class=\"content\" id="+ id_content + ">");
+ $('#' + id_content).append(c_page_sel);
+ $('#' + id_content).append('<a id=\"remove_link\" class=\"form-link\" href=\"remove\" name=\"remove_link-' + count + '\"> Remove</a>');
+ $('#' + id_section).append("</div>");
+ id_section = "crm-section-per-" + count;
+ sect_tag = "<div class=\"crm-section\" id=" + id_section + "> <div class=\"label\"><label>Percentage</label>";
+ $('#addmore_link').parent().parent().before(sect_tag);
- $('input[name=percentage_1]').parent().parent().append("<br>")
- $('input[name=percentage_1]').parent().parent().append(c_page);
-// $('input[name=percentage_1]').parent('div').append('<br><select name="contribution_page_' + count +'" />');
+ id_content = "content_per-" + count;
+ $('#' + id_section).append("<div class=\"content\" id="+ id_content + ">");
+ $('#' + id_content).append('<input type="text" size="20" id = percentage_'+ count + ' name="percentage_' + count +'" value="" />');
+ $('#' + id_section).append("</div");
- $('input[name=percentage_1]').parent().parent().append('<br><input type="text" size="20" name="percentage_' + count +'" value="" />');
-// $('input[name=contribution_page_' + count + ']').text($('input[name=contribution_page_1]').text());
-
- $('input[name=percentage_1]').parent().parent().append('<a id="#remove_link" href="test" > Remove</a>');
-
- $('input[name=contrib_count]').val(count);
- alert(count);
- //alert(contr_sel);
- //alert($('input[name=contrib_count]').val());
- //alert($('select[name=contribution_page]').val());
- //alert($("select[name=contribution_page] option:selected").text());
- //alert($("#count").val());
- //$('select[name=contribution_page]').
-
-
+ $( "#contribution_page_" + count).rules( "add", {
+ required: true
+ });
+
+ $( "#percentage_" + count).rules( "add", {
+ required: true,
+ max: 100,
+ number: true
+ });
+
+ $('input[name=contrib_count]').val(count);
+
});
- $('#remove_link').on('click', function( e ) {
+ $(document).on('click', '#remove_link', function( e ) {
e.preventDefault();
- alert("hi");
- })
-/*
- $(function() {
- var scntDiv = $('#p_scents');
- var i = $('#p_scents p').size() + 1;
-
- $('#addmore_link').live('click', function() {
- $('<p><label for="p_scnts"><input type="text" id="p_scnt" size="20" name="p_scnt_' + i +'" value="" placeholder="Input Value" /></label> <a href="#" id="remScnt">Remove</a></p>').appendTo(scntDiv);
- i++;
- return false;
- });
- */
-
+
+ var rem_name = e.target.name;
+ //assuming that - is the delimiter. second string will be the count
+ var rem_name_ar = rem_name.split('-');
+ var contri_page = "\"#percentage_" + rem_name_ar[1] + "\"";
+ $('#crm-section-con-'+ rem_name_ar[1] +'').remove();
+ $('#crm-section-per-'+ rem_name_ar[1] +'').remove();
+ var count = parseInt($('input[name=contrib_count]').val());
+ count--;
+ $('input[name=contrib_count]').val(count);
+ });
});