voltar 0.0.23
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +3 -0
- data/Rakefile +37 -0
- data/app/assets/fonts/FontAwesome.otf +0 -0
- data/app/assets/fonts/Simple-Line-Icons.eot +0 -0
- data/app/assets/fonts/Simple-Line-Icons.svg +1369 -0
- data/app/assets/fonts/Simple-Line-Icons.ttf +0 -0
- data/app/assets/fonts/Simple-Line-Icons.woff +0 -0
- data/app/assets/fonts/fontawesome-webfont.eot +0 -0
- data/app/assets/fonts/fontawesome-webfont.svg +520 -0
- data/app/assets/fonts/fontawesome-webfont.ttf +0 -0
- data/app/assets/fonts/fontawesome-webfont.woff +0 -0
- data/app/assets/fonts/glyphicons-halflings-regular.eot +0 -0
- data/app/assets/fonts/glyphicons-halflings-regular.svg +229 -0
- data/app/assets/fonts/glyphicons-halflings-regular.ttf +0 -0
- data/app/assets/fonts/glyphicons-halflings-regular.woff +0 -0
- data/app/assets/fonts/sourcesanspro/sourcesanspro-bold.woff +0 -0
- data/app/assets/fonts/sourcesanspro/sourcesanspro-light.woff +0 -0
- data/app/assets/fonts/sourcesanspro/sourcesanspro.woff +0 -0
- data/app/assets/javascripts/voltar/app.js +203 -0
- data/app/assets/javascripts/voltar/application.js +33 -0
- data/app/assets/javascripts/voltar/controllers/app_ctrl.js.erb +673 -0
- data/app/assets/javascripts/voltar/directives/app_directives.js +345 -0
- data/app/assets/javascripts/voltar/factories/app_services.js +255 -0
- data/app/assets/javascripts/voltar/stripe.js.coffee +2 -0
- data/app/assets/stylesheets/voltar/app.css +4990 -0
- data/app/assets/stylesheets/voltar/application.css +23 -0
- data/app/assets/stylesheets/voltar/voltar.css.scss +93 -0
- data/app/controllers/voltar/application_controller.rb +4 -0
- data/app/controllers/voltar/dashboard_controller.rb +11 -0
- data/app/helpers/voltar/application_helper.rb +4 -0
- data/app/views/layouts/voltar/application.html.erb +40 -0
- data/app/views/voltar/account/_billing.html.erb +552 -0
- data/app/views/voltar/account/_locations.html.erb +135 -0
- data/app/views/voltar/account/_managers.html +134 -0
- data/app/views/voltar/account/_password.html.erb +57 -0
- data/app/views/voltar/account/_profile.html.erb +84 -0
- data/app/views/voltar/dashboard/index.html.erb +0 -0
- data/app/views/voltar/inventory/_delete_dialog.html.erb +16 -0
- data/app/views/voltar/inventory/_edit.html.erb +244 -0
- data/app/views/voltar/inventory/_index.html.erb +160 -0
- data/app/views/voltar/inventory/_mark_as_sold_dialog.html.erb +26 -0
- data/app/views/voltar/shared/_keen_js.html.haml +11 -0
- data/app/views/voltar/shared/_voltar_app.html.erb +83 -0
- data/app/views/voltar/shared/_voltar_aside.html.erb +71 -0
- data/app/views/voltar/shared/_voltar_footer.html.erb +13 -0
- data/app/views/voltar/shared/_voltar_header.html.erb +156 -0
- data/app/views/voltar/shared/app/_country_province_select.html +19 -0
- data/app/views/voltar/shared/app/_dashboard.html.erb +243 -0
- data/app/views/voltar/shared/app/_notifications.html.erb +13 -0
- data/app/views/voltar/shared/app/_spinner.html.erb +8 -0
- data/config/routes.rb +4 -0
- data/lib/tasks/voltar_tasks.rake +4 -0
- data/lib/voltar.rb +5 -0
- data/lib/voltar/engine.rb +15 -0
- data/lib/voltar/version.rb +3 -0
- data/test/dummy/README.rdoc +28 -0
- data/test/dummy/Rakefile +6 -0
- data/test/dummy/app/assets/javascripts/application.js +13 -0
- data/test/dummy/app/assets/stylesheets/application.css +15 -0
- data/test/dummy/app/controllers/application_controller.rb +5 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/bin/bundle +3 -0
- data/test/dummy/bin/rails +4 -0
- data/test/dummy/bin/rake +4 -0
- data/test/dummy/bin/setup +29 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/config/application.rb +26 -0
- data/test/dummy/config/boot.rb +5 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +41 -0
- data/test/dummy/config/environments/production.rb +76 -0
- data/test/dummy/config/environments/test.rb +39 -0
- data/test/dummy/config/initializers/assets.rb +11 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/test/dummy/config/initializers/inflections.rb +16 -0
- data/test/dummy/config/initializers/mime_types.rb +4 -0
- data/test/dummy/config/initializers/session_store.rb +3 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +23 -0
- data/test/dummy/config/routes.rb +4 -0
- data/test/dummy/config/secrets.yml +22 -0
- data/test/dummy/log/development.log +0 -0
- data/test/dummy/public/404.html +67 -0
- data/test/dummy/public/422.html +67 -0
- data/test/dummy/public/500.html +66 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/integration/navigation_test.rb +10 -0
- data/test/test_helper.rb +15 -0
- data/test/voltar_test.rb +7 -0
- data/vendor/assets/images/voltar/a0.jpg +0 -0
- data/vendor/assets/images/voltar/a1.jpg +0 -0
- data/vendor/assets/images/voltar/a10.jpg +0 -0
- data/vendor/assets/images/voltar/a2.jpg +0 -0
- data/vendor/assets/images/voltar/a3.jpg +0 -0
- data/vendor/assets/images/voltar/a4.jpg +0 -0
- data/vendor/assets/images/voltar/a5.jpg +0 -0
- data/vendor/assets/images/voltar/a6.jpg +0 -0
- data/vendor/assets/images/voltar/a7.jpg +0 -0
- data/vendor/assets/images/voltar/a8.jpg +0 -0
- data/vendor/assets/images/voltar/a9.jpg +0 -0
- data/vendor/assets/images/voltar/b0.jpg +0 -0
- data/vendor/assets/images/voltar/b1.jpg +0 -0
- data/vendor/assets/images/voltar/b2.jpg +0 -0
- data/vendor/assets/images/voltar/b3.jpg +0 -0
- data/vendor/assets/images/voltar/b4.jpg +0 -0
- data/vendor/assets/images/voltar/b5.jpg +0 -0
- data/vendor/assets/images/voltar/c0.jpg +0 -0
- data/vendor/assets/images/voltar/c1.jpg +0 -0
- data/vendor/assets/images/voltar/c2.jpg +0 -0
- data/vendor/assets/images/voltar/c3.jpg +0 -0
- data/vendor/assets/images/voltar/c4.jpg +0 -0
- data/vendor/assets/images/voltar/c5.jpg +0 -0
- data/vendor/assets/images/voltar/chosen-sprite.png +0 -0
- data/vendor/assets/images/voltar/chosen-sprite@2x.png +0 -0
- data/vendor/assets/images/voltar/logo.png +0 -0
- data/vendor/assets/images/voltar/p0.jpg +0 -0
- data/vendor/assets/javascripts/voltar/angular-animate.js +1689 -0
- data/vendor/assets/javascripts/voltar/angular-contenteditable.js +98 -0
- data/vendor/assets/javascripts/voltar/angular-cookies.js +206 -0
- data/vendor/assets/javascripts/voltar/angular-sanitize.js +647 -0
- data/vendor/assets/javascripts/voltar/angular-ui-router.js +3658 -0
- data/vendor/assets/javascripts/voltar/angular.js +22024 -0
- data/vendor/assets/javascripts/voltar/chosen.jquery.min.js +2 -0
- data/vendor/assets/javascripts/voltar/easypiechart/jquery.easy-pie-chart.js +209 -0
- data/vendor/assets/javascripts/voltar/flot/jquery.flot.min.js +29 -0
- data/vendor/assets/javascripts/voltar/flot/jquery.flot.orderBars.js +187 -0
- data/vendor/assets/javascripts/voltar/flot/jquery.flot.pie.min.js +56 -0
- data/vendor/assets/javascripts/voltar/flot/jquery.flot.resize.js +60 -0
- data/vendor/assets/javascripts/voltar/flot/jquery.flot.spline.js +212 -0
- data/vendor/assets/javascripts/voltar/flot/jquery.flot.tooltip.min.js +12 -0
- data/vendor/assets/javascripts/voltar/jquery.min.js +5 -0
- data/vendor/assets/javascripts/voltar/moment.js +2856 -0
- data/vendor/assets/javascripts/voltar/ngStorage.js +103 -0
- data/vendor/assets/javascripts/voltar/ocLazyLoad.js +906 -0
- data/vendor/assets/javascripts/voltar/smart-table.min.js +1 -0
- data/vendor/assets/javascripts/voltar/sparkline/jquery.sparkline.min.js +2 -0
- data/vendor/assets/javascripts/voltar/toaster.js +185 -0
- data/vendor/assets/javascripts/voltar/ui-bootstrap-tpls.js +4116 -0
- data/vendor/assets/javascripts/voltar/ui-jq.js +86 -0
- data/vendor/assets/javascripts/voltar/ui-load.js +93 -0
- data/vendor/assets/javascripts/voltar/ui-validate.js +119 -0
- data/vendor/assets/stylesheets/voltar/animate.css +1098 -0
- data/vendor/assets/stylesheets/voltar/bootstrap.css +6202 -0
- data/vendor/assets/stylesheets/voltar/chosen.css +399 -0
- data/vendor/assets/stylesheets/voltar/font-awesome.min.css +4 -0
- data/vendor/assets/stylesheets/voltar/font.css +18 -0
- data/vendor/assets/stylesheets/voltar/simple-line-icons.css +526 -0
- data/vendor/assets/stylesheets/voltar/toaster.css +213 -0
- metadata +333 -0
@@ -0,0 +1,673 @@
|
|
1
|
+
angular.module('voltar.controllers', ['voltar.services'])
|
2
|
+
.controller('AppCtrl', ['$scope', '$rootScope', 'BusType', 'Dealer', 'Analytics', function($scope, $rootScope, BusType, Dealer, Analytics) {
|
3
|
+
|
4
|
+
BusType.all()
|
5
|
+
.success(function(success) {
|
6
|
+
$rootScope.bus_types = success;
|
7
|
+
});
|
8
|
+
|
9
|
+
$rootScope.fetchDealer = function() {
|
10
|
+
return Dealer.get();
|
11
|
+
}
|
12
|
+
|
13
|
+
$rootScope.$watch('current_user', function(newVal, oldVal) {
|
14
|
+
if (newVal) {
|
15
|
+
$scope.fetchAnalytics();
|
16
|
+
}
|
17
|
+
})
|
18
|
+
|
19
|
+
$scope.app = {
|
20
|
+
name: 'Voltar',
|
21
|
+
//for chart colors
|
22
|
+
color: {
|
23
|
+
primary: '#7266ba',
|
24
|
+
info: '#23b7e5',
|
25
|
+
success: '#27c24c',
|
26
|
+
warning: '#fad733',
|
27
|
+
danger: '#f05050',
|
28
|
+
light: '#e8eff0',
|
29
|
+
dark: '#3a3f51',
|
30
|
+
black: '#1c2b36'
|
31
|
+
},
|
32
|
+
settings: {
|
33
|
+
themeID: 1,
|
34
|
+
navbarHeaderColor: 'bg-primary',
|
35
|
+
navbarCollapseColor: 'bg-primary',
|
36
|
+
asideColor: 'bg-light',
|
37
|
+
headerFixed: true,
|
38
|
+
asideFixed: true,
|
39
|
+
asideFolded: true,
|
40
|
+
asideDock: false,
|
41
|
+
container: false
|
42
|
+
}
|
43
|
+
}
|
44
|
+
|
45
|
+
$scope.analytics = {};
|
46
|
+
|
47
|
+
$scope.analytics.desktop = 0;
|
48
|
+
$scope.analytics.smartphone = 0;
|
49
|
+
$scope.analytics.tablet = 0;
|
50
|
+
|
51
|
+
$scope.fetchAnalytics = function() {
|
52
|
+
Keen.ready(function() {
|
53
|
+
|
54
|
+
pageviewsQuery = new Keen.Query("count", {
|
55
|
+
eventCollection: "pageviews",
|
56
|
+
filters: [{
|
57
|
+
property_name: "stock.dealer_id",
|
58
|
+
operator: "eq",
|
59
|
+
property_value: $rootScope.current_user.id
|
60
|
+
}]
|
61
|
+
});
|
62
|
+
|
63
|
+
keenClient.run(pageviewsQuery, function(response) {
|
64
|
+
$scope.analytics.pageViews = response.result
|
65
|
+
$scope.fetchDeviceUsage()
|
66
|
+
$scope.$digest();
|
67
|
+
});
|
68
|
+
|
69
|
+
leadsQuery = new Keen.Query("count", {
|
70
|
+
eventCollection: "leads",
|
71
|
+
filters: [{
|
72
|
+
property_name: "stock.dealer_id",
|
73
|
+
operator: "eq",
|
74
|
+
property_value: $rootScope.current_user.id
|
75
|
+
}]
|
76
|
+
});
|
77
|
+
|
78
|
+
keenClient.run(leadsQuery, function(response) {
|
79
|
+
$scope.analytics.leadsCount = response.result
|
80
|
+
$scope.$digest();
|
81
|
+
});
|
82
|
+
|
83
|
+
});
|
84
|
+
}
|
85
|
+
|
86
|
+
$scope.fetchDeviceUsage = function() {
|
87
|
+
deviceUsageQuery = new Keen.Query("count", {
|
88
|
+
eventCollection: "pageviews",
|
89
|
+
groupBy: "form_factor",
|
90
|
+
filters: [{
|
91
|
+
property_name: "stock.dealer_id",
|
92
|
+
operator: "eq",
|
93
|
+
property_value: $rootScope.current_user.id
|
94
|
+
}]
|
95
|
+
});
|
96
|
+
|
97
|
+
keenClient.run(deviceUsageQuery, function(response) {
|
98
|
+
$scope.analytics.desktop = (response.result[0].result/$scope.analytics.pageViews * 100).toPrecision(4) ;
|
99
|
+
$scope.analytics.smartphone = (response.result[1].result/$scope.analytics.pageViews * 100).toPrecision(4);
|
100
|
+
$scope.analytics.tablet = (response.result[2].result/$scope.analytics.pageViews * 100).toPrecision(4);
|
101
|
+
$scope.deviceUsageAvailable = true;
|
102
|
+
$scope.$digest();
|
103
|
+
});
|
104
|
+
}
|
105
|
+
|
106
|
+
Analytics.busTypes()
|
107
|
+
.success(function(success) {
|
108
|
+
$scope.bus_types_chart_data = success.bus_types;
|
109
|
+
$scope.ticks = success.ticks;
|
110
|
+
})
|
111
|
+
|
112
|
+
$scope.busTypesTooltip = function(label, x, y, item) {
|
113
|
+
return item.series.xaxis.ticks[x].label + " Buses: " + y
|
114
|
+
}
|
115
|
+
|
116
|
+
}])
|
117
|
+
|
118
|
+
// Inventories Controller
|
119
|
+
.controller('InventoriesController', ['$scope', 'Inventory', '$rootScope', '$stateParams', '$modal', 'toaster', function($scope, Inventory, $rootScope, $stateParams, $modal, toaster) {
|
120
|
+
|
121
|
+
$scope.search = {};
|
122
|
+
|
123
|
+
if ($stateParams.pageNumber) {
|
124
|
+
$scope.search['page'] = $stateParams.pageNumber;
|
125
|
+
}
|
126
|
+
|
127
|
+
$scope.issueSearch = function(formSearch) {
|
128
|
+
$scope.search['search'] = formSearch || {};
|
129
|
+
$scope.loadInventories();
|
130
|
+
}
|
131
|
+
|
132
|
+
$scope.loadInventories = function() {
|
133
|
+
Inventory.all($scope.search)
|
134
|
+
.success(function(success) {
|
135
|
+
$scope.inventories = success.inventories;
|
136
|
+
$scope.inventories.meta = success.meta
|
137
|
+
})
|
138
|
+
.error(function(error) {
|
139
|
+
// error
|
140
|
+
})
|
141
|
+
}
|
142
|
+
|
143
|
+
$scope.markAsSold = function(inventory) {
|
144
|
+
var modalInstance = $modal.open({
|
145
|
+
templateUrl: 'markAsSold.html',
|
146
|
+
controller: 'MarkAsSoldController',
|
147
|
+
resolve: {
|
148
|
+
inventory: function() {
|
149
|
+
return inventory;
|
150
|
+
}
|
151
|
+
}
|
152
|
+
});
|
153
|
+
|
154
|
+
modalInstance.result.then(function (inventory) {
|
155
|
+
$scope.loadInventories();
|
156
|
+
}, function () {
|
157
|
+
// clicked cancel
|
158
|
+
});
|
159
|
+
|
160
|
+
}
|
161
|
+
|
162
|
+
$scope.prioritize = function(inventory) {
|
163
|
+
var prioritize = confirm('Are you sure you want to prioritize this listing?');
|
164
|
+
|
165
|
+
if (prioritize) {
|
166
|
+
Inventory.prioritize([inventory.id])
|
167
|
+
.success(function(success) {
|
168
|
+
toaster.pop('success', 'Success', 'Inventory prioritized successfully!');
|
169
|
+
$scope.loadInventories()
|
170
|
+
})
|
171
|
+
.error(function(error) {
|
172
|
+
toaster.pop('error', 'Failed', 'We were unable to prioritize this listing!');
|
173
|
+
})
|
174
|
+
} else {
|
175
|
+
toaster.pop('info', 'Info', 'You can always decide to prioritize this listing whenever you are ready. :)');
|
176
|
+
}
|
177
|
+
|
178
|
+
}
|
179
|
+
|
180
|
+
$scope.deleteInventory = function(inventory) {
|
181
|
+
var modalInstance = $modal.open({
|
182
|
+
templateUrl: 'deleteInventory.html',
|
183
|
+
controller: 'DeleteInventoryController',
|
184
|
+
resolve: {
|
185
|
+
inventory: function() {
|
186
|
+
return inventory;
|
187
|
+
}
|
188
|
+
}
|
189
|
+
});
|
190
|
+
|
191
|
+
modalInstance.result.then(function (inventory) {
|
192
|
+
Inventory.destroy(inventory.id)
|
193
|
+
.success(function(success) {
|
194
|
+
toaster.pop('success', 'Success', 'Inventory deleted successfully!');
|
195
|
+
$scope.loadInventories();
|
196
|
+
})
|
197
|
+
.error(function(error) {
|
198
|
+
toaster.pop('error', 'Failed', 'Unable to fulfil your request. The inventory was not deleted.')
|
199
|
+
});
|
200
|
+
|
201
|
+
}, function () {
|
202
|
+
// clicked cancel
|
203
|
+
});
|
204
|
+
|
205
|
+
}
|
206
|
+
|
207
|
+
$scope.loadInventories();
|
208
|
+
|
209
|
+
}])
|
210
|
+
|
211
|
+
|
212
|
+
// EditInventoryController
|
213
|
+
.controller('EditInventoryController', ['$scope', 'Inventory', '$rootScope', '$stateParams', 'BusType', 'YearRange', 'mode', '$state', 'toaster', 'FileUploader', 'apiBaseUrl', function($scope, Inventory, $rootScope, $stateParams, BusType, YearRange, mode, $state, toaster, FileUploader, apiBaseUrl) {
|
214
|
+
|
215
|
+
$scope.mode = mode;
|
216
|
+
$scope.years = YearRange.generate();
|
217
|
+
$scope.body_makes = {}
|
218
|
+
$scope.inventory = {
|
219
|
+
images: [],
|
220
|
+
image_ids: []
|
221
|
+
};
|
222
|
+
$scope.uploader = new FileUploader({
|
223
|
+
url: apiBaseUrl + 'images',
|
224
|
+
removeAfterUpload: true,
|
225
|
+
autoUpload: true
|
226
|
+
});
|
227
|
+
|
228
|
+
// executed after file has been successfully uploaded.
|
229
|
+
$scope.uploader.onSuccessItem = function(item, response, status, headers) {
|
230
|
+
$scope.inventory.images.push(response);
|
231
|
+
$scope.inventory.image_ids.push(response.id);
|
232
|
+
}
|
233
|
+
|
234
|
+
// executed before the file is uploaded.
|
235
|
+
$scope.uploader.onBeforeUploadItem = function(item) {
|
236
|
+
if ($scope.inventory.id) {
|
237
|
+
item.formData.push({ bus_id: $scope.inventory.id });
|
238
|
+
}
|
239
|
+
}
|
240
|
+
|
241
|
+
$scope.uploadUnsavedImages = function() {
|
242
|
+
if ($scope.uploader.queue.length > 0) {
|
243
|
+
console.log($scope.uploader.uploadAll());
|
244
|
+
}
|
245
|
+
}
|
246
|
+
|
247
|
+
$scope.updateBodyMakes = function(inventory) {
|
248
|
+
BusType.body_makes(inventory.bus_type_id)
|
249
|
+
.success(function(success) {
|
250
|
+
//angular.element(document.querySelector('#body_make_select')).trigger('chosen:updated')
|
251
|
+
$scope.body_makes = success;
|
252
|
+
})
|
253
|
+
.error(function(error) {
|
254
|
+
// handle error here
|
255
|
+
})
|
256
|
+
}
|
257
|
+
|
258
|
+
$scope.loadEditPage = function(inventory) {
|
259
|
+
$state.go('app.inventoryEditPage', { inventoryId: inventory.id })
|
260
|
+
}
|
261
|
+
|
262
|
+
$scope.preSave = function() {
|
263
|
+
$scope.uploadUnsavedImages()
|
264
|
+
$scope.savingInventory = true
|
265
|
+
$scope.success = false;
|
266
|
+
$scope.errors = false;
|
267
|
+
}
|
268
|
+
|
269
|
+
$scope.postSave = function() {
|
270
|
+
$("body,html").animate({scrollTop: 0}, "slow");
|
271
|
+
}
|
272
|
+
|
273
|
+
$scope.addNew = function(inventory) {
|
274
|
+
$scope.preSave()
|
275
|
+
|
276
|
+
Inventory.save(inventory)
|
277
|
+
.success(function(success) {
|
278
|
+
$scope.savingInventory = false;
|
279
|
+
$scope.success = true;
|
280
|
+
$scope.inventory = success;
|
281
|
+
$scope.loadEditPage($scope.inventory);
|
282
|
+
toaster.pop('success', 'SUCCESS', 'Inventory added successfully!');
|
283
|
+
})
|
284
|
+
.error(function(error) {
|
285
|
+
$scope.savingInventory = false;
|
286
|
+
$scope.errors = error.errors;
|
287
|
+
})
|
288
|
+
$scope.postSave()
|
289
|
+
}
|
290
|
+
|
291
|
+
$scope.updateInventory = function(inventory) {
|
292
|
+
$scope.preSave()
|
293
|
+
|
294
|
+
Inventory.update(inventory)
|
295
|
+
.success(function(success) {
|
296
|
+
$scope.savingInventory = false;
|
297
|
+
$scope.success = true;
|
298
|
+
$scope.inventory = success;
|
299
|
+
})
|
300
|
+
.error(function(error) {
|
301
|
+
$scope.savingInventory = false;
|
302
|
+
$scope.errors = error.errors;
|
303
|
+
})
|
304
|
+
|
305
|
+
$scope.postSave()
|
306
|
+
}
|
307
|
+
|
308
|
+
// If inventory edit mode.
|
309
|
+
if ($stateParams.inventoryId) {
|
310
|
+
Inventory.get($stateParams.inventoryId)
|
311
|
+
.success(function(success) {
|
312
|
+
$scope.inventory = success;
|
313
|
+
$scope.updateBodyMakes($scope.inventory);
|
314
|
+
})
|
315
|
+
.error(function(error) {
|
316
|
+
// get rid
|
317
|
+
})
|
318
|
+
}
|
319
|
+
|
320
|
+
}])
|
321
|
+
|
322
|
+
// delete inventory controller
|
323
|
+
.controller('DeleteInventoryController', ['$scope', '$modalInstance', 'inventory', function($scope, $modalInstance, inventory) {
|
324
|
+
|
325
|
+
$scope.inventory = inventory;
|
326
|
+
|
327
|
+
$scope.yes = function(inventory) {
|
328
|
+
$modalInstance.close(inventory);
|
329
|
+
}
|
330
|
+
|
331
|
+
$scope.cancel = function () {
|
332
|
+
$modalInstance.dismiss('cancel');
|
333
|
+
};
|
334
|
+
|
335
|
+
|
336
|
+
}])
|
337
|
+
|
338
|
+
|
339
|
+
// mark as sold controller
|
340
|
+
.controller('MarkAsSoldController', ['$scope', '$modalInstance', 'inventory', 'Inventory', 'toaster', function($scope, $modalInstance, inventory, Inventory, toaster) {
|
341
|
+
|
342
|
+
$scope.inventory = inventory;
|
343
|
+
|
344
|
+
$scope.markAsSold = function(inventory) {
|
345
|
+
//inventory.sold_checked = true;
|
346
|
+
$scope.errors = null;
|
347
|
+
Inventory.update(inventory)
|
348
|
+
.success(function(success) {
|
349
|
+
toaster.pop('success', 'Success', 'Inventory successfully marked as SOLD.');
|
350
|
+
$modalInstance.close(inventory);
|
351
|
+
})
|
352
|
+
.error(function(error) {
|
353
|
+
$scope.errors = error.errors;
|
354
|
+
toaster.pop('error', 'Failed', 'Unable to fulfil your request. The inventory was not marked as sold. Fix the errors please.')
|
355
|
+
})
|
356
|
+
|
357
|
+
}
|
358
|
+
|
359
|
+
$scope.cancel = function() {
|
360
|
+
$modalInstance.dismiss('cancel');
|
361
|
+
}
|
362
|
+
|
363
|
+
|
364
|
+
}])
|
365
|
+
|
366
|
+
|
367
|
+
// profile controller
|
368
|
+
.controller('ProfileController', ['$scope', 'toaster', 'Dealer', 'Country', 'Province', function($scope, toaster, Dealer, Country, Province) {
|
369
|
+
|
370
|
+
Dealer.get()
|
371
|
+
.success(function(success) {
|
372
|
+
$scope.dealer = success;
|
373
|
+
})
|
374
|
+
.error(function(error) {
|
375
|
+
//
|
376
|
+
})
|
377
|
+
|
378
|
+
$scope.updateProfile = function(dealer) {
|
379
|
+
$scope.savingProfile = true
|
380
|
+
$scope.success = false;
|
381
|
+
$scope.errors = false;
|
382
|
+
|
383
|
+
Dealer.update(dealer)
|
384
|
+
.success(function(success) {
|
385
|
+
$scope.savingProfile = false;
|
386
|
+
$scope.success = true;
|
387
|
+
$scope.dealer = success;
|
388
|
+
})
|
389
|
+
.error(function(error) {
|
390
|
+
$scope.savingProfile = false;
|
391
|
+
$scope.errors = error.errors;
|
392
|
+
})
|
393
|
+
|
394
|
+
$("body,html").animate({scrollTop: 0}, "slow");
|
395
|
+
}
|
396
|
+
|
397
|
+
$scope.updateStates = function(countryId) {
|
398
|
+
Province.get(countryId)
|
399
|
+
.success(function(success) {
|
400
|
+
$scope.provinces = success;
|
401
|
+
})
|
402
|
+
.error(function(error) {
|
403
|
+
//$scope.error = error
|
404
|
+
})
|
405
|
+
}
|
406
|
+
|
407
|
+
|
408
|
+
}])
|
409
|
+
|
410
|
+
|
411
|
+
// password controller
|
412
|
+
.controller('PasswordController', ['$scope', 'Password', 'Dealer', function($scope, Password, Dealer) {
|
413
|
+
|
414
|
+
Dealer.get()
|
415
|
+
.success(function(success) {
|
416
|
+
$scope.dealer = success;
|
417
|
+
})
|
418
|
+
.error(function(error) {
|
419
|
+
//
|
420
|
+
})
|
421
|
+
|
422
|
+
$scope.updatePassword = function(dealer) {
|
423
|
+
$scope.errors = null;
|
424
|
+
$scope.updatingPassword = true;
|
425
|
+
Password.update(dealer)
|
426
|
+
.success(function(success) {
|
427
|
+
$scope.success = true;
|
428
|
+
$scope.updatingPassword = false;
|
429
|
+
})
|
430
|
+
.error(function(error) {
|
431
|
+
$scope.errors = error.errors;
|
432
|
+
$scope.updatingPassword = false;
|
433
|
+
})
|
434
|
+
}
|
435
|
+
|
436
|
+
}])
|
437
|
+
|
438
|
+
|
439
|
+
// Locations controller
|
440
|
+
.controller('LocationsController', ['$scope', 'Location', function($scope, Location) {
|
441
|
+
|
442
|
+
$scope.fetchLocations = function() {
|
443
|
+
Location.all()
|
444
|
+
.success(function(success) {
|
445
|
+
$scope.locations = success;
|
446
|
+
})
|
447
|
+
.error(function(error) {
|
448
|
+
// error handling here.
|
449
|
+
})
|
450
|
+
}
|
451
|
+
|
452
|
+
// location can either be edited or added
|
453
|
+
// this function handles both..
|
454
|
+
// in case of add, location is not present
|
455
|
+
$scope.editLocation = function(location) {
|
456
|
+
$scope.success = false;
|
457
|
+
$scope.errors = false;
|
458
|
+
if (location) {
|
459
|
+
$scope.selectedLocation = location;
|
460
|
+
$scope.mode = 'Edit Location';
|
461
|
+
} else {
|
462
|
+
$scope.selectedLocation = {};
|
463
|
+
$scope.mode = 'Add Location'
|
464
|
+
}
|
465
|
+
$scope.showLocationForm = true;
|
466
|
+
}
|
467
|
+
|
468
|
+
$scope.persistLocation = function(location) {
|
469
|
+
$scope.success = false;
|
470
|
+
$scope.errors = false;
|
471
|
+
$scope.updatingLocation = true;
|
472
|
+
|
473
|
+
Location.persist(location)
|
474
|
+
.success(function(success) {
|
475
|
+
$scope.updatingLocation = false;
|
476
|
+
$scope.success = true;
|
477
|
+
$scope.fetchLocations();
|
478
|
+
$("body,html").animate({scrollTop: 0}, "slow");
|
479
|
+
})
|
480
|
+
.error(function(error) {
|
481
|
+
$scope.errors = error.errors;
|
482
|
+
$scope.updatingLocation = false;
|
483
|
+
$("body,html").animate({scrollTop: 0}, "slow");
|
484
|
+
})
|
485
|
+
}
|
486
|
+
|
487
|
+
$scope.fetchLocations();
|
488
|
+
|
489
|
+
}])
|
490
|
+
|
491
|
+
|
492
|
+
|
493
|
+
.controller('ManagersController', ['$scope', 'Manager', '$rootScope', function($scope, Manager, $rootScope) {
|
494
|
+
|
495
|
+
$scope.fetchManagers = function() {
|
496
|
+
Manager.all()
|
497
|
+
.success(function(success) {
|
498
|
+
$scope.managers = success;
|
499
|
+
})
|
500
|
+
.error(function(error) {
|
501
|
+
//
|
502
|
+
})
|
503
|
+
}
|
504
|
+
|
505
|
+
// location can either be edited or added
|
506
|
+
// this function handles both..
|
507
|
+
// in case of add, location is not present
|
508
|
+
$scope.editTeamUser = function(user) {
|
509
|
+
$scope.success = false;
|
510
|
+
$scope.errors = false;
|
511
|
+
if (user) {
|
512
|
+
$scope.selectedTeamUser = user;
|
513
|
+
$scope.mode = 'Edit Team User';
|
514
|
+
} else {
|
515
|
+
$scope.selectedTeamUser = {};
|
516
|
+
$scope.mode = 'Add Team User'
|
517
|
+
}
|
518
|
+
$scope.showTeamUserForm = true;
|
519
|
+
}
|
520
|
+
|
521
|
+
$scope.persistTeamUser = function(user) {
|
522
|
+
user.accepts_terms = true;
|
523
|
+
user.company = 'Parent ' + $rootScope.current_user.company;
|
524
|
+
user.dealer_id = $rootScope.current_user.id;
|
525
|
+
|
526
|
+
$scope.success = false;
|
527
|
+
$scope.errors = false;
|
528
|
+
$scope.updatingTeamUser = true;
|
529
|
+
|
530
|
+
Manager.persist(user)
|
531
|
+
.success(function(success) {
|
532
|
+
$scope.updatingTeamUser = false;
|
533
|
+
$scope.success = true;
|
534
|
+
$scope.fetchManagers();
|
535
|
+
$("body,html").animate({scrollTop: 0}, "slow");
|
536
|
+
})
|
537
|
+
.error(function(error) {
|
538
|
+
$scope.errors = error.errors;
|
539
|
+
$scope.updatingTeamUser = false;
|
540
|
+
$("body,html").animate({scrollTop: 0}, "slow");
|
541
|
+
})
|
542
|
+
}
|
543
|
+
|
544
|
+
|
545
|
+
$scope.fetchManagers();
|
546
|
+
|
547
|
+
}])
|
548
|
+
|
549
|
+
.controller('BillingController', ['$scope', 'Invoice', 'Dealer', '$window', '$rootScope', 'CreditCard', 'toaster', function($scope, Invoice, Dealer, $window, $rootScope, CreditCard, toaster) {
|
550
|
+
|
551
|
+
$ = $window.jQuery;
|
552
|
+
|
553
|
+
$rootScope.$watch('current_user', function(newVal, oldVal) {
|
554
|
+
if (newVal) {
|
555
|
+
$scope.dealer = $rootScope.current_user;
|
556
|
+
$scope.credit_card = $scope.dealer.stripe_card;
|
557
|
+
$scope.currentPlan = $rootScope.current_user.current_plan;
|
558
|
+
}
|
559
|
+
})
|
560
|
+
|
561
|
+
Invoice.all()
|
562
|
+
.success(function(success) {
|
563
|
+
$scope.invoices = success.data;
|
564
|
+
})
|
565
|
+
|
566
|
+
$scope.editCreditCard = function(card) {
|
567
|
+
$scope.cancelCardEdit()
|
568
|
+
$scope.showEditForm = true;
|
569
|
+
$scope.currentCard = card;
|
570
|
+
}
|
571
|
+
|
572
|
+
$scope.addCreditCard = function() {
|
573
|
+
$scope.cancelCardEdit()
|
574
|
+
$scope.showAddCardForm = true;
|
575
|
+
$(document).ready(function() {
|
576
|
+
$scope.skeuocard = new Skeuocard($('#skeuocard'));
|
577
|
+
})
|
578
|
+
}
|
579
|
+
|
580
|
+
$scope.addNewCard = function() {
|
581
|
+
$scope.stripeError = false
|
582
|
+
card = {
|
583
|
+
number: $('#cc_number').val(),
|
584
|
+
cvc: $('#cc_cvc').val(),
|
585
|
+
expMonth: $('#cc_exp_month').val(),
|
586
|
+
expYear: $('#cc_exp_year').val(),
|
587
|
+
name: $('#cc_name').val(),
|
588
|
+
address_line1: $('#address_line1').val(),
|
589
|
+
address_city: $('#address_city').val(),
|
590
|
+
address_state: $('#address_state').val(),
|
591
|
+
address_zip: $('#address_zip').val(),
|
592
|
+
address_country: $('#address_country').val(),
|
593
|
+
}
|
594
|
+
Stripe.createToken(card, $scope.handleStripeResponse)
|
595
|
+
}
|
596
|
+
|
597
|
+
$scope.handleStripeResponse = function(status, response) {
|
598
|
+
if (response.error) {
|
599
|
+
$scope.stripeError = response.error
|
600
|
+
} else {
|
601
|
+
CreditCard.create(response)
|
602
|
+
.success(function(success) {
|
603
|
+
toaster.pop('success', 'Success', 'Credit Card added successfully!');
|
604
|
+
$scope.refreshCardsList();
|
605
|
+
})
|
606
|
+
.error(function(error) {
|
607
|
+
toaster.pop('error', 'Failed', 'We couldn\'t add your Credit Card successfully! Please verify its validity.');
|
608
|
+
})
|
609
|
+
}
|
610
|
+
$scope.$digest()
|
611
|
+
}
|
612
|
+
|
613
|
+
$scope.cancelCardEdit = function(card) {
|
614
|
+
$scope.showEditForm = false;
|
615
|
+
$scope.showAddCardForm = false;
|
616
|
+
}
|
617
|
+
|
618
|
+
$scope.updateCard = function() {
|
619
|
+
CreditCard.update($scope.currentCard)
|
620
|
+
.success(function(success) {
|
621
|
+
toaster.pop('success', 'Success', 'Credit Card updated successfully!');
|
622
|
+
})
|
623
|
+
.error(function(error) {
|
624
|
+
toaster.pop('error', 'Failed', 'We couldn\'t update your Credit Card successfully! Please verify its validity.');
|
625
|
+
})
|
626
|
+
}
|
627
|
+
|
628
|
+
$scope.makePrimary = function(card) {
|
629
|
+
CreditCard.makePrimary(card)
|
630
|
+
.success(function(success) {
|
631
|
+
toaster.pop('success', 'Success', 'Credit Card made primary!');
|
632
|
+
$scope.refreshCardsList()
|
633
|
+
})
|
634
|
+
.error(function(error) {
|
635
|
+
toaster.pop('error', 'Failed', 'Unable to make this card primary. Contact support.');
|
636
|
+
})
|
637
|
+
}
|
638
|
+
|
639
|
+
$scope.refreshCardsList = function() {
|
640
|
+
Dealer.get()
|
641
|
+
.success(function(user) {
|
642
|
+
$rootScope.current_user = user;
|
643
|
+
})
|
644
|
+
$scope.cancelCardEdit();
|
645
|
+
}
|
646
|
+
|
647
|
+
|
648
|
+
}])
|
649
|
+
|
650
|
+
|
651
|
+
// Plans Controller
|
652
|
+
.controller('PlansController', ['$scope', 'Plan', '$rootScope', 'Plan', 'toaster', function($scope, Plan, $rootScope, Plan, toaster) {
|
653
|
+
|
654
|
+
$scope.selectPlan = function(planName) {
|
655
|
+
var changePlan = confirm("Are you sure you want to switch to " + planName + " plan? ");
|
656
|
+
if (changePlan) {
|
657
|
+
Plan.switchPlan(planName)
|
658
|
+
.success(function(success) {
|
659
|
+
toaster.pop('success', 'Success', 'Plan Changed successfully!')
|
660
|
+
$rootScope.fetchDealer()
|
661
|
+
.success(function(success) {
|
662
|
+
$scope.currentPlan = success.current_plan;
|
663
|
+
})
|
664
|
+
})
|
665
|
+
.error(function(error) {
|
666
|
+
toaster.pop('error', 'Failed', 'Yikes, couldnt make it happen. Try again?')
|
667
|
+
})
|
668
|
+
} else {
|
669
|
+
console.log('will NOT change plan')
|
670
|
+
}
|
671
|
+
}
|
672
|
+
|
673
|
+
}])
|