Skip to content

Commit 4f38218

Browse files
Adding more small fixes
1 parent f9ef23d commit 4f38218

7 files changed

Lines changed: 125 additions & 110 deletions

File tree

backend/web/app/Aisel/Kernel/controllers/abstractDetails.js

Lines changed: 97 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -13,113 +13,116 @@
1313
*/
1414

1515
define(['app'], function (app) {
16-
app.controller('AbstractDetailsCtrl', function ($controller, $scope, $stateParams, itemService, $state, Environment, notify) {
16+
app.controller('AbstractDetailsCtrl',
17+
function ($controller, $scope, $stateParams, itemService, $state, Environment, notify) {
1718

18-
$scope.details = {
19-
id: $stateParams.id,
20-
name: $scope.route.name
21-
};
22-
$scope.item = {};
23-
var locale = Environment.currentLocale();
19+
$scope.details = {
20+
id: $stateParams.id,
21+
name: $scope.route.name
22+
};
2423

25-
var errorNotify = function(data) {
26-
notify('Response:' + data.code + ' Message:' + data.message);
27-
console.log(data);
28-
};
24+
$scope.item = {};
25+
var locale = Environment.currentLocale();
2926

30-
/**
31-
* GET
32-
*/
33-
if ($scope.details.id !== undefined) {
34-
itemService.get($scope.details.id).success(
35-
function (data, status) {
36-
$scope.item = data;
37-
}
38-
).error(function(data, status) {
39-
if (data.error.code == 404) {
40-
$state.transitionTo('home', {locale: locale});
41-
notify('404 Noting found');
42-
console.log(data);
43-
} else {
44-
errorNotify(data);
45-
}
46-
});
47-
};
27+
var errorNotify = function (data) {
28+
notify('Response:' + data.code + ' Message:' + data.message);
29+
console.log(data);
30+
};
4831

49-
/**
50-
* SAVE
51-
*/
52-
$scope.editSave = function () {
53-
// Existent item
32+
/**
33+
* GET
34+
*/
5435
if ($scope.details.id !== undefined) {
55-
itemService.save($scope.item).success(
36+
itemService.get($scope.details.id).success(
5637
function (data, status) {
57-
notify($scope.route.name + ' has been saved');
58-
console.log(data);
38+
$scope.item = data;
5939
}
60-
).error(function(data, status) {
61-
errorNotify(data);
62-
});
40+
).error(function (data, status) {
41+
if (data.error.code == 404) {
42+
$state.transitionTo('home', {locale: locale});
43+
notify('404 Noting found');
44+
console.log(data);
45+
} else {
46+
errorNotify(data);
47+
}
48+
});
6349
}
64-
// New item
65-
if ($scope.details.id === undefined) {
66-
itemService.create($scope.item).success(
50+
;
51+
52+
/**
53+
* SAVE
54+
*/
55+
$scope.editSave = function () {
56+
// Existent item
57+
if ($scope.details.id !== undefined) {
58+
itemService.save($scope.item).success(
59+
function (data, status) {
60+
notify($scope.route.name + ' has been saved');
61+
console.log(data);
62+
}
63+
).error(function (data, status) {
64+
errorNotify(data);
65+
});
66+
}
67+
// New item
68+
if ($scope.details.id === undefined) {
69+
itemService.create($scope.item).success(
70+
function (data, status) {
71+
notify($scope.route.name + ' was added');
72+
$state.transitionTo(
73+
$scope.route.edit,
74+
{locale: Environment.currentLocale(), id: data.id}
75+
);
76+
}
77+
).error(function (data, status) {
78+
errorNotify(data);
79+
});
80+
}
81+
};
82+
83+
/**
84+
* SAVE & EXIT
85+
*/
86+
$scope.editSaveAndExit = function () {
87+
itemService.save($scope.item).success(
6788
function (data, status) {
68-
notify($scope.route.name + ' was added');
89+
notify($scope.route.name + ' has been saved');
6990
$state.transitionTo(
70-
$scope.route.edit,
71-
{locale: Environment.currentLocale(), id: data.id}
91+
$scope.route.collection,
92+
{locale: Environment.currentLocale()}
7293
);
7394
}
74-
).error(function(data, status) {
75-
errorNotify(data);
76-
});
77-
}
78-
};
95+
).error(function (data, status) {
96+
errorNotify(data);
97+
});
98+
};
7999

80-
/**
81-
* SAVE & EXIT
82-
*/
83-
$scope.editSaveAndExit = function () {
84-
itemService.save($scope.item).success(
85-
function (data, status) {
86-
notify($scope.route.name + ' has been saved');
87-
$state.transitionTo(
88-
$scope.route.collection,
89-
{locale: Environment.currentLocale()}
90-
);
91-
}
92-
).error(function(data, status) {
93-
errorNotify(data);
94-
});
95-
};
100+
/**
101+
* CANCEL
102+
*/
103+
$scope.editCancel = function () {
104+
$state.transitionTo(
105+
$scope.route.collection,
106+
{locale: Environment.currentLocale()}
107+
);
108+
};
96109

97-
/**
98-
* CANCEL
99-
*/
100-
$scope.editCancel = function () {
101-
$state.transitionTo(
102-
$scope.route.collection,
103-
{locale: Environment.currentLocale()}
104-
);
105-
};
106-
107-
/**
108-
* DELETE
109-
*/
110-
$scope.editDelete = function () {
111-
itemService.remove($scope.details.id).success(
112-
function (data, status) {
113-
notify($scope.route.name + ' has been deleted');
114-
$state.transitionTo(
115-
$scope.route.collection,
116-
{locale: Environment.currentLocale()}
117-
);
118-
}
119-
).error(function(data, status) {
120-
errorNotify(data);
121-
});
122-
};
110+
/**
111+
* DELETE
112+
*/
113+
$scope.editDelete = function () {
114+
itemService.remove($scope.details.id).success(
115+
function (data, status) {
116+
notify($scope.route.name + ' has been deleted');
117+
$state.transitionTo(
118+
$scope.route.collection,
119+
{locale: Environment.currentLocale()}
120+
);
121+
}
122+
).error(function (data, status) {
123+
errorNotify(data);
124+
});
125+
};
123126

124-
});
127+
});
125128
});

backend/web/app/Aisel/Kernel/controllers/abstractDetailsCategory.js

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,30 @@ define(['app'], function (app) {
2525
itemService.getCategoryTree($scope.item.locale).success(
2626
function (data, status) {
2727
$scope.categories = data;
28-
$scope.setItemCategories();
28+
29+
setItemCategories(
30+
$scope.item,
31+
$scope.categories
32+
);
2933
}
3034
)
3135
});
3236

3337
/**
3438
* Set categories
39+
*
40+
* @param {Object} item
41+
* @param {Object} categories
3542
*/
36-
$scope.setItemCategories = function () {
43+
var setItemCategories = function (item, categories) {
3744
var isAnySelected = false;
3845

3946
var setSelected = function (categories) {
4047
angular.forEach(categories, function (category) {
41-
angular.forEach($scope.item.categories, function (c) {
42-
if (c.id == category.id){
48+
angular.forEach(item.categories, function (c) {
49+
if (c.id == category.id) {
4350
category.selected = true;
44-
//isAnySelected = true;
51+
isAnySelected = true;
4552
}
4653
});
4754
if (category.children) {
@@ -50,33 +57,36 @@ define(['app'], function (app) {
5057
});
5158
};
5259

53-
if ($scope.categories.length) {
60+
if (categories.length) {
5461
setSelected($scope.categories);
5562

5663
if (!isAnySelected) {
57-
$scope.item.categories = [];
64+
item.categories = [];
5865
}
5966
}
6067
};
6168

6269
/**
6370
* Update categories
71+
*
72+
* @param {Object} item
73+
* @param {Object} categories
6474
*/
65-
$scope.updateItemCategories = function () {
66-
$scope.item.categories = [];
75+
$scope.updateItemCategories = function (item, categories) {
76+
item.categories = [];
6777

6878
var findSelectedCategories = function (categories) {
6979
angular.forEach(categories, function (category) {
7080
if (category.selected) {
71-
$scope.item.categories.push(category);
81+
item.categories.push(category);
7282
}
7383
if (category.children) {
7484
findSelectedCategories(category.children)
7585
}
7686
})
7787
};
7888

79-
findSelectedCategories($scope.categories);
89+
findSelectedCategories(categories);
8090
};
8191

8292
});

backend/web/app/Aisel/Kernel/views/edit/field/categories.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
<div class="categoryTree">
22
<script type="text/ng-template" id="field_renderer.html">
3-
<input type="checkbox" ng-model="category.selected" ng-change="updateItemCategories()" > {{ category.title}}
3+
<input type="checkbox"
4+
ng-model="category.selected"
5+
ng-change="updateItemCategories(item, categories)">
6+
{{ category.title}}
47
<ul>
58
<li ng-repeat="category in category.children"
69
ng-include="'field_renderer.html'"></li>

src/Aisel/ProductBundle/spec/Aisel/ProductBundle/Controller/ApiNodeControllerSpec.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
/**
1717
* @author Ivan Proskoryakov <volgodark@gmail.com>
1818
*/
19-
class ApiCategoryControllerSpec extends ObjectBehavior
19+
class ApiNodeControllerSpec extends ObjectBehavior
2020
{
2121
public function it_is_initializable()
2222
{

src/Aisel/ResourceBundle/Entity/AbstractCollectionRepository.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ public function getCollectionFromRequest($params)
179179
/**
180180
* Returns enabled categories sorted as tree
181181
*
182-
* @param string $locale
182+
* @param string $locale
183183
* @param boolean $onlyEnabled
184184
*
185185
* @return array $result

src/Aisel/ResourceBundle/Request/ParamConverter.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@ protected function loadEntity($resolvedClass, $id, $maxDepth = false)
129129
return json_decode($entity, true);
130130
}
131131

132-
133132
return $entity;
134133
}
135134

src/Aisel/ResourceBundle/Tests/AbstractWebTestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public function logInBackend($username = 'backenduser', $password = 'backenduser
7575
$content = $response->getContent();
7676
$result = json_decode($content, true);
7777

78-
if ($result['status'] !== true ) {
78+
if ($result['status'] !== true) {
7979
throw new \LogicException('Authentication failed.');
8080
}
8181
}

0 commit comments

Comments
 (0)