xCRUD v.1.7

Documentation and code examples for the new features


xCRUD - is a simple-usage but powerful Create-Read-Update-Delete application for php and MySQL.

Modal View


Forms can be display in modal view. The modals are draggable. The settings to enable or disable modal view is specific to each form.
By default forms are in normal mode where editign replaces the records list and on return, the list is displayed again
To display forms in Side View you need to define the following line anywhere in your form as shown below


     $xcrud->is_edit_modal(true);
     

Side View


Forms can be display in side view. This means the edit or add form is on the side. of the list. The settings to enable or disable side view is specific to each form.
By default forms are in normal mode where editing replaces the records list and on return the list is displayed again
You can manipulate the themes to specify where to load the edit form. If you are using the theme 'default' You will change 'xcrud/themes/default/xcrud_list_view.php'. You will then move the code section with the class "edit_side_panel".
To display forms in Side View you need to define the following line anywhere in your form as shown below


     $xcrud->is_edit_side(true);
     

Modal View


Tabulator is a powerfull script on its own and can be gotten from Tabulator Site
Xcrud has provided a mechanism to import and utilize some of the features in it. It has alot of features and xcrud 1.7 has utilized a couple of them
To enable tabulator you should follow the steps below


We might not exhaust all column properties but you can always cross reference in tabulator - column section

Credit goes to tabulator script!
.


Parsley JS is a powerfull script on its own and can be gotten from Parsley Site
Xcrud on its own has a strong inbuild validation tool as shown in version 1.6 documentation. It uses validation pattern i.e validation_pattern( field(s), pattren )
Now with parsley validation, xcrud is able to achieve validation in a better way. The benefits of parsley is


To enable parsley validations you should follow the steps below

 		  
$xcrud = Xcrud::get_instance();
$xcrud->table('employees');
$xcrud->set_attr('lastName',array('id'=>'user','data-role'=>'admin'));	
//Activate parslet validation
$xcrud->parsley_active(true);
//Ensure First Name is alpha numeric	
$xcrud->set_attr('firstName',array('data-parsley-trigger'=>'change','id'=>'user','data-parsley-type'=>'alphanum'));
//ensure valid email and display "Email not valid"
$xcrud->set_attr('email',array('data-parsley-trigger'=>'change','id'=>'user','data-parsley-type'=>'email','data-parsley-error-message'=>"Email not valid"));	
//ensure office Code is between 3 and 5 number characters
$xcrud->set_attr('officeCode',array('id'=>'user','data-parsley-type'=>'digits','data-parsley-length'=>"[3,5]"));	    
$xcrud->button('javascript:void(0);','My Title','icon-link','',array('target'=>'_blank'));
echo $xcrud->render();
	?>
Define Trigger
What triggers the validation . 'data-parsley-trigger'=>'change'

API Description
data-parsley-trigger="input" Specify one or many javascript events that will trigger item validation, before any failure. To set multiple events, separate them with a space data-parsley-trigger="focusin focusout". Default is null. See the various events supported by jQuery.
data-parsley-trigger-after-failure="focusout" Specify one or many javascript events that will trigger item validation, after the first failure. Default is 'input'.
data-parsley-no-focus If this field fails, do not focus on it (if first focus strategy is on, next field would be focused, if last strategy is on, previous field would be focused)
data-parsley-validation-threshold="10" Used with trigger option above, for all key- events, do not validate until the field has a certain number of characters. Default is 3
data-parsley-class-handler="#element" Specify the existing DOM container where ParsleyUI should add error and success classes. It is also possible to configure it with a callback function from javascript, see the annotated source.
data-parsley-errors-container="#element" Specify the existing DOM container where ParsleyUI should put the errors. It is also possible to configure it with a callback function from javascript, see the annotated source.
data-parsley-error-message="my message" Customize a unique global message for the field.
data-parsley-`constraint`-message="my message" Customize the error message for the field constraint. eg: data-parsley-required-message="this field is required"
Define Type
What Type is it . i.e 'data-parsley-type'=>'alphanum'
API Description
Required
required HTML5
data-parsley-required
data-parsley-required="true"
data-parsley-required="false"
Validates that a required field has been filled with a non blank value. If data-parsley-required="false", validator is deactivated and the field is not required.
Email
type="email" HTML5
data-parsley-type="email"
Validates that a value is a valid email address.
Number data-parsley-type="number" Validates that a value is a valid number according to the given step, min and original value.
The default step for HTML5 is "1", which is so counterintuive that Parsley uses a default step of "any" for data-parsley-type="number". Warning! HTML5 type="number" can be counterintuitive. The default step of '1' is near useless. Moreover, for browsers that support it, the value accessible from javascript in case of invalid input is "", so you will never get an error (unless it is also required).
Integer
type="number" HTML5
data-parsley-type="integer"
Validates that a value is a valid integer.
Digits data-parsley-type="digits" Validates that a value is only digits.
Alphanum data-parsley-type="alphanum" Validates that a value is a valid alphanumeric string.
Url
type="url" HTML5
data-parsley-type="url"
Validates that a value is a valid url.
Minlength
minlength="6" HTML5
data-parsley-minlength="6"
Validates that the length of a string is at least as long as the given limit.
Maxlength
maxlength="10" HTML5
data-parsley-maxlength="10"
Validates that the length of a string is not longer than the given limit.
Length data-parsley-length="[6, 10]" Validates that a given string length is between some minimum and maximum value.
Min
min="6" HTML5
data-parsley-min="6"
Validates that a given input (number or date) or date is greater than or equal to some minimum (number or date.)
Max
max="10" HTML5
data-parsley-max="10"
Validates that the given input (number or date) is less than or equal to some maximum value (number or date).
Range
type="range" HTML5
data-parsley-range="[6, 10]"
Validates that a given value (number or date) is between some minimum and maximum values (numbers or dates).
Pattern
pattern="\d+" HTML5
data-parsley-pattern="\d+"
Validates that a value matches a specific regular expression (regex).
Note that patterns are anchored, i.e. must match the whole string.
Parsley deviates from the standard for patterns looking like /pattern/{flag}; these are interpreted as literal regexp and are not anchored.
MinCheck data-parsley-mincheck="3" Validates that a certain minimum number of checkboxes in a group are checked.
MaxCheck data-parsley-maxcheck="3" Validates that a certain maximum number of checkboxes in a group are checked.
Check data-parsley-check="[1, 3]" Validates that the number of checked checkboxes in a group is within a certain range.
Equalto data-parsley-equalto="#anotherfield" Validates that the value is identical to another field's value (useful for password confirmation check).

We might not exhaust all column properties but you can always cross reference in tabulator - column section

Credit goes to tabulator script!
.

Bulk delete has been implemented so that a user is able to select multiple records and delete or update the records.
When activated the user is provided with the option to select the multiple records and delete or update the records.

To enable bulk selection & deletion the user needs to include the following line of code

 		  
      
       $xcrud->set_bulk_select(false);
	


A user can give a logic to the bulk deletion such that certain records will have the checkbox and others not. This is done by the following line of code
 		  
      
      $xcrud->set_bulk_select(false,'cd_key','=','EBGC57SXM-VW47I6AF-401X7DYM');
	
The above code states that bulk selection should not be available for the record with the cd_key that is 'EBGC57SXM-VW47I6AF-401X7DYM'. Lastly the user can implement what the bulk selection will do.

The javascript code below is called on the button click and deletes the selected list records.
 

    function deleteItems(){
        var r = confirm("Confirm deletion of " + items.length + " items.");
        if (r == true) {
          Xcrud.request('.xcrud-ajax',Xcrud.list_data('.xcrud-ajax',{action: 'bulk_delete', task:'action',selected:items,table:'million',identifier:'id'}))
          items = [];
        }       
    }

Inline editing is a powerfull feature that allows data to be edited from the list view by just clicking or double clicking the table cell and editing the data. The user needs to explicitly set the fields that they need to be able to edit through the inline method. To activate the fields for inline editing,the following code is used

 		  
   $xcrud->fields_inline('customerNumber');

You should include all the fields that you want to be able edit using the inline method.

Then you need to specify how those cells/columns become edited. There are two ways. Either through single click or double click

Single Click

With single click way, user has to click the cell once for it to become editable

 		  
   $xcrud->inline_edit_click('single_click');

Double Click

With double click way, user has to double click the cell to become editable

 		  
   $xcrud->inline_edit_click('double_click');

Toast Alerts provide a nice way of alerting the user without intrusion and discruption of the current activity. To use toast alerts in xCRUD you need to activate them from the config files. You also need to define which colors to show for either success or failure

You will ammend the following lines of code in the file 'xcrud/xcrud_config.php'.

 		      
    public static $load_toast = true; //loads the toast js
    public static $activate_toast_alerts = true; // activates toast alerts   
	public static $toast_success_color = '#1a5589'; //Sets the success color for toast message
	public static $toast_error_color = '#ff6666'; //Sets the fail color for the toast message	

After the lines above have been activated, all alerts will now be in the form of toast alerts. The default configuration of the toast alerts is to appear on the bottom right section of the screen for 10 seconds. This can be changed from xcrud.js file.

With this feature, you can now group fields in the form view. By grouping you are able place certain fields under a group.

To group fields you write the following code

 		     
   $xcrud->fields_arrange('firstName,lastName,extension,officeCode','Group 1-Names',true);	

To code above states the folowing. The first parameter specifies the fields to be included in the a group, So the fields 'firstName,lastName,extension,officeCode' will belong to the group 'Group 1-Names'. The second parameter specifies the group name which for our case is 'Group 1-Names' The third parameter is boolean which specifies whether to show or ommit the group name. If true, the group name is displayed.

The groups will appear in the sequence they are defined. If the $xcrud->fields_arrange is not defined, the form will have no grouping.

IMPORTANT!
You should not include a field in more than one group. If you do so it will appear in the last included group and rearrange the groups in a wrong order.

With this feature users are able to move to the next record or previous record when in form view either edit mode or view mode.

To activate the next and previous navigation in form view, the code will read as follows

 		      
    $xcrud->set_next_previous(true);	

With the above code, the next and previous buttons will be displayed on the form and the user will be able to navigate to the next or previous record

jQuery - http://jquery.com/

jQuery UI - http://jqueryui.com/

jQuery-Timepicker-Addon - https://github.com/trentrichardson/jQuery-Timepicker-Addon

PhpLetter - http://www.phpletter.com/Our-Projects/AjaxFileUpload/

Twitter Bootstrap - http://getbootstrap.com/

Icomoon - http://icomoon.io/

Tabulator - http://tabulator.info/

Parsley - https://parsleyjs.org/