Upon page load, I'm trying to use the JavaScript function below to look in a SharePoint list to see if there are any requests for which the current user is the manager, and if so, allow them to approve or reject these requests.
//Logic to approve events if the current user is a manager.
function promptToApproveEvents(){
var hostUrl = decodeURIComponent(getQueryStringParameter("SPHostUrl"));
var hostContext = new SP.AppContextSite(currentContext, hostUrl);
var hostweb = hostContext.get_web();
var list = hostweb.get_lists().getByTitle(paidTimeOffListName);
//A caml query to get records where manager is equal to current user.
var queryXml = "<View><Query><Where><Eq><FieldRef Name='Manager' /><Value Type='Integer'><UserID /></Value></Eq></Where></Query></View>"
var query = new SP.CamlQuery();
query.set_viewXml(queryXml);
var items = list.getItems(query);
currentContext.load(items);
currentContext.executeQueryAsync(
function() //on success.
{
for(var i = 0;i < items.get_count();i++) {
var item = items.getItemAtIndex(i);
//Is the item we're looking at in need of approval?
if (item.get_item("Approved") === false)
{
//Yes, prompt for approval.
//$('#approvalModal').modal('show'); //modals don't seem to work in loops.
confirm("here's something in need of approval.");
}
else
{
//No, do nothing.
alert("skip it, it doesn't need approved.");
}
}
},
function(sender,args){
alert("Failed to get manager's name. Make sure your Organization Contacts list is filled out! Error: " + args.get_message()); //On fail
});
}
My issue is that I thought I'd be able to use a bootstrap modal to prompt the user for input for every unapproved request. For example, give them some info about the request then they can decide to click an accept or reject button to pass judgement using a prompt like the mock-up below. Once they've made a decision about this request, I'll run a bit of code to record their decision on this request, and then they should be prompted about the next request, until the for loop exits.
_________________________________________________________
| Hey boss. What to you think of this request? |
| Name: xx |
| Reason: xx |
| Other info: xx |
| |
| [ACCEPT] [REJECT] |
|_______________________________________________________|
Unfortunately, only one bootstrap modal pops up, and it shows up after the for loop is finished--which doesn't fit the desired behavior of a prompt for each matching item found.
I'm basically not sure what would be the best method to accomplish this. It seems like alert and confirm boxes "pause" execution like I want, and behave as desired. (For example if I have 2 unapproved requests and 1 approved, the code above pops up two "confirm" boxes and an "alert," as expected.) But their styling won't fit with the rest of my application at all, and they also have a "X" button that I'd prefer not to have in my prompts (they should be forced to explicitly click accept or reject.)
Any suggestions on what approach I should take?