Newer
Older
ubFramework / Portal / docroot / templates / admin / billing / voip_data.html
@Christopher W. Olsen Christopher W. Olsen on 10 Dec 2017 4 KB Cleaning Up Making It A Sub Module
<script>
  $(function() {
    var dialog, form,
 
      // From http://www.whatwg.org/specs/web-apps/current-work/multipage/states-of-the-type-attribute.html#e-mail-state-%28type=email%29
      emailRegex = /^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/,
      name = $( "#name" ),
      email = $( "#email" ),
      password = $( "#password" ),
      allFields = $( [] ).add( name ).add( email ).add( password ),
      tips = $( ".validateTips" );
 
    function updateTips( t ) {
      tips
        .text( t )
        .addClass( "ui-state-highlight" );
      setTimeout(function() {
        tips.removeClass( "ui-state-highlight", 1500 );
      }, 500 );
    }
 
    function checkLength( o, n, min, max ) {
      if ( o.val().length > max || o.val().length < min ) {
        o.addClass( "ui-state-error" );
        updateTips( "Length of " + n + " must be between " +
          min + " and " + max + "." );
        return false;
      } else {
        return true;
      }
    }
 
    function checkRegexp( o, regexp, n ) {
      if ( !( regexp.test( o.val() ) ) ) {
        o.addClass( "ui-state-error" );
        updateTips( n );
        return false;
      } else {
        return true;
      }
    }
 
    function addUser() {
      var valid = true;
      allFields.removeClass( "ui-state-error" );
 
      valid = valid && checkLength( name, "username", 3, 16 );
      valid = valid && checkLength( email, "email", 6, 80 );
      valid = valid && checkLength( password, "password", 5, 16 );
 
      valid = valid && checkRegexp( name, /^[a-z]([0-9a-z_\s])+$/i, "Username may consist of a-z, 0-9, underscores, spaces and must begin with a letter." );
      valid = valid && checkRegexp( email, emailRegex, "eg. ui@jquery.com" );
      valid = valid && checkRegexp( password, /^([0-9a-zA-Z])+$/, "Password field only allow : a-z 0-9" );
 
      if ( valid ) {
        $( "#users tbody" ).append( "<tr>" +
          "<td>" + name.val() + "</td>" +
          "<td>" + email.val() + "</td>" +
          "<td>" + password.val() + "</td>" +
        "</tr>" );
        dialog.dialog( "close" );
      }
      return valid;
    }
 
    dialog = $( "#dialog-form" ).dialog({
      autoOpen: false,
      height: 600,
      width: 650,
      modal: true,
      buttons: {
        "Create an account": addUser,
        Cancel: function() {
          dialog.dialog( "close" );
        }
      },
      close: function() {
        form[ 0 ].reset();
        allFields.removeClass( "ui-state-error" );
      }
    });
 
    form = dialog.find( "form" ).on( "submit", function( event ) {
      event.preventDefault();
      addUser();
    });
 
    $( "#add-plan-data" ).button().on( "click", function() {
      dialog.dialog( "open" );
    });
  });
</script>

<table id="pd">
<tr>
  <th style="width:80px;">Code</th>
  <th style="width:80px;">Type</th>
  <th style="width:400px;">Item</th>
  <th style="width:80px;">Unit</th>
  <th style="width:80px;">Cost</th>
</tr>
{ROWS}
</table>

<button id="add-plan-data">Add Plan Item</button>

<div id="dialog-form" title="New Plan Item">
  <p class="validateTips">All form fields are required.</p>
  <form>
    <fieldset>
      <label for="code">Code</label>
      <input type="text" name="data[pcode]" id="pcode" value="" class="text ui-widget-content ui-corner-all"><br />
      <label for="qty">Quantity</label>
      <input type="text" name="data[qty]" id="qty" value="" class="text ui-widget-content ui-corner-all"><br />
      <label for="punit">Unit</label>
      <select name="data[punit]"><option value="1">Account</option><option value="2">GB</option><option value="3">Domain</option><select><br />
      <label for="ptype">Unit</label>
      <select name="data[ptype]"><option value="0" selected>SDU</option><option value="1">E-Mail</option><option value="2">Hosting</option><option value="3">Security</option><option value="4">Backup</option><option value="5">Support</option><option value="6">Virtualization</option><option value="7">VoIP</option><option value="8">Misc</option></select><br />
      <label for="item">Item</label>
      <input type="text" name="data[item]" id="item" value="" class="text ui-widget-content ui-corner-all"><br />
      <label for="description">Descrption</label>
      <textarea name="data[description]" style="width:450px;height:100px;"></textarea><br />
      <label for="mrr">MRR</label>
      <input type="text" name="data[mrr]" id="mrr" value="" class="text ui-widget-content ui-corner-all"><br />
      <label for="otc">OTC</label>
      <input type="text" name="data[otc]" id="otc" value="" class="text ui-widget-content ui-corner-all"><br />
      
 
      <!-- Allow form submission with keyboard without duplicating the dialog button -->
      <input type="submit" tabindex="-1" style="position:absolute; top:-1000px">
    </fieldset>
  </form>
</div>