Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add Cycle applet

  • Loading branch information...
commit 7e3cfddae5adad9bbdce387dcc011cb4a6e8bd3b 1 parent f2cb20e
Chad Smith authored
1  .gitignore
View
@@ -0,0 +1 @@
+*~
4 README.md
View
@@ -1,6 +1,6 @@
# A/B Split for OpenVBX
-This plugin selects the next applet in a Flow at random.
+This plugin selects the next applet in a Flow at random (Split) or by cycling through a list of applets (Cycle).
## Installation
@@ -10,5 +10,5 @@ This plugin selects the next applet in a Flow at random.
## Usage
-1. Add the Split applet to your Call or SMS flow
+1. Add the Split or Cycle applet to your Call or SMS flow
2. Add two or more applets as possible next actions and one will be selected at random
5 applets/cycle/applet.json
View
@@ -0,0 +1,5 @@
+{
+ "name" : "Cycle",
+ "description" : "Select the next applet on the list.",
+ "type" : ["voice", "sms"]
+}
BIN  applets/cycle/icon.png
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 applets/cycle/script.js
View
@@ -0,0 +1,37 @@
+$(document).ready(function() {
+ $('.cycle-applet .action.add').live('click', function(event) {
+ event.preventDefault();
+ var row = $(this).closest('tr');
+ var newRow = $('tfoot tr', $(this).parents('.cycle-applet')).html();
+ newRow = $('<tr>' + newRow + '</tr>')
+ .show()
+ .insertAfter(row);
+ $('.flowline-item').droppable(Flows.events.drop.options);
+ $('td', newRow).flicker();
+ $('.flowline-item input', newRow).attr('name', 'choices[]');
+ $(event.target).parents('.options-table').trigger('change');
+ return false;
+ });
+
+ $('.cycle-applet .action.remove').live('click', function() {
+ var row = $(this).closest('tr');
+ var bgColor = row.css('background-color');
+ row.animate(
+ {
+ backgroundColor : '#FEEEBD'
+ },
+ 'fast')
+ .fadeOut('fast', function() {
+ row.remove();
+ });
+
+ return false;
+ });
+
+ $('.cycle-applet .options-table').live('change', function() {
+ var first = $('tbody tr', this).first();
+ $('.action.remove', first).hide();
+ });
+
+ $('.cycle-applet .options-table').trigger('change');
+});
19 applets/cycle/twiml.php
View
@@ -0,0 +1,19 @@
+<?php
+$choices = (array) AppletInstance::getDropZoneUrl('choices[]');
+$instanceId = AppletInstance::getInstanceId();
+$position = intval(PluginData::get($instanceId));
+
+array_filter($choices);
+
+if(!$choices[$position])
+ $position = 0;
+
+$next = $choices[$position];
+$response = new TwimlResponse;
+
+PluginData::set($instanceId, ++$position);
+
+if(!empty($next))
+ $response->redirect($next);
+
+$response->respond();
36 applets/cycle/ui.php
View
@@ -0,0 +1,36 @@
+<?php
+$defaultNumberOfChoices = 2;
+$choices = AppletInstance::getValue('choices[]', array('', ''));
+?>
+<div class="vbx-applet cycle-applet">
+ <table class="vbx-menu-grid options-table">
+ <thead>
+ <tr>
+ <td>Applet</td>
+ <td>Add &amp; Remove</td>
+ </tr>
+ </thead>
+ <tfoot>
+ <tr class="hide">
+ <td>
+ <?php echo AppletUI::dropZone('new-choices[]', 'Drop applet here'); ?>
+ </td>
+ <td>
+ <a href="" class="add action"><span class="replace">Add</span></a> <a href="" class="remove action"><span class="replace">Remove</span></a>
+ </td>
+ </tr>
+ </tfoot>
+ <tbody>
+ <?php foreach($choices as $id => $choice): ?>
+ <tr>
+ <td>
+ <?php echo AppletUI::dropZone('choices['.($id).']', 'Drop applet here'); ?>
+ </td>
+ <td>
+ <a href="" class="add action"><span class="replace">Add</span></a> <a href="" class="remove action"><span class="replace">Remove</span></a>
+ </td>
+ </tr>
+ <?php endforeach; ?>
+ </tbody>
+ </table><!-- .vbx-menu-grid -->
+</div><!-- .vbx-applet -->
6 plugin.json
View
@@ -1,6 +1,6 @@
{
- "name" : "A/B Split",
+ "name" : "Split and Cycle ",
"author" : "Chad Smith <chad@nospam.me>",
- "description" : "Select the next applet at random.",
+ "description" : "Select the next applet at random or by cycling through a list.",
"url" : "http://twitter.com/chadsmith"
-}
+}
Please sign in to comment.
Something went wrong with that request. Please try again.