Skip to content

Commit

Permalink
support the facility to return additional unstructured field
Browse files Browse the repository at this point in the history
from a JSON endpoint in updateView
rename it from additionalFields to additionalData
  • Loading branch information
philippK-de committed May 24, 2017
1 parent 85aa750 commit 0d391d6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 19 deletions.
33 changes: 17 additions & 16 deletions include/js/viewManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function createView(myView) {
var myModel = {
items: [],
pages: [],
additionalFields: [],
additionalData: [],
limit: pagination.itemsPerPage,
offset: 0,
currentPage: 1,
Expand Down Expand Up @@ -64,8 +64,8 @@ function createView(myView) {
myModel.itemsCount = responseData.count;

//if the response has additional data fields, write em to the additionalFields field
if(responseData.additionalFields != undefined) {
myModel.additionalFields = responseData.additionalFields;
if (responseData.additionalData != undefined) {
myModel.additionalData = responseData.additionalData;
}
//get the list of pages and add it to the model
const pages = pagination.listPages(responseData.count);
Expand Down Expand Up @@ -103,7 +103,12 @@ function updateView(view, updateDependencies) {
var ajax = new ajaxRequest(myUrl, view.$el.id, function () {
//retrieve data and update the views model with it
const responseData = JSON.parse(ajax.request.responseText);
//update the items field with the regular list items
Vue.set(view, "items", responseData.items);
//if the response has additional data fields, write em to the additionalFields field
if (responseData.additionalData != undefined) {
Vue.set(view, "additionalData", responseData.additionalData);
}
Vue.set(view, "pages", pagination.listPages(responseData.count));

view.$emit("iloaded");
Expand Down Expand Up @@ -199,8 +204,8 @@ var pagination = {
}
this.loadPage(view, nextPage);
},
limitPagesDisplayed: function(page,pages){
return (page.index == 1 || page.index == 2) || (page.index ==pages.length / 2) || (currentPage == page.index) || (page.index== pages.length - 1) ||(page.index == pages.length );
limitPagesDisplayed: function (page, pages) {
return (page.index == 1 || page.index == 2) || (page.index == pages.length / 2) || (currentPage == page.index) || (page.index == pages.length - 1) || (page.index == pages.length );
}
};

Expand Down Expand Up @@ -233,19 +238,17 @@ function submitForm(event) {
var element = theForm.elements[i];
//construct post body
//if multiple is set, it is a select element that can have multiple selections
if(element.attributes.multiple != undefined)
{
if (element.attributes.multiple != undefined) {
var selectPostStr = "";
//loop over the options and assign the selected values to the post body
for(var j=0;j<element.options.length;j++)
{
for (var j = 0; j < element.options.length; j++) {
var option = element.options[j];
if(option.selected){
if (option.selected) {
selectPostStr += "&" + element.name + "=" + encodeURIComponent(option.value);
}
}
//if there were selected options, add to postBody
if(selectPostStr != ""){
if (selectPostStr != "") {
postBody += selectPostStr;
}
}
Expand All @@ -272,8 +275,7 @@ function submitForm(event) {
catch (e) {
}
}
else
{
else {
console.log(response);
}
});
Expand Down Expand Up @@ -324,8 +326,7 @@ function deleteElement(theElement, theUrl, theView) {
}
var result = true;
}
else
{
else {
console.log(ajax.request.responseText);
}
});
Expand Down Expand Up @@ -362,7 +363,7 @@ function removeRow(row, color) {
Velocity(rowElement, {
backgroundColor: color,
backgroundColorAlpha: 0.6,
colorAlpha:0.6
colorAlpha: 0.6
}, {
complete: function () {
Velocity(rowElement, "fadeOut", {
Expand Down
7 changes: 4 additions & 3 deletions include/js/viewManager.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0d391d6

Please sign in to comment.