From 7d8ac5b7650dff7adafa0adf572dba12c139c78e Mon Sep 17 00:00:00 2001 From: Jagadedes Date: Thu, 16 Oct 2014 16:58:13 +0530 Subject: [PATCH] #29764 Widget embedding code, #29767 Widget preview in widget creation form., #29763 External widget controller. --- CRM/Wci/BAO/ProgressBar.php | 2 +- CRM/Wci/BAO/Widget.php | 1 + CRM/Wci/Form/CreateWidget.php | 29 +++- CRM/Wci/Form/ProgressBar.php | 2 +- extern/wciwidget.php | 2 +- templates/CRM/Wci/Form/CreateWidget.tpl | 21 +++ templates/CRM/Wci/Page/WidgetList.tpl | 93 ++++++++++++ templates/CRM/Wci/Page/wciwidget.tpl | 188 ++++++++++++++++++++++++ 8 files changed, 331 insertions(+), 7 deletions(-) create mode 100644 templates/CRM/Wci/Page/WidgetList.tpl create mode 100644 templates/CRM/Wci/Page/wciwidget.tpl diff --git a/CRM/Wci/BAO/ProgressBar.php b/CRM/Wci/BAO/ProgressBar.php index ff1a677..e07ee37 100644 --- a/CRM/Wci/BAO/ProgressBar.php +++ b/CRM/Wci/BAO/ProgressBar.php @@ -170,7 +170,7 @@ class CRM_Wci_BAO_ProgressBar extends CRM_Wci_DAO_ProgressBar { $sa = $con_page[$dao->id]['starting_amount']; $ga = $con_page[$dao->id]['goal_amount']; } - + $query = "SELECT * FROM civicrm_wci_progress_bar_formula WHERE progress_bar_id =" . $idPB; $params = array(); diff --git a/CRM/Wci/BAO/Widget.php b/CRM/Wci/BAO/Widget.php index a098a5c..bc84161 100644 --- a/CRM/Wci/BAO/Widget.php +++ b/CRM/Wci/BAO/Widget.php @@ -150,6 +150,7 @@ class CRM_Wci_BAO_Widget extends CRM_Wci_DAO_Widget { $data["color_border"] = $dao->color_border; $data["color_button"] = $dao->color_button; $data["color_button_bg"] = $dao->color_button_bg; + $data["pb_percentage"] = CRM_Wci_BAO_ProgressBar::getProgressbarPercentage($dao->progress_bar_id); } return $data; diff --git a/CRM/Wci/Form/CreateWidget.php b/CRM/Wci/Form/CreateWidget.php index c5a404f..aa40ab5 100644 --- a/CRM/Wci/Form/CreateWidget.php +++ b/CRM/Wci/Form/CreateWidget.php @@ -13,11 +13,23 @@ cj(function ( $ ) { } else { $('#custom_template').attr("disabled",true); - } + } + if( $('#title').val() != "") { + $('#embd_code').parent().parent().parent().show(); + } else { + $('#embd_code').parent().parent().parent().hide(); + } +// $('#embd_code').attr("disabled",true); } $(document).ready(setState) $('#override').click(setState); +/* + $("input[name='_qf_CreateWidget_savenprev']").on('click', function( e ) { + e.preventDefault(); + alert( document.title ); + + });*/ }); @@ -75,7 +87,7 @@ class CRM_Wci_Form_CreateWidget extends CRM_Core_Form { 'color_button' => array(ts('Widget button text color'), 'text', FALSE, - '#96C0E7', + '#000000', ), 'color_button_bg' => array(ts('Widget button background color'), 'text', @@ -124,18 +136,24 @@ class CRM_Wci_Form_CreateWidget extends CRM_Core_Form { $this->add('checkbox', 'override', ts('Override default template')); $this->add('textarea', 'custom_template', ts('Custom template:
Please customize the smarty v2 template only if you know what you are doing')); + $this->addElement('submit','preview','name="Save and Preview" id="preview"'); $this->addButtons(array( array( 'type' => 'submit', 'name' => ts('Save'), 'isDefault' => TRUE, ), + array( + 'type' => 'savenprev', + 'name' => ts('Save & Preview'), + ), )); - + + $this->add('textarea', 'embd_code', ts('Code to embed:')); + // export form elements $this->assign('elementNames', $this->getRenderableElementNames()); - $smarty = CRM_Core_Smarty::singleton(); if (isset($this->_id)) { /** Updating existing widget*/ @@ -195,6 +213,9 @@ where w.id=" . $this->_id; 'custom_template' => $cust_templ)); } } + $emb_code = " +"; + $this->getElement('embd_code')->setValue($emb_code); } else { /** Keep template in civicrm-wci/templates folder*/ diff --git a/CRM/Wci/Form/ProgressBar.php b/CRM/Wci/Form/ProgressBar.php index 012d6f5..0a453fe 100644 --- a/CRM/Wci/Form/ProgressBar.php +++ b/CRM/Wci/Form/ProgressBar.php @@ -14,7 +14,7 @@ class CRM_Wci_Form_ProgressBar extends CRM_Core_Form { private $_id; function preProcess() { $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this, FALSE, NULL, 'REQUEST'); - CRM_Core_Resources::singleton()->addScriptFile('org.civicrm.wci', 'addmore.js'); + CRM_Core_Resources::singleton()->addScriptFile('org.civicrm.wci', 'F3/sites/all/modules/civicrm/extensions/civicrm-wci/addmore.js'); parent::preProcess(); } function fillData() { diff --git a/extern/wciwidget.php b/extern/wciwidget.php index a96273b..9dcf43a 100644 --- a/extern/wciwidget.php +++ b/extern/wciwidget.php @@ -57,7 +57,7 @@ if (isset($embed) && (true == $embed)) { } else { $data = CRM_Wci_BAO_Widget::getWidgetData($widgetId); - $template->assign('form', $data); + $template->assign('wciform', $data); $template->template_dir[] = $_SERVER['DOCUMENT_ROOT'] . "/F3/sites/all/modules/civicrm/extensions/civicrm-wci/templates/CRM/Wci/Page"; $wcidata = $template->fetch('wciwidget.tpl'); diff --git a/templates/CRM/Wci/Form/CreateWidget.tpl b/templates/CRM/Wci/Form/CreateWidget.tpl index c99bb1f..1a4ca1b 100644 --- a/templates/CRM/Wci/Form/CreateWidget.tpl +++ b/templates/CRM/Wci/Form/CreateWidget.tpl @@ -14,6 +14,25 @@ {/foreach} +{if $form.title.value != ""} + {php} + if(isset($_REQUEST['id'])) { + $wid_id = $_REQUEST['id']; + $data = CRM_Wci_BAO_Widget::getWidgetData($wid_id); + $template = CRM_Core_Smarty::singleton(); + $template->assign('wciform', $data); + $template->template_dir[] = $_SERVER['DOCUMENT_ROOT'] . "/F3/sites/all/modules/civicrm/extensions/civicrm-wci/templates/CRM/Wci/Page"; + $wcidata = $template->fetch('wciwidget.tpl'); + } + {/php} + +
+
+ {include file="CRM/Wci/Page/wciwidget.tpl"} +
+
+{/if} + {* FIELD EXAMPLE: OPTION 2 (MANUAL LAYOUT)
@@ -22,6 +41,8 @@
{* FOOTER *} +
{include file="CRM/common/formButtons.tpl" location="bottom"}
+ diff --git a/templates/CRM/Wci/Page/WidgetList.tpl b/templates/CRM/Wci/Page/WidgetList.tpl new file mode 100644 index 0000000..e98724c --- /dev/null +++ b/templates/CRM/Wci/Page/WidgetList.tpl @@ -0,0 +1,93 @@ +{* +

This new page is generated by CRM/Wci/Page/WidgetList.php

+*} +{* Example: Display a variable directly +

The current time is {$currentTime}

+*} +{* Example: Display a translated string -- which happens to include a variable +

{ts 1=$currentTime}(In your native language) The current time is %1.{/ts}

+*} + + {if $rows} +
+ {strip} + + {include file="CRM/common/pager.tpl" location="top"} + {include file="CRM/common/pagerAToZ.tpl"} + {* handle enable/disable actions *} + {include file="CRM/common/enableDisable.tpl"} + {include file="CRM/common/jsortable.tpl"} + + + + + + {**} + {* + {if call_user_func(array('CRM_Campaign_BAO_Campaign','isCampaignEnable'))} + + {/if} *} + + + + {foreach from=$rows item=row} + {* class="{if NOT $row.is_active} disabled{/if}" *} + + +{* + {if call_user_func(array('CRM_Campaign_BAO_Campaign','isCampaignEnable'))} + + {/if} *} + + + + {/foreach} +
{ts}Title{/ts}{ts}Description{/ts}{ts}Enabled?{/ts}{ts}Campaign{/ts}
{$row.title}{$row.description}{if $row.is_active eq 1} {ts}Yes{/ts} {else} {ts}No{/ts} {/if}{$row.campaign} + + {if $row.configureActionLinks} +
+ {$row.configureActionLinks|replace:'xx':$row.id} +
+ {/if} + + {if $row.contributionLinks} +
+ {$row.contributionLinks|replace:'xx':$row.id} +
+ {/if} + + {if $row.onlineContributionLinks} +
+ {$row.onlineContributionLinks|replace:'xx':$row.id} +
+ {/if} + +
+ {$row.action|replace:'xx':$row.id} +
+ +
+ + {/strip} +
+ {else} + {if $isSearch eq 1} +
+ {ts}status{/ts} + {capture assign=browseURL}{crmURL p='civicrm/contribute/manage' q="reset=1"}{/capture} + {ts}No available Contribution Pages match your search criteria. Suggestions:{/ts} +
+ + {ts 1=$browseURL}Or you can browse all available Contribution Pages.{/ts} +
+ {else} +
+
  + {ts 1=$newPageURL}No contribution pages have been created yet. Click here to create a new contribution page.{/ts} +
+ {/if} + {/if} diff --git a/templates/CRM/Wci/Page/wciwidget.tpl b/templates/CRM/Wci/Page/wciwidget.tpl new file mode 100644 index 0000000..9bae716 --- /dev/null +++ b/templates/CRM/Wci/Page/wciwidget.tpl @@ -0,0 +1,188 @@ +{literal} + + + +{/literal} + +
+
+ {if $wciform.logo_image} + + {/if} + {$wciform.title} +
+
+
+
+
+
+
+
+
+
+
+
+ {$wciform.description} +
+
+
+ +
-- 2.25.1