Remove boilerplate from infoadmin controllers

This commit is contained in:
okalintu
2017-03-30 15:24:08 +03:00
parent 842930b24e
commit f93cb5aad5
3 changed files with 24 additions and 46 deletions
@@ -1,4 +1,4 @@
<div ng-controller="infoadmin_externalimage_create" style="margin-top:20px;">
<div ng-controller="infoadmin_external_image_create" style="margin-top:20px;">
<div>
Create new image. Enter name and full url for any image available in internet (eg. https://i.imgur.com/XXSSqDG.gif)
</div>
+21 -42
View File
@@ -123,43 +123,6 @@ app.controller('infoadmin_ctrl', function($scope, $http, $window, ItemList, Inst
});
ItemList.loadItems();
});
app.controller('infoadmin_externalimage_create', function($scope, $http,ItemList){
$scope.item = {}
$scope.send = function(){
$http.post("/infoscreen/create_external_image", $scope.item).then(ItemList.loadItems)
}
});
app.controller('infoadmin_abbitem_create', function($scope, $http,ItemList){
$scope.item = {}
$scope.send = function(){
$http.post("/infoscreen/create_abbitem", $scope.item).then(ItemList.loadItems)
}
});
app.controller('infoadmin_sossoitem_create', function($scope, $http,ItemList){
$scope.item = {}
$scope.send = function(){
$http.post("/infoscreen/create_sossoitem", $scope.item).then(ItemList.loadItems)
}
});
app.controller('infoadmin_eventitem_create', function($scope, $http,ItemList){
$scope.item = {}
$scope.send = function(){
$http.post("/infoscreen/create_eventitem", $scope.item).then(ItemList.loadItems)
}
});
app.controller('infoadmin_hslitem_create', function($scope, $http,ItemList){
$scope.item = {}
$scope.send = function(){
$http.post("/infoscreen/create_hslitem", $scope.item).then(ItemList.loadItems)
}
});
app.controller('infoadmin_websiteitem_create', function($scope, $http,ItemList){
$scope.item = {}
$scope.send = function(){
$http.post("/infoscreen/create_websiteitem", $scope.item).then(ItemList.loadItems)
}
});
app.controller('infoadmin_image_create', ['$scope', 'Upload', '$timeout',"ItemList", function ($scope, Upload, $timeout,ItemList) {
$scope.send = function(file) {
@@ -182,9 +145,25 @@ app.controller('infoadmin_image_create', ['$scope', 'Upload', '$timeout',"ItemLi
}
}]);
app.controller('infoadmin_apyitem_create', function($scope, $http,ItemList){
$scope.item = {}
$scope.send = function(){
$http.post("/infoscreen/create_apyitem", $scope.item).then(ItemList.loadItems)
function itemGenerator(create_url){
return function($scope, $http, ItemList){
$scope.item = {}
$scope.send = function(){
$http.post(create_url, $scope.item).then(ItemList.loadItems)
}
}
});
}
function controllerGenerator(name){
app.controller("infoadmin_" + name + "_create",
itemGenerator("/infoscreen/create_" + name));
}
var simple_controllers = [
"external_image",
"abbitem",
"sossoitem",
"eventitem",
"hslitem",
"websiteitem",
"apyitem",
];
_.each(simple_controllers, controllerGenerator);
@@ -129,7 +129,7 @@ app.controller('timetableCtrl',
objects=data['data'];
for(var objectIndex in objects){
var stop = objects[objectIndex];
var lineIndex;
for (lineIndex in stop['lines']){
var elem=stop['lines'][lineIndex].split(":");
@@ -165,7 +165,7 @@ app.controller('timetableCtrl',
departure['stop']="A. A. puisto"
var trigger = true;
for (var arrIndex = $scope.arr.length - 1; arrIndex >= 0; arrIndex--) {
if ($scope.arr[arrIndex]['bus'] == departure['bus'] &&
if ($scope.arr[arrIndex]['bus'] == departure['bus'] &&
$scope.arr[arrIndex]['laststop'] == departure['laststop']) {
if ($scope.arr[arrIndex]['dist'] == departure['dist']){
@@ -226,4 +226,3 @@ app.controller('timetableCtrl',
var inter3=$interval(updateTime, 1000);
}
);