#30645 fixed No remove link in progressbar form
authorJagadedes <jagadees.pillai@zyxware.com>
Fri, 24 Oct 2014 09:52:59 +0000 (15:22 +0530)
committerJagadedes <jagadees.pillai@zyxware.com>
Fri, 24 Oct 2014 09:52:59 +0000 (15:22 +0530)
CRM/Wci/Form/CreateWidget.php
CRM/Wci/Form/ProgressBar.php
addmore.js

index 5bbfe458a9fce8d32227153b5ffb2cd699e36603..99aa05092a5f3a77b4b8150f2cb241f7dcd52154 100644 (file)
@@ -271,7 +271,7 @@ where w.id=" . $this->_id;
               $widget_id = CRM_Core_DAO::singleValueQuery('SELECT LAST_INSERT_ID()');
         CRM_Utils_System::redirect('?action=update&reset=1&id=' . $widget_id);
       } else {
-        CRM_Utils_System::redirect('widget?reset=1');#CRM_Utils_System::redirect('./?reset=1');
+        CRM_Utils_System::redirect('widget?reset=1');
       }
     }    
     catch (Exception $e) {
index 19fd5b197bd1c1070b8a2d37b5d46cb097fec68d..09217e0bad9048c16d1dc288fb4c2d19db092b97 100644 (file)
@@ -51,13 +51,13 @@ class CRM_Wci_Form_ProgressBar extends CRM_Core_Form {
           'contribution_page_'.$count, // field name
           'Contribution page', // field label
           getContributionPageOptions(), // list of options
-          true // is required
+          false // is required
         );
         $this->add(
           'text', // field type
           'percentage_'.$count, // field name
           'Percentage', // field label
-          true // is required
+          false // is required
         );
         //save formula id 
         $this->addElement('hidden', 'contrib_elem_'.$count , $for_page[$dao->id]['id']);
@@ -111,19 +111,6 @@ class CRM_Wci_Form_ProgressBar extends CRM_Core_Form {
       'Goal amount', // field label
       true // is required
     );
-/*    $this->add(
-      'select', // field type
-      'contribution_page_1', // field name
-      'Contribution page', // field label
-      getContributionPageOptions(), // list of options
-      true // is required
-    );
-    $this->add(
-      'text', // field type
-      'percentage_1', // field name
-      'Percentage', // field label
-      true // is required
-    );*/
     
     $this->fillData();
     
@@ -147,30 +134,28 @@ class CRM_Wci_Form_ProgressBar extends CRM_Core_Form {
     $errorScope = CRM_Core_TemporaryErrorScope::useException();
     if (isset($this->_id)) {
       try {
+        $transaction = new CRM_Core_Transaction();
+        
         $sql = "UPDATE civicrm_wci_progress_bar SET name = '". $_REQUEST['progressbar_name'] . 
           "', starting_amount = '" . $_REQUEST['starting_amount'] . 
           "', goal_amount = '" . $_REQUEST['goal_amount'] . 
           "' where id =".$this->_id;
 
-        $transaction = new CRM_Core_Transaction();
         CRM_Core_DAO::executeQuery($sql);
-
-        for($i = 1; $i <= (int)$_REQUEST['contrib_count']; $i++):
+        /** Delete existiing formula fields and add fields fresh*/
+        CRM_Core_DAO::executeQuery('DELETE FROM civicrm_wci_progress_bar_formula WHERE progress_bar_id=' . $this->_id);
+        
+        for($i = 1; $i <= (int)$_REQUEST['contrib_count']; $i++) {
           $page = 'contribution_page_' . (string)$i;
           $perc = 'percentage_' . (string)$i;
-          if (isset($_REQUEST['contrib_elem_'.$i])) {
-            $sql = "UPDATE civicrm_wci_progress_bar_formula SET contribution_page_id = '". $_REQUEST[$page] . "',
-              percentage = '". $_REQUEST[$perc] . "'
-              WHERE id = " . (int)$_REQUEST['contrib_elem_'.$i];
-          } 
-          else {
-            $sql = "INSERT INTO civicrm_wci_progress_bar_formula (contribution_page_id, progress_bar_id, percentage) 
+          $sql = "INSERT INTO civicrm_wci_progress_bar_formula (contribution_page_id, progress_bar_id, percentage) 
               VALUES ('" . $_REQUEST[$page] . "','" . $this->_id . "','" . $_REQUEST[$perc] . "')";
-          }
 
           CRM_Core_DAO::executeQuery($sql);
-        endfor;
+        }
+        
         $transaction->commit();
+
         CRM_Utils_System::redirect('progress-bar?reset=1');
       }
       catch (Exception $e) {
index afb31d2976b058384100d08d13b1d8f0d9e3b253..ae871b60f879b8fd891ae24e9ac48ac912b344d9 100644 (file)
@@ -1,7 +1,15 @@
 // Updated to wait until the document is loaded. addmore_link
 
 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);
+    }
+  });
   $("#ProgressBar").validate({
     rules: {
       starting_amount: {
@@ -74,7 +82,6 @@ cj(function ( $ ) {
     //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());