#29801 - Fix for broken Newsletter signup form action url.
[com.zyxware.civiwci.git] / templates / CRM / Wci / Form / CreateWidget.tpl
index e4046780fd4b75548d1531a7c69e5a18d4117ffc..c91646cd7f998cd19c9208c3a198a0520c61569e 100644 (file)
       $data = CRM_Wci_BAO_Widget::getWidgetData($wid_id);
       $template = CRM_Core_Smarty::singleton();
       $template->assign('wciform', $data);
-      $template->template_dir[] = getWciWidgetTemplatePath();
-      $wcidata = $template->fetch('wciwidget.tpl');
+      if($data["override"] == 0) {
+        $template->template_dir[] = getWciWidgetTemplatePath();
+        $wcidata = $template->fetch('wciwidget.tpl');
+      } else {
+        $wcidata = $template->fetch('string:' . base64_decode($wid_page[$dao->id]['custom_template']));
+      }
+      $widget_controller_path = getWciWidgetControllerPath();
     }
   {/php}
 
   <div class="crm-section">
+    <div class="label">
+      <label for="embd_code">Code to embed:</label>
+    </div>
     <div class="content">
-    {include file="CRM/Wci/Page/wciwidget.tpl"}
+      <div class="resizable-textarea">
+        <span>{literal}
+          <textarea name="embd_code" id="embd_code" class="form-textarea textarea-processed">
+<script type="text/javascript" src="{/literal}{php}echo $widget_controller_path;{/php}{literal}?widgetId={/literal}{php}echo $wid_id;{/php}{literal}"></script>
+<script type="text/javascript">
+// Cleanup functions for the document ready method
+if ( document.addEventListener ) {
+    DOMContentLoaded = function() {
+        document.removeEventListener( "DOMContentLoaded", DOMContentLoaded, false );
+        onReady();
+    };
+} else if ( document.attachEvent ) {
+    DOMContentLoaded = function() {
+        // Make sure body exists, at least, in case IE gets a little overzealous
+        if ( document.readyState === "complete" ) {
+            document.detachEvent( "onreadystatechange", DOMContentLoaded );
+            onReady();
+        }
+    };
+}
+if ( document.readyState === "complete" ) {
+    // Handle it asynchronously to allow scripts the opportunity to delay ready
+    setTimeout( onReady, 1 );
+}
+
+// Mozilla, Opera and webkit support this event
+if ( document.addEventListener ) {
+    // Use the handy event callback
+    document.addEventListener( "DOMContentLoaded", DOMContentLoaded, false );
+    // A fallback to window.onload, that will always work
+    window.addEventListener( "load", onReady, false );
+    // If IE event model is used
+} else if ( document.attachEvent ) {
+    // ensure firing before onload,
+    // maybe late but safe also for iframes
+    document.attachEvent("onreadystatechange", DOMContentLoaded);
+
+    // A fallback to window.onload, that will always work
+    window.attachEvent( "onload", onReady );
+}
+
+function onReady( ) {
+  document.getElementById('widgetwci').innerHTML = wciwidgetcode;
+}
+</script>
+<div id='widgetwci'></div></textarea>{/literal}
+          <div class="grippie" style="margin-right: 18px;"></div>
+        </span>
+      </div>
+    </div>
+    <div class="clear"></div>
+  </div>
+  <div class="crm-section">
+    <div class="content">
+   {* {include file="CRM/Wci/Page/wciwidget.tpl"} *}
+
+<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
+<script type="text/javascript" src="{php}echo $widget_controller_path;{/php}?widgetId={php}echo $wid_id;{/php}"></script>
+<script>
+  $( document ).ready(function()  {ldelim} 
+    $('#widgetwci').html(wciwidgetcode);
+   {rdelim} );
+</script>
+<div id='widgetwci'></div>
+
     </div>
   </div>
 {/if}