.control-item-add - to trigger add item dialog
.control-item-edit - to trigger edit item dialog
.control-item-load - loads a piece of html to container
data-item-id - to specify item id to edit/load
data-form-url - to specify url to get add item form (to override default url if we have several forms)
data-form-action - to specify url that updates db on form submit (to override default url if we have several forms)
data-dialog-for - to specify what container at parent page will be updated. it works together with data-blockname
data-form-options="custom_buttons,return_to_dialog"
custom_buttons - to disable standart buttons in dialog
return_to_dialog - if we want to return to current dialog
redirect - redirect to url returned by submit ajax request.
Example
.control-updatable - container that will be updated
.control-updatable[-ID] - container with item id (in case we have several items at the page)
data-load-url - to specify where to get data
data-update-varname (OPTIONAL) - using this attribute we can get different pieces of data
data-blockname (OPTIONAL) - to specify which dialog updates the container
TODO rename data-load-url => data-update-url TODO rename content_type=>varname at server side
Init:
SiteControl.setOptions({
'edit_form_url' : '/news/edit.php', //return edit form
'add_form_url' : '/news/add.php', //return add form
'ajax_url' : '/news/ajax.controller.php', //handles db updating, html requesting
'multi' : true, //if we have list of editable items at the page. Use with .control-updatable-ID class
});
you have to specify urls for ajax calls
.control-submit-button
.control-cancel-button
Example of button
<button class="btn btn-primary control-submit-button" data-submit-next="/admin/profilepic.php" data-submit-control="current-window">Use Uploaded File </button>
data-submit-next - url to load INTO DIALOG after form data submited to server
data-submit-action - url to send form data (you can override form action attribute here)
data-submit-control - options for submit action:
-- current-window (says: do not current dialog)
-- confirm-action (you can use data-confirm-message="" to set message or assign object variable SiteControl.session.confirmActionMsg = "" )
-- skip-one (for submit-button or cancel button it allow to return back for 2 steps) (NEW FEATURE)
$('.modal-dialog').on('click', '.control-submit-button', function () {
var validator = $(".modal-body .form-horizontal").validate({
errorClass: 'error',
//hidden elements are validated now
ignore: [],
rules: {
companyname: {
required: true,
minlength: 3
},
validate_checkboxes: {
sections_selected: true
}
},
//this scrolls up to error position
focusInvalid: false,
invalidHandler: function (form, validator) {
if (!validator.numberOfInvalids())
return;
$('.modal-body').animate(
{scrollTop: $(validator.errorList[0].element).focus().top},
1000,
'swing',
function () {
$(validator.errorList[0].element).blur();
}
);
}
});
var result = validator.form();
if (result === false) {
SiteControl.validationFailed = true;
return;
} else {
SiteControl.validationFailed = false;
}
});
Example Old:
$("#sendNote").click( function() {
var company_id = $("#company_id").val();
var subject = $("#subject").val().trim();
if(subject == '') {$("#result").empty().append("<div class='alert alert-error'>Subject can't be empty.</div>"); SiteControl.validationFailed = true; return; }
SiteControl.validationFailed = false;
});
You can check all the data coming to server in Firefox Firebug Console (at least its easy to view there)
1) when modal dialog opens
$_GET[id] id of item passed if we open edit window
2) when updating containers with .control-updatable classes
$_POST['load'] = 1
$_POST['content_type'] stores value of data-update-varname="" attribute
3) when we submit form from bootsrap dialog window we just submit form data
<form action="/conflicts//save_conflict.php" .... <button data-submit-next="/conflicts//add_edit_conflict.php?added=1" data-submit-control="current-window" data-form-options="return_to_dialog" class="btn btn-primary control-submit-button">Save Conflict</button>When we click save, we check for duplicates at save_conflict.php, save state in session
<form action="/conflicts//save_conflict.php" .... <a data-submit-next="/conflicts//add_edit_conflict.php?added=1" data-submit-control="current-window" class="btn btn-primary control-submit-button" >Continue and Save</a> <button class="btn control-cancel-button">Cancel and Make Changes</button>If we click Continue, conflict is saved finally and warning state reseted. Now add_edit_conflict.php?added=1 returns success modal
<button class="btn control-cancel-button">Add Similar</button> <a href="#" class="btn control-cancel-button" data-submit-control="skip-restore" >Add New</a> <a href="#" class="btn control-cancel-button" data-submit-control="last-step" >Return To List</a>(there are highlighted options that modify .control-cancel-button behaviour)
<button class="btn control-cancel-button" data-submit-control="skip-one">Add Similar</button>