💎 PREMIUM: Changeset/ - Complete Album!

Changeset 885570


Ignore:
Timestamp:
04/01/2014 11:29:59 AM (12 years ago)
Author:
aniketpant
Message:

Add tab for generating shortcodes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • instamojo/trunk/option.php

    r884544 r885570  
    2828  }
    2929
     30  public function admin_tabs()
     31  {
     32    $current = isset($_GET['tab']) ? $_GET['tab'] : 'homepage';
     33
     34    $tabs = array(
     35      'homepage'    => 'Instamojo Credentials',
     36      'shortcode'   => 'Shortcodes'
     37    );
     38    ?>
     39    <h2><?php _e('Instamojo Options') ?></h2>
     40    <h3 class="nav-tab-wrapper">
     41    <?php
     42    foreach ($tabs as $tab => $name)
     43    {
     44      $class = ($tab == $current) ? ' nav-tab-active' : '';
     45      ?>
     46      <a class="nav-tab<?php echo $class; ?>" href="?page=instamojo&tab=<?php echo $tab; ?>"><?php _e($name); ?></a>
     47    <?php
     48    }
     49    ?>
     50    </h3>
     51    <?php
     52  }
     53
    3054  public function create_admin_page()
    3155  {
     56    $tab = isset($_GET['tab']) ? $_GET['tab'] : 'homepage';
     57
    3258    $this->_options = get_option('instamojo_credentials');
    3359    $auth_token = $this->_options['auth_token'];
     
    7399    ?>
    74100    <div class="wrap">
    75       <h2><?php _e('Instamojo Options'); ?></h2>
    76 
     101      <?php $this->admin_tabs(); ?>
     102      <?php
     103      switch ($tab)
     104      {
     105        case 'homepage':
     106      ?>
    77107      <h3><?php _e('Instamojo Credentials'); ?></h3>
    78108      <form method="post" action="" id="instamojo-conf">
     
    108138        </p>
    109139      </form>
     140      <?php
     141          break;
     142
     143        case 'shortcode':
     144          // Create Instamojo instance for interacting with API
     145          $instamojo = new Instamojo(APPLICATION_ID);
     146          $instamojo->setAuthToken($auth_token);
     147          $offerObject = $instamojo->listAllOffers();
     148          $offers = $offerObject['offers'];
     149      ?>
     150      <form method="" action="" id="instamojo-shortcode-generate">
     151        <table class="form-table">
     152          <tbody>
     153            <tr>
     154              <th>
     155                <label for="instamojo_offer"><?php _e('Instamojo Offer'); ?></label>
     156              </th>
     157              <td>
     158                <select id="instamojo_offer" name="instamojo-offer">
     159                  <option value="none" selected="selected">None</option>
     160                <?php
     161                  foreach ($offers as $offer) {
     162                ?>
     163                  <option value="<?php echo $offer['slug']; ?>"><?php echo $offer['title']; ?></option>
     164                <?php
     165                  }
     166                ?>
     167                </select>
     168              </td>
     169            </tr>
     170            <tr>
     171              <th>
     172                <label for="instamojo_style"><?php _e('Button Style'); ?></label>
     173              </th>
     174              <td>
     175                <select id="instamojo_style" name="button-style">
     176                  <option value="none" selected="selected">None</option>
     177                  <option value="light">Light</option>
     178                  <option value="dark">Dark</option>
     179                  <option value="flat">Flat Light</option>
     180                  <option value="flat-dark">Flat Dark</option>
     181                </select>
     182              </td>
     183            </tr>
     184            <tr>
     185              <th>
     186                <label for="instamojo_text"><?php _e('Button Text'); ?></label>
     187              </th>
     188              <td>
     189                <input type="text" id="instamojo_text" name="button-text" value="Checkout with Instamojo" />
     190              </td>
     191            </tr>
     192            <tr>
     193              <th>
     194                <label for="instamojo_shortcode_output"><?php _e('Shortcode'); ?></label>
     195              </th>
     196              <td>
     197                <textarea id="generatedShortcode" contenteditable></textarea>
     198              </td>
     199            </tr>
     200          </tbody>
     201        </table>
     202      </form>
     203      <script type="text/javascript">
     204        jQuery(document).ready(function() {
     205          generateShortcode();
     206
     207          jQuery('#instamojo_offer, #instamojo_style, #instamojo_text').change(function() {
     208            generateShortcode();
     209          });
     210
     211          function generateShortcode() {
     212            var $form = jQuery('#instamojo-shortcode-generate');
     213            var offer = $form.find('#instamojo_offer').val();
     214            var style = $form.find('#instamojo_style').val();
     215            var text = $form.find('#instamojo_text').val();
     216
     217            var output = '[instamojo';
     218
     219            if (offer !== 'none') {
     220              output = output + ' offer="' + offer + '"';
     221            }
     222
     223            output = output + ' style="' + style + '"';
     224
     225            output = output + ' text="' + text + '"';
     226
     227            output = output + ']';
     228
     229            jQuery('#generatedShortcode').text(output);
     230          }
     231        });
     232      </script>
     233      <?php
     234          break;
     235
     236        default:
     237          break;
     238      }
     239      ?>
    110240    </div>
    111241    <?php
Note: See TracChangeset for help on using the changeset viewer.