Matteo Scandolo | 8cc22e4 | 2016-04-12 09:00:04 -0700 | [diff] [blame] | 1 | 'use strict'; |
| 2 | |
| 3 | angular.module('xos.sampleView', [ |
| 4 | 'ngResource', |
| 5 | 'ngCookies', |
Matteo Scandolo | 8cc22e4 | 2016-04-12 09:00:04 -0700 | [diff] [blame] | 6 | 'ui.router', |
| 7 | 'xos.helpers' |
| 8 | ]) |
| 9 | .config(($stateProvider) => { |
| 10 | $stateProvider |
| 11 | .state('user-list', { |
| 12 | url: '/', |
| 13 | template: '<users-list></users-list>' |
| 14 | }); |
| 15 | }) |
| 16 | .config(function($httpProvider){ |
| 17 | $httpProvider.interceptors.push('NoHyperlinks'); |
| 18 | }) |
| 19 | .directive('usersList', function(){ |
| 20 | return { |
| 21 | restrict: 'E', |
| 22 | scope: {}, |
| 23 | bindToController: true, |
| 24 | controllerAs: 'vm', |
| 25 | templateUrl: 'templates/users-list.tpl.html', |
Matteo Scandolo | bd2e5cd | 2016-04-12 11:59:29 -0700 | [diff] [blame] | 26 | controller: function(Users){ |
Matteo Scandolo | 18adcb5 | 2016-04-14 12:06:50 -0700 | [diff] [blame] | 27 | |
| 28 | this.tableConfig = { |
| 29 | columns: [ |
| 30 | { |
| 31 | label: 'E-Mail', |
| 32 | prop: 'email' |
| 33 | }, |
| 34 | { |
Matteo Scandolo | a6a9e61 | 2016-04-14 16:52:13 -0700 | [diff] [blame] | 35 | label: 'First Name', |
Matteo Scandolo | 18adcb5 | 2016-04-14 12:06:50 -0700 | [diff] [blame] | 36 | prop: 'firstname' |
| 37 | }, |
| 38 | { |
Matteo Scandolo | a6a9e61 | 2016-04-14 16:52:13 -0700 | [diff] [blame] | 39 | label: 'Last Name', |
Matteo Scandolo | 18adcb5 | 2016-04-14 12:06:50 -0700 | [diff] [blame] | 40 | prop: 'lastname' |
| 41 | } |
| 42 | ], |
Matteo Scandolo | 9e6c6fc | 2016-04-14 14:59:09 -0700 | [diff] [blame] | 43 | classes: 'table table-striped table-condensed', |
| 44 | actions: [ |
| 45 | { |
| 46 | label: 'delete', |
| 47 | icon: 'remove', |
| 48 | cb: (user) => { |
| 49 | console.log(user); |
| 50 | }, |
| 51 | color: 'red' |
| 52 | } |
Matteo Scandolo | a6a9e61 | 2016-04-14 16:52:13 -0700 | [diff] [blame] | 53 | ], |
Matteo Scandolo | 03e5960 | 2016-04-14 17:19:08 -0700 | [diff] [blame] | 54 | filter: 'field', |
Matteo Scandolo | cc6954e | 2016-04-15 12:20:14 -0700 | [diff] [blame] | 55 | order: true, |
Matteo Scandolo | 7bc39c4 | 2016-04-20 11:38:42 -0700 | [diff] [blame] | 56 | pagination: { |
| 57 | pageSize: 3 |
| 58 | } |
Matteo Scandolo | 18adcb5 | 2016-04-14 12:06:50 -0700 | [diff] [blame] | 59 | }; |
| 60 | |
Matteo Scandolo | 74b6ef7 | 2016-04-15 16:43:48 -0700 | [diff] [blame] | 61 | this.alertConfig = { |
| 62 | type: 'danger', |
| 63 | closeBtn: true |
| 64 | } |
| 65 | |
Matteo Scandolo | 7bc39c4 | 2016-04-20 11:38:42 -0700 | [diff] [blame] | 66 | this.formConfig = { |
| 67 | exclude: ['password'], |
Matteo Scandolo | 840260d | 2016-04-22 09:56:48 -0700 | [diff] [blame] | 68 | formName: 'myForm', |
Matteo Scandolo | 7bc39c4 | 2016-04-20 11:38:42 -0700 | [diff] [blame] | 69 | fields: { |
Matteo Scandolo | 7bc39c4 | 2016-04-20 11:38:42 -0700 | [diff] [blame] | 70 | }, |
| 71 | actions: [ |
| 72 | { |
| 73 | label: 'Save', |
| 74 | icon: 'ok', // refers to bootstraps glyphicon |
| 75 | cb: (user) => { // receive the model |
| 76 | console.log(user); |
| 77 | }, |
| 78 | class: 'success' |
| 79 | } |
| 80 | ] |
| 81 | } |
Matteo Scandolo | 74b6ef7 | 2016-04-15 16:43:48 -0700 | [diff] [blame] | 82 | |
Matteo Scandolo | 8cc22e4 | 2016-04-12 09:00:04 -0700 | [diff] [blame] | 83 | // retrieving user list |
Matteo Scandolo | bd2e5cd | 2016-04-12 11:59:29 -0700 | [diff] [blame] | 84 | Users.query().$promise |
Matteo Scandolo | 8cc22e4 | 2016-04-12 09:00:04 -0700 | [diff] [blame] | 85 | .then((users) => { |
Matteo Scandolo | 7bc39c4 | 2016-04-20 11:38:42 -0700 | [diff] [blame] | 86 | this.users = users.concat(users).concat(users); |
Matteo Scandolo | 8cc22e4 | 2016-04-12 09:00:04 -0700 | [diff] [blame] | 87 | }) |
| 88 | .catch((e) => { |
| 89 | throw new Error(e); |
| 90 | }); |
| 91 | } |
| 92 | }; |
| 93 | }); |