Commit ede0b638 authored by Rafael Ostertag's avatar Rafael Ostertag
Browse files

Support for refreshing/reconfiguring form elements added.

parent e4ec6811
......@@ -74,6 +74,10 @@ if (!QfqNS) {
.fail(this.submitFailureHandler.bind(this));
};
n.Form.prototype.serialize = function () {
return this.$form.serialize();
};
/**
*
* @param data
......
......@@ -11,10 +11,11 @@ if (!QfqNS) {
(function (n) {
'use strict';
n.QfqForm = function (formId, submitTo, deleteUrl) {
n.QfqForm = function (formId, submitTo, deleteUrl, dataRefreshUrl) {
this.formId = formId;
this.submitTo = submitTo;
this.deleteUrl = deleteUrl;
this.dataRefreshUrl = dataRefreshUrl;
this.form = new n.Form(this.formId);
this.bsTabs = null;
this.lastButtonPress = null;
......@@ -31,6 +32,8 @@ if (!QfqNS) {
this.getCloseButton().click(this.handleCloseClick.bind(this));
this.getNewButton().click(this.handleNewClick.bind(this));
this.getDeleteButton().click(this.handleDeleteClick.bind(this));
this.setupRefreshHandler();
};
n.QfqForm.prototype.setBsTabs = function (bsTabs) {
......@@ -58,6 +61,23 @@ if (!QfqNS) {
}
};
n.QfqForm.prototype.setupRefreshHandler = function () {
$('input[data-load]').on('change', this.refreshHandler.bind(this));
};
n.QfqForm.prototype.refreshHandler = function () {
var that = this;
$.post(this.dataRefreshUrl, this.form.serialize(), "json")
.fail(function (jqXHR, textStatus, errorThrown) {
var alert = new QfqNS.Alert("Error:<br>" + errorThrown, "error");
alert.show();
})
.done(function (data) {
this.applyElementConfiguration(data);
}.bind(that));
};
/**
* @private
*/
......
{
"text": {
"value": "value. Now its enabled",
"disabled": false,
"readonly": true
},
"select": {
"value": [
{
"value": 100,
"text": "a",
"selected": true
},
{
"value": 200,
"text": "b",
"selected": false
}
]
},
"radio": {
"value": "a",
"disabled": false
},
"checkbox": {
"value": true,
"readonly": true
},
"trigger": {
"value": false
}
}
\ No newline at end of file
......@@ -133,6 +133,25 @@
</div>
</div>
<div class="form-group">
<div class="col-md-2">
<b class="control-label">
Data reload trigger
</b>
</div>
<div class="col-md-6">
<div class="checkbox">
<label>
<input type="checkbox" id="checkbox2" name="trigger" data-load="">
</label>
<p class="help-block">
Changing the value of this checkbox triggers reload
</p>
</div>
</div>
</div>
</form>
</div>
......@@ -143,7 +162,7 @@
<script src="../js/qfq.debug.js"></script>
<script type="text/javascript">
$(function () {
var form = new QfqNS.QfqForm("myForm", 'none', 'none');
var form = new QfqNS.QfqForm("myForm", 'none', 'none', 'api/form_refresh.json');
QfqNS.Log.level = 0;
$("#applyconfig").click(function () {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment