Updates to the data tracking app; Updated the VAP list.
This commit is contained in:
@@ -25,6 +25,7 @@
|
||||
<th data-key-name="subcategory">Subcategory</th>
|
||||
<th data-key-name="defaultPrice">Default Price</th>
|
||||
<th data-key-name="measures">Measures</th>
|
||||
<th data-key-name="aliases">Aliases</th>
|
||||
</tr>
|
||||
</thead>
|
||||
</table>
|
||||
@@ -54,6 +55,12 @@
|
||||
<div class="form-group">
|
||||
<select class="js-states form-control" name="measures" id="DFMeasures" multiple="multiple" tabindex="0" style="width: 100%;" required></select>
|
||||
</div>
|
||||
<label for="DFNewAlias">Aliases</label>
|
||||
<div class="input-group">
|
||||
<input name="newAlias" id="DFNewAlias" type="text" class="form-control text" tabindex="0"><span class="input-group-btn"><button id="DFNewAliasAdd" class="btn" type="button">Add</button></span>
|
||||
</div>
|
||||
<div id="DFAliases" class="list-group" tabindex="0">
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button id="DFSave" type="button" class="btn btn-default btn-primary btn-md" tabindex="0">Save</button>
|
||||
@@ -127,9 +134,6 @@
|
||||
return map;
|
||||
}, {});
|
||||
|
||||
//Save the categories by id for use when setting the editor dialog's dropdown selection.
|
||||
categoriesById = byId;
|
||||
|
||||
return byId;
|
||||
}},
|
||||
{name: "subcategories", url: "data/Subcategory/readAll", parameters: {showDeleted: true}, postProcess: function(data) {
|
||||
@@ -141,9 +145,6 @@
|
||||
return map;
|
||||
}, {});
|
||||
|
||||
//Save the categories by id for use when setting the editor dialog's dropdown selection.
|
||||
subcategoriesById = byId;
|
||||
|
||||
return byId;
|
||||
}}
|
||||
],
|
||||
@@ -202,7 +203,10 @@
|
||||
var $editorDialog = $page.find('#editorDialog');
|
||||
var $deleteDialog = $page.find('#deleteDialog');
|
||||
var $editorForm = $editorDialog.find('form');
|
||||
var queries = [$.get("data/Category/readAll", {include: [{model: 'Subcategory', paranoid: true, as: 'subcategories'}], order: ['name', ['name']]}), $.get('data/Measure/readAll', {order: ['name']})];
|
||||
var queries = [
|
||||
$.get("data/Category/readAll", {request: JSON.stringify({paranoid: true, include: [{model: 'Subcategory', paranoid: true, as: 'subcategories'}], order: ['name', ['name']]})}),
|
||||
$.get('data/Measure/readAll', {request: JSON.stringify({paranoid: true, order: ['name']})})
|
||||
];
|
||||
|
||||
//Update the dialog drop downs when the queries finish.
|
||||
$.when.apply($, queries).then(function(query1, query2) {
|
||||
@@ -241,6 +245,14 @@
|
||||
// $('#createDialog form').find('*').on('focusout focus change input', function(event) {
|
||||
// console.log("Event [" + event.type + "] on " + event.target + (event.target.name ? "." + event.target.name : event.target.id ? "." + event.target.id : "") + "{" + event.target.classList + "}");
|
||||
// });
|
||||
|
||||
$editorForm.find('#DFMeasures').on('select2:select', function(event) {
|
||||
var $el = $(event.params.data.element);
|
||||
|
||||
$el.detach();
|
||||
$(this).append($el);
|
||||
$(this).trigger("change");
|
||||
})
|
||||
});
|
||||
|
||||
//Handle opening the create dialog.
|
||||
@@ -259,15 +271,28 @@
|
||||
$btnEdit.on("click", function(event) {
|
||||
//debugger;
|
||||
if(dataTable.getSelectedRow() != null) {
|
||||
var model = dataTable.getSelectedRow().data("model");
|
||||
|
||||
//Configure the dialog to edit an existing element.
|
||||
$editorDialog.find("#DFCreate, #DFCreatePlus").hide();
|
||||
$editorDialog.find("#DFSave").show();
|
||||
$editorDialog.find(".modal-title").text("Edit Item");
|
||||
//Reset fields to selected values.
|
||||
$editorDialog.find('#DFName').val(dataTable.getSelectedRow().data("model").name);
|
||||
$editorDialog.find('#DFSubcategory').val(dataTable.getSelectedRow().data("model").subcategoryId);
|
||||
$editorDialog.find('#DFPrice').val(dataTable.getSelectedRow().data("model").defaultPrice);
|
||||
$editorDialog.find('#DFMeasures').val(dataTable.getSelectedRow().data("model").measures);
|
||||
$editorDialog.find('#DFName').val(model.name);
|
||||
$editorDialog.find('#DFSubcategory').val(model.subcategoryId);
|
||||
$editorDialog.find('#DFPrice').val(model.defaultPrice);
|
||||
$editorDialog.find('#DFMeasures').val(model.measures);
|
||||
|
||||
if(model.aliases && model.aliases.length) {
|
||||
var $aliasesList = $editorDialog.find('DFAliases');
|
||||
|
||||
for(var a = 0; a < model.aliases.length; a++) {
|
||||
var alias = model.aliases[a];
|
||||
$aliasesList.append("<li>" + alias + "</li>");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//Open the dialog.
|
||||
$editorDialog.modal();
|
||||
}
|
||||
@@ -277,24 +302,17 @@
|
||||
var createFunction = function(close) {
|
||||
$editorForm.data('bs.validator').validate(function(isValid) {
|
||||
if(isValid) {
|
||||
try {
|
||||
$.post("data/Item/create", {
|
||||
name: $editorForm.find("#DFName").val(),
|
||||
subcategoryId: parseInt($editorForm.find("#DFSubcategory").val()),
|
||||
defaultPrice: $editorForm.find("#DFPrice").val(),
|
||||
measures: JSON.stringify($editorForm.find("#DFMeasures").val())
|
||||
}, function(data) {
|
||||
if(data.result == "success") {
|
||||
if(close) $editorDialog.modal("hide");
|
||||
dataTable.refresh();
|
||||
}
|
||||
else {
|
||||
alert(data.result);
|
||||
}
|
||||
}, "json");
|
||||
} catch(e) {
|
||||
alert(e);
|
||||
}
|
||||
$.ajax({url: "data/Item/create", type: "POST", dataType: "json", data: encodeData({
|
||||
name: $editorForm.find("#DFName").val(),
|
||||
subcategoryId: parseInt($editorForm.find("#DFSubcategory").val()),
|
||||
defaultPrice: $editorForm.find("#DFPrice").val(),
|
||||
measures: JSON.stringify($editorForm.find("#DFMeasures").val())
|
||||
})}).done(function(data) {
|
||||
if(close) $editorDialog.modal("hide");
|
||||
dataTable.refresh();
|
||||
}).fail(function(data) {
|
||||
alert("Server call failed.");
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
@@ -308,31 +326,82 @@
|
||||
$editorDialog.find('#DFSave').on('click', function(event) {
|
||||
$editorForm.data('bs.validator').validate(function(isValid) {
|
||||
if(isValid) {
|
||||
try {
|
||||
$.post("data/Item/edit", {
|
||||
id: dataTable.getSelectedRow().data("model").id,
|
||||
name: $editorForm.find("#DFName").val(),
|
||||
subcategoryId: parseInt($editorForm.find("#DFSubcategory").val()),
|
||||
defaultPrice: $editorForm.find("#DFPrice").val(),
|
||||
measures: JSON.stringify($editorForm.find("#DFMeasures").val())
|
||||
}, function(data) {
|
||||
if(data.result == "success") {
|
||||
$editorDialog.modal("hide");
|
||||
dataTable.refresh();
|
||||
}
|
||||
else {
|
||||
alert(data.result);
|
||||
}
|
||||
}, "json");
|
||||
} catch(e) {
|
||||
alert(e);
|
||||
}
|
||||
$.ajax({url: "data/Item/edit", type: "POST", dataType: "json", data: encodeData({
|
||||
id: dataTable.getSelectedRow().data("model").id,
|
||||
name: $editorForm.find("#DFName").val(),
|
||||
subcategoryId: parseInt($editorForm.find("#DFSubcategory").val()),
|
||||
defaultPrice: $editorForm.find("#DFPrice").val(),
|
||||
measures: JSON.stringify($editorForm.find("#DFMeasures").val())
|
||||
})}).done(function(data) {
|
||||
if(close) $editorDialog.modal("hide");
|
||||
dataTable.refresh();
|
||||
}).fail(function(data) {
|
||||
alert("Server call failed.");
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
$editorDialog.find('#DFCancel').on('click', function(event) {
|
||||
$editorDialog.modal('hide');
|
||||
});
|
||||
//Add a new alias to the alias list.
|
||||
$editorDialog.find('#DFNewAliasAdd').on('click', function(event) {
|
||||
//Add the text in the DFNewAlias input as an alias in the list.
|
||||
var $aliasInput = $editorDialog.find('#DFNewAlias');
|
||||
var text = $aliasInput.val();
|
||||
|
||||
if(text) text = text.trim();
|
||||
|
||||
if(text && text.length) {
|
||||
var $aliases = $editorDialog.find('#DFAliases');
|
||||
|
||||
$("<span>", {
|
||||
roll: 'button',
|
||||
tabindex: '0',
|
||||
text: text
|
||||
}).appendTo($aliases);
|
||||
|
||||
$aliasInput.val("");
|
||||
}
|
||||
|
||||
$editorDialog.find('#DFNewAlias').focus();
|
||||
});
|
||||
//When the alias list is focused, select the first alias if none was previously selected.
|
||||
$editorDialog.find('#DFAliases').on('focus', function(event) {
|
||||
var $selected = $(event.target).children('.selected');
|
||||
|
||||
//If there isn't a selected list element, then select the first.
|
||||
if(!$selected.length) {
|
||||
$(event.target).children(':first').addClass('selected');
|
||||
}
|
||||
});
|
||||
//Allow navigation of the selection with arrow keys, allow deletion with the delete key.
|
||||
$editorDialog.find('#DFAliases').on('keyup', function(event) {
|
||||
switch(event.keyCode) {
|
||||
case 46:
|
||||
var $selected = $(event.target).children('.selected');
|
||||
|
||||
$selected.prev().addClass('selected').siblings().removeClass('selected');
|
||||
$selected.remove();
|
||||
break;
|
||||
case 38:
|
||||
var $selected = $(event.target).children('.selected');
|
||||
var $nextSelected = $selected.length ? $selected.prev().length ? $selected.prev() : $(event.target).children(':last') : $(event.target).children(':first');
|
||||
|
||||
$nextSelected.addClass('selected').siblings().removeClass('selected');
|
||||
break;
|
||||
case 40:
|
||||
var $selected = $(event.target).children('.selected');
|
||||
var $nextSelected = $selected.length ? $selected.next().length ? $selected.next() : $(event.target).children(':first') : $(event.target).children(':first');
|
||||
|
||||
$nextSelected.addClass('selected').siblings().removeClass('selected');
|
||||
break;
|
||||
}
|
||||
});
|
||||
//Allow the user to click to select an alias.
|
||||
$editorDialog.find('#DFAliases').on('click', 'span', function(event) {
|
||||
$(event.target).addClass('selected').siblings().removeClass('selected');
|
||||
});
|
||||
//Set the initial focus control.
|
||||
$editorDialog.on('shown.bs.modal', function() {
|
||||
$editorDialog.find('#DFName').focus();
|
||||
@@ -352,15 +421,12 @@
|
||||
//Delete the element and close the dialog.
|
||||
$deleteDialog.find('#deleteButton').on("click", function(event) {
|
||||
if(dataTable.getSelectedRow() != null) {
|
||||
$.post("data/Item/delete", {where: {id: dataTable.getSelectedRow().data("model").id}}, function(data) {
|
||||
if(data.result == "success") {
|
||||
$deleteDialog.modal("hide");
|
||||
dataTable.refresh();
|
||||
}
|
||||
else {
|
||||
alert(data.result);
|
||||
}
|
||||
}, "json");
|
||||
$.ajax({url: "data/Item/delete", type: "POST", dataType: "json", data: encodeData({where: {id: dataTable.getSelectedRow().data("model").id}})}).done(function(data) {
|
||||
$deleteDialog.modal("hide");
|
||||
dataTable.refresh();
|
||||
}).fail(function(data) {
|
||||
alert("Server call failed.");
|
||||
});
|
||||
}
|
||||
});
|
||||
$deleteDialog.find('#DFCancelDelete').on('click', function(event) {
|
||||
|
||||
Reference in New Issue
Block a user