|
1 | 1 | 'use strict'; |
2 | | -angular.module('com.module.pages') |
3 | | - .config(function($stateProvider) { |
4 | | - $stateProvider.state('app.pages', { |
5 | | - abstract: true, |
6 | | - url: '/pages', |
7 | | - templateUrl: 'modules/pages/views/main.html' |
8 | | - }) |
9 | | - .state('app.pages.list', { |
10 | | - url: '', |
11 | | - templateUrl: 'modules/pages/views/list.html', |
12 | | - controller: 'PagesCtrl' |
13 | | - }) |
14 | | - .state('app.pages.add', { |
15 | | - url: '/add', |
16 | | - templateUrl: 'modules/pages/views/form.html', |
17 | | - controller: 'PagesCtrl' |
18 | | - }) |
19 | | - .state('app.pages.edit', { |
20 | | - url: '/:id/edit', |
21 | | - templateUrl: 'modules/pages/views/form.html', |
22 | | - controller: 'PagesCtrl' |
23 | | - }) |
24 | | - .state('app.pages.view', { |
25 | | - url: '/:id', |
26 | | - templateUrl: 'modules/pages/views/view.html', |
27 | | - controller: 'PagesCtrl' |
| 2 | + |
| 3 | +var app = angular.module('com.module.pages'); |
| 4 | + |
| 5 | +app.config(function ($stateProvider) { |
| 6 | + $stateProvider.state('app.pages', { |
| 7 | + abstract: true, |
| 8 | + url: '/pages', |
| 9 | + templateUrl: 'modules/pages/views/main.html' |
| 10 | + }).state('app.pages.list', { |
| 11 | + url: '', |
| 12 | + templateUrl: 'modules/pages/views/list.html', |
| 13 | + controllerAs: 'ctrl', |
| 14 | + controller: function (pages) { |
| 15 | + this.pages = pages; |
| 16 | + }, |
| 17 | + resolve: { |
| 18 | + pages: function (PageService) { |
| 19 | + return PageService.find(); |
| 20 | + } |
| 21 | + } |
| 22 | + }).state('app.pages.add', { |
| 23 | + url: '/add', |
| 24 | + templateUrl: 'modules/pages/views/form.html', |
| 25 | + controllerAs: 'ctrl', |
| 26 | + controller: function ($state, PageService, page) { |
| 27 | + this.editorOptions = { |
| 28 | + theme: 'monokai', |
| 29 | + lineWrapping: true, |
| 30 | + lineNumbers: true, |
| 31 | + mode: 'markdown' |
| 32 | + }; |
| 33 | + this.page = page; |
| 34 | + this.formFields = PageService.getFormFields(); |
| 35 | + this.formOptions = {}; |
| 36 | + this.submit = function () { |
| 37 | + PageService.upsert(this.page).then(function () { |
| 38 | + $state.go('^.list'); |
| 39 | + }); |
| 40 | + }; |
| 41 | + }, |
| 42 | + resolve: { |
| 43 | + page: function () { |
| 44 | + return { |
| 45 | + content: '# Hi!\n\n## This is a markdown editor.\n\n fine code goes here \n\n- lists \n- go \n- here ' + |
| 46 | + '\n\n*Find* **more information** about `markdown` [Here](https://daringfireball.net/projects/markdown/basics)!' |
| 47 | + }; |
| 48 | + } |
| 49 | + } |
| 50 | + }).state('app.pages.edit', { |
| 51 | + url: '/:id/edit', |
| 52 | + templateUrl: 'modules/pages/views/form.html', |
| 53 | + controllerAs: 'ctrl', |
| 54 | + controller: function ($state, PageService, page) { |
| 55 | + this.editorOptions = { |
| 56 | + theme: 'monokai', |
| 57 | + lineWrapping: true, |
| 58 | + lineNumbers: true, |
| 59 | + mode: 'markdown' |
| 60 | + }; |
| 61 | + this.page = page; |
| 62 | + this.formFields = PageService.getFormFields(); |
| 63 | + this.formOptions = {}; |
| 64 | + this.submit = function () { |
| 65 | + PageService.upsert(this.page).then(function () { |
| 66 | + $state.go('^.list'); |
| 67 | + }); |
| 68 | + }; |
| 69 | + }, |
| 70 | + resolve: { |
| 71 | + page: function ($stateParams, PageService) { |
| 72 | + return PageService.findById($stateParams.id); |
| 73 | + } |
| 74 | + } |
| 75 | + }).state('app.pages.view', { |
| 76 | + url: '/:id', |
| 77 | + templateUrl: 'modules/pages/views/view.html', |
| 78 | + controllerAs: 'ctrl', |
| 79 | + controller: function (page) { |
| 80 | + this.page = page; |
| 81 | + }, |
| 82 | + resolve: { |
| 83 | + page: function ($stateParams, PageService) { |
| 84 | + return PageService.findById($stateParams.id); |
| 85 | + } |
| 86 | + } |
| 87 | + }).state('app.pages.delete', { |
| 88 | + url: '/:id/delete', |
| 89 | + template: '', |
| 90 | + controllerAs: 'ctrl', |
| 91 | + controller: function ($stateParams, $state, PageService) { |
| 92 | + PageService.delete($stateParams.id, function () { |
| 93 | + $state.go('^.list'); |
| 94 | + }, function () { |
| 95 | + $state.go('^.list'); |
28 | 96 | }); |
| 97 | + } |
29 | 98 | }); |
| 99 | +}); |
0 commit comments