// Written by Joshua Paul A. Chan
(function() {
"use strict";

// `users` CONTROLLER
//
angular.module('wr.controllers')
.controller('users', function($scope, $state, $userService) {

    $scope.users = [];

    $scope.curPage = 0;

    ///////////////////////// DISPLAYING USERS /////////////////////////

    // `loadConversations(pg)`
    // Loads the conversations from the server using the conersation service.
    //
    // @pre     : the conversation list service must be initialized
    // @pre     : `pg` must be a non-negative integer
    // @pre     : `numItemsPerPage` must be a positive integer
    // @post    : [success] the `numItemsPerPage` will saved to the service,
    // allowing `loadNextPage` to be used instead
    // @post    : [success] the conversations will replace the current convos
    // @post    : [error] if no more items (pg > LAST_PAGE), do nothing
    // @post    : [error] if other error, error will be sent to error service to
    // display on page and log for analytics
    //
    // @param   : pg    : Number    : the page number of the converations to get
    // @return  : null
    $scope.loadApprovedUsers = (pg) => {
        $userService
            .loadApprovedUsers(pg, $scope.numItemsPerPage)
            .then(
                (users) => {
                    $scope.users = users;
                    $scope.$apply();                // update angular
                },
                (err) => {
                    console.error(err);
                    // FIXME: uncomment when notification service is implemented
                    // $notificationService.notify({
                    //     type: "error",
                    //     text: "There was an error loading the conversations from the server."
                    // });
                });
    };

    // TODO: `loadNextPage()`
    // Load the next page of conversation items (either during regular browsing
    // or search).
    //
    // @pre     : the conversation list service must be initialized
    // @pre     : [success] Either a search through the conversations or a
    // conversation page load must have been completed previously (to save the
    // default number of pages and current page in the conversation list
    // service)
    // @post    : [success] the next page of conversations will be appended to
    // the current list of conversations
    // @post    : [error] the current conversation list will not be mutated in
    // any way
    // @post    : [error] if other error, error will be sent to error service to
    // display on page and log for analytics
    //
    // @param   : null
    // @return  : null
    $scope.loadNextPage = () => {
        // CODE IN HERE
    };

    ///////////////////////////// APPROVING USERS /////////////////////////////

    // TODO: `approveUser()`
    // Opens the 'Move To' modal for selecting a folder (i.e inbox, trash, etc.)
    // to move a conversation/several conversations to.
    //
    // @pre     : at least one conversation must be selected
    // @pre     : no other modal (even the Move modal) should be open on screen
    // @post    : [success] the Mark modal will be opened and visible on screen
    //
    // @param   : null
    // @return  : null
    $scope.approveUser = (user) => {
        // CODE IN HERE
    };

    // Load messages when initialized
    $scope.loadApprovedUsers($scope.curPage);
});
}());

@@ -255,16 +255,20 @@
 ////////
+////
  DISPLAY
@@ -294,32 +294,36 @@
 ////////////////
+////
 %0A%0A    // %60loadCo
@@ -1134,32 +1134,24 @@
  $scope.load
-Approved
 Users = (pg)
@@ -1190,32 +1190,24 @@
        .load
-Approved
 Users(pg, $s
@@ -2712,605 +2712,8 @@
 %7D;%0A%0A
-    ///////////////////////////// APPROVING USERS /////////////////////////////%0A%0A    // TODO: %60approveUser()%60%0A    // Opens the 'Move To' modal for selecting a folder (i.e inbox, trash, etc.)%0A    // to move a conversation/several conversations to.%0A    //%0A    // @pre     : at least one conversation must be selected%0A    // @pre     : no other modal (even the Move modal) should be open on screen%0A    // @post    : %5Bsuccess%5D the Mark modal will be opened and visible on screen%0A    //%0A    // @param   : null%0A    // @return  : null%0A    $scope.approveUser = (user) =%3E %7B%0A        // CODE IN HERE%0A    %7D;%0A%0A
     
@@ -2765,16 +2765,8 @@
 load
-Approved
 User

Switch to non-discriminatory loading