<repo_name>seanholahan/seanholahan-assignment-web<file_sep>/public/assignment/services/website.service.client.js
(function(){
    angular
        .module("WebAppMaker")
        .factory("WebsiteService", WebsiteService);

    function WebsiteService($http) {

        var api = {
            findWebsitesForUser: findWebsitesForUser,
            findWebsiteById: findWebsiteById,
            createWebsite: createWebsite,
            updateWebsite: updateWebsite,
            removeWebsite: removeWebsite
        };
        return api;

        function removeWebsite(websiteId) {
            var url = "/api/website/"+ websiteId;
            $http.delete(url);

        }

        function updateWebsite(websiteId, website) {
            var url = "/api/website/"+websiteId;
            $http.put(url, website);
        }

        function createWebsite(uid, website) {
            var url = "/api/user/"+uid+"/website";
            $http.post(url, website);
        }

        function findWebsiteById(wid) {
            var url = "/api/website/"+wid;
            return $http.get(url);

        }

        function findWebsitesForUser(uid) {
            var url = "/api/user/"+uid+"/website";
            return $http.get(url, uid);
        }
    }
})();<file_sep>/public/assignment/views/website/website-list.controller.js

(function (angular) {


        var WebAppMaker = angular.module("WebAppMaker")
            .controller("WebsiteListController", WebsiteListController)

    function WebsiteListController($routeParams, WebsiteService) {
        var vm = this;
         vm.userId = parseInt($routeParams.uid);


        function init() {
            var promise = WebsiteService.findWebsitesForUser(vm.userId);
            promise
                .success(function(websites){
                    vm.websites = websites;
                });
        }
        init();
    }

})(window.angular);<file_sep>/public/assignment/views/page/page-new.controller.client.js



(function (angular) {


    var WebAppMaker = angular.module("WebAppMaker")
        .controller("PageNewController", PageNewController)

    function PageNewController($routeParams, PageService, $location) {
        var vm = this;
        vm.userId = parseInt($routeParams.uid);
        vm.websiteId = parseInt($routeParams.wid);
        vm.pageId = parseInt($routeParams.pid);
        vm.userId = parseInt($routeParams.uid);
        vm.websiteId = parseInt($routeParams.wid);
        vm. widgetId = parseInt($routeParams.wgid);
        vm.updatePage = updatePage;
        vm.deletePage = deletePage;
        vm.createPage = createPage;
        vm.paged = { "_id": 0,
            "name": "",
            "websiteId": "",
            "description": ""};

        function init() {
            vm.pages = PageService.findPageByWebsiteId(vm.websiteId);
            vm.page = PageService.findPageById(vm.pageId);

        }
        init();


        function updatePage(page) {
            PageService.updatePage(page);
            $location.url("/user/" + vm.userId + "/website/" +vm.websiteId + "/page");
        }

        function deletePage(pid) {
            PageService.deletePage(vm.pageId);
            $location.url("/user/" +vm.userId + "/website/"+vm.websiteId + "/page");
        }

        function createPage(paged) {

            vm.paged._id = (new Date()).getTime();
            vm.paged.websiteId = this.websiteId;


            PageService.createPage(vm.paged);

            $location.url("/user/" + vm.userId + "/website/" + vm.websiteId + "/page");

      //      vm.pages = PageService.findWebsitesForUser(vm.userId);

        }


    }

})(window.angular);<file_sep>/public/assignment/views/page/page-list.controller.client.js
(function (angular) {


    var WebAppMaker = angular.module("WebAppMaker")
        .controller("PageListController", PageListController)

    function PageListController($routeParams, PageService) {
        var vm = this;
        vm.websiteId = parseInt($routeParams.wid);
        vm.uid  = $routeParams.uid;
        vm.wid  = $routeParams.wid;
        vm.pid  = $routeParams.pid;
        vm.wgid = $routeParams.wgid;

       /* vm.updatePage = updatePage;
        vm.removePage = removePage;*/


        function init() {

            var promise = PageService.findPagesByWebsiteId(vm.websiteId);
            promise
                .success(function(pages){
                    vm.pages = pages;
                });

        }
        init();
    }

})(window.angular);
<file_sep>/public/assignment/views/website/website-edit.controller.client.js
(function () {
    angular
        .module("WebAppMaker")
        .controller("WebsiteEditController", WebsiteEditController);

    function WebsiteEditController($routeParams, WebsiteService) {
        var vm = this;
        vm.userId = parseInt($routeParams.uid);
        vm.uid  = $routeParams.uid;
        vm.wid  = $routeParams.wid;
        vm.pid  = $routeParams.pid;
        vm.wgid = $routeParams.wgid;


        function init() {
            var promise = WebsiteService.findWebsitesForUser(vm.userId);
            promise
                .success(function(websites){
                    vm.websites = websites;
                });
        }
        init();
    }

})(window.angular);


