Skip to content

Commit

Permalink
Merge pull request #92 from ottemo/develop
Browse files Browse the repository at this point in the history
release 0.9.7
  • Loading branch information
James Vastbinder committed Apr 13, 2015
2 parents c5e034c + 1b49350 commit 4d3f0f8
Show file tree
Hide file tree
Showing 51 changed files with 861 additions and 491 deletions.
106 changes: 101 additions & 5 deletions app/scripts/category/controller/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
"$location",
"$q",
"$categoryApiService",
"$designImageService",
"$dashboardUtilsService",
function ($scope, $routeParams, $location, $q, $categoryApiService, $dashboardUtilsService) {
var categoryId, rememberProducts, oldProducts, getDefaultCategory;
function ($scope, $routeParams, $location, $q, $categoryApiService, $designImageService, $dashboardUtilsService) {
var categoryId, rememberProducts, oldProducts, getDefaultCategory, addImageManagerAttribute;

// Initialize SEO
if (typeof $scope.initSeo === "function") {
Expand All @@ -30,6 +31,24 @@

oldProducts = [];

addImageManagerAttribute = function () {
if(typeof $scope.attributes !== "undefined" && typeof $scope.category._id !== "undefined") {
$scope.attributes.unshift({
Attribute: "image",
Collection: "category",
Default: "",
Editors: "picture_manager",
Group: "Picture",
IsRequired: false,
IsStatic: false,
Label: "Image",
Model: "Category",
Options: "",
Type: "text"
});
}
};

getDefaultCategory = function () {
return {
name: "",
Expand All @@ -51,14 +70,16 @@
$categoryApiService.attributesInfo().$promise.then(function (response) {
var result = response.result || [];
$scope.attributes = result;
addImageManagerAttribute();
});

if (null !== categoryId) {
$categoryApiService.getCategory({"id": categoryId}).$promise.then(function (response) {
$categoryApiService.getCategory({"categoryID": categoryId}).$promise.then(function (response) {
var result = response.result || {};
$scope.category = result;
rememberProducts();
$scope.category.parent = $scope.category['parent_id'];
addImageManagerAttribute();
});
}

Expand Down Expand Up @@ -139,8 +160,8 @@

if (-1 === getProductIds($scope.category.products).indexOf(oldProdId)) {
$categoryApiService.removeProduct({
categoryId: categoryId,
productId: oldProdId
categoryID: categoryId,
productID: oldProdId
}).$promise.then(function () {
removeDefer.resolve(index);
}
Expand Down Expand Up @@ -183,6 +204,7 @@
if (response.error === null) {
$scope.category = response.result || getDefaultCategory();
$scope.message = $dashboardUtilsService.getMessage(null, 'success', 'Category was created successfully');
addImageManagerAttribute();
defer.resolve(true);
}
$('[ng-click="save()"]').removeClass('disabled').children('i').remove();
Expand Down Expand Up @@ -255,6 +277,80 @@
}
};

//-----------------
// IMAGE FUNCTIONS
//-----------------
$scope.reloadImages = function () {
if ($scope.category !== undefined && $scope.category._id !== undefined) {
// taking media patch for new category
$categoryApiService.getImagePath({"categoryID": $scope.category._id}).$promise.then(
function (response) {
$scope.imagesPath = response.result || "";
});
// taking registered images for category
$categoryApiService.listImages({"categoryID": $scope.category._id}).$promise.then(
function (response) {
$scope.productImages = response.result || [];
});
$scope.category['default_image'] = $scope.category['image'];
}
};
$scope.$watch("category", function () {
$scope.reloadImages();
});
/**
* Adds file to category
*
* @param fileElementId
*/
$scope.imageAdd = function (fileElementId) {
var file = document.getElementById(fileElementId);
var pid = $scope.category._id, mediaName = file.files[0].name;
var postData = new FormData();
postData.append("file", file.files[0]);
if (pid !== undefined) {
$categoryApiService.addImage({"categoryID": pid, "mediaName": mediaName}, postData)
.$promise.then(function () {
$scope.reloadImages();
});
}
};
/**
* Removes image from category (from category folder) and sends request to saves
*
* @param {string} selected - image name
*/
$scope.imageRemove = function (selected) {
var pid = $scope.category._id, mediaName = selected;
if (pid !== undefined && selected !== undefined) {
$categoryApiService.removeImage({"categoryID": pid, "mediaName": mediaName})
.$promise.then(function () {
$scope.selectedImage = undefined;
$scope.reloadImages();
$scope.category['image'] = "";
$scope.save();
});
}
};
/**
* Sets image as image default
*
* @param {string} selected - image name
*/
$scope.imageDefault = function (selected) {
$scope.category['image'] = selected;
};
/**
* Returns full path to image
*
* @param {string} path - the destination path to category folder
* @param {string} image - image name
* @returns {string} - full path to image
*/
$scope.getImage = function (image) {
return $designImageService.getFullImagePath("", image);
};

}
]
);
Expand Down
16 changes: 11 additions & 5 deletions app/scripts/category/controller/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,28 @@
"$categoryApiService",
"COUNT_ITEMS_PER_PAGE",
function ($scope, $location, $routeParams, $q, DashboardListService, $categoryApiService, COUNT_ITEMS_PER_PAGE) {
var serviceList, getCategoriesList, getCategoryCount, getAttributeList;
var serviceList, getCategoriesList, getCategoryCount, getAttributeList, showColumns;

// Initialize SEO
if (typeof $scope.initSeo === "function") {
$scope.initSeo("category");
}

serviceList = new DashboardListService();
showColumns = {
'name' : {'type' : 'select-link', 'label' : 'Name'},
'enabled' : {}
};

$scope.idsSelectedRows = {};

/**
* Gets list of categories
*/
getCategoriesList = function () {
$categoryApiService.categoryList($location.search(), {"extra": serviceList.getExtraFields()}).$promise.then(
var params = $location.search();
params["extra"] = serviceList.getExtraFields();
$categoryApiService.categoryList(params).$promise.then(
function (response) {
var result, i;
$scope.categoriesTmp = [];
Expand All @@ -43,7 +49,7 @@
* Gets count of categories
*/
getCategoryCount = function () {
$categoryApiService.getCount($location.search(), {}).$promise.then(
$categoryApiService.getCount($location.search()).$promise.then(
function (response) {
if (response.error === null) {
$scope.count = response.result;
Expand All @@ -61,7 +67,7 @@
serviceList.init('categories');
$scope.attributes = result;
serviceList.setAttributes($scope.attributes);
$scope.fields = serviceList.getFields();
$scope.fields = serviceList.getFields(showColumns);
getCategoriesList();
}
);
Expand Down Expand Up @@ -109,7 +115,7 @@
_remove = function (id) {
var defer = $q.defer();

$categoryApiService.remove({"id": id},
$categoryApiService.remove({"categoryID": id},
function (response) {
if (response.result === "ok") {
defer.resolve(id);
Expand Down
71 changes: 43 additions & 28 deletions app/scripts/category/service/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,68 +10,83 @@
* $productApiService interaction service
*/
.service("$categoryApiService", ["$resource", "REST_SERVER_URI", function ($resource, REST_SERVER_URI) {

var categoryBaseURL = REST_SERVER_URI + "/category";

return $resource(categoryBaseURL, {}, {
return $resource(REST_SERVER_URI, {}, {
"attributesInfo": {
method: "GET",
url: categoryBaseURL + "/attribute/list"
url: REST_SERVER_URI + "/categories/attributes"
},
"getCategory": {
method: "GET",
params: { id: "@id" },
url: categoryBaseURL + "/get/:id"
url: REST_SERVER_URI + "/category/:categoryID"
},
"categoryList": {
method: "POST",
url: categoryBaseURL + "/list"
method: "GET",
url: REST_SERVER_URI + "/categories"
},
"getCount": {
method: "GET",
url: categoryBaseURL + "/count"
params: { action: "count" },
url: REST_SERVER_URI + "/categories"
},
"save": {
method: "POST",
url: categoryBaseURL + "/create"
url: REST_SERVER_URI + "/category"
},
"remove": {
method: "DELETE",
params: { id: "@id" },
url: categoryBaseURL + "/delete/:id"
url: REST_SERVER_URI + "/category/:categoryID"
},
"update": {
method: "PUT",
params: { id: "@id" },
url: categoryBaseURL + "/update/:id"
params: { categoryID: "@id" },
url: REST_SERVER_URI + "/category/:categoryID"
},
"getImage": {
method: "GET",
url: REST_SERVER_URI + "/category/:categoryID/media/image/:mediaName"
},
"getImagePath": {
method: "GET",
url: REST_SERVER_URI + "/category/:categoryID/mediapath/image"
},
"listImages": {
method: "GET",
url: REST_SERVER_URI + "/category/:categoryID/media/image"
},
"removeImage": {
method: "DELETE",
url: REST_SERVER_URI + "/category/:categoryID/media/image/:mediaName"
},
"addImage": { // http://stackoverflow.com/questions/13963022/angularjs-how-to-implement-a-simple-file-upload-with-multipart-form
method: "POST",
params: { categoryID: "@categoryId", mediaName: "@mediaName" },
url: REST_SERVER_URI + "/category/:categoryID/media/image/:mediaName",

headers: {"Content-Type": undefined },
transformRequest: angular.identity // jshint ignore:line
},

// Products
"addProduct": {
method: "GET",
method: "POST",
params: {
categoryId: "@categoryId",
productId: "@productId"
categoryID: "@categoryId",
productID: "@productId"
},
url: categoryBaseURL + "/product/add/:categoryId/:productId"
url: REST_SERVER_URI + "/category/:categoryID/product/:productID"
},
"removeProduct": {
method: "GET",
params: {
categoryId: "@categoryId",
productId: "@productId"
},
url: categoryBaseURL + "/product/remove/:categoryId/:productId"
method: "DELETE",
url: REST_SERVER_URI + "/category/:categoryID/product/:productID"
},
"getProducts": {
method: "GET",
params: {id: "@id"},
url: categoryBaseURL + "/product/:id"
url: REST_SERVER_URI + "/category/:categoryID/products"
}
});
}]);

return productModule;
});

})(window.define);
})(window.define);
2 changes: 1 addition & 1 deletion app/scripts/cms/controller/blockEdit.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
);

if (null !== blockId) {
$cmsApiService.blockGet({"id": blockId}).$promise.then(
$cmsApiService.blockGet({"blockID": blockId}).$promise.then(
function (response) {
var result = response.result || {};
$scope.block = result;
Expand Down
17 changes: 12 additions & 5 deletions app/scripts/cms/controller/blockList.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,23 @@
"$cmsApiService",
"COUNT_ITEMS_PER_PAGE",
function ($scope, $location, $routeParams, $q, DashboardListService, $cmsApiService, COUNT_ITEMS_PER_PAGE) {
var serviceList, getBlockCount, getAttributeList, getBlocksList;
var serviceList, getBlockCount, getAttributeList, getBlocksList, showColumns;
serviceList = new DashboardListService();
showColumns = {
'identifier' : {'type' : 'select-link', 'label' : 'Name'},
'created_at' : {'label' : 'Creation Date'},
'updated_at' : {'label' : 'Last Updated'}
};

$scope.idsSelectedRows = {};

/**
* Gets list of blocks
*/
getBlocksList = function () {
$cmsApiService.blockListP($location.search(), {"extra": serviceList.getExtraFields()}).$promise.then(
var params = $location.search();
params["extra"] = serviceList.getExtraFields();
$cmsApiService.blockList(params).$promise.then(
function (response) {
var result, i;
$scope.blocksTmp = [];
Expand All @@ -37,7 +44,7 @@
* Gets list of blocks
*/
getBlockCount = function () {
$cmsApiService.getCountB($location.search(), {}).$promise.then(
$cmsApiService.blockCount($location.search()).$promise.then(
function (response) {
if (response.error === null) {
$scope.count = response.result;
Expand All @@ -55,7 +62,7 @@
serviceList.init('blocks');
$scope.attributes = result;
serviceList.setAttributes($scope.attributes);
$scope.fields = serviceList.getFields();
$scope.fields = serviceList.getFields(showColumns);
getBlocksList();
}
);
Expand Down Expand Up @@ -101,7 +108,7 @@
_remove = function (id) {
var defer = $q.defer();

$cmsApiService.blockRemove({"id": id},
$cmsApiService.blockRemove({"blockID": id},
function (response) {
if (response.result === "ok") {
defer.resolve(id);
Expand Down
2 changes: 1 addition & 1 deletion app/scripts/cms/controller/pageEdit.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
);

if (null !== pageId) {
$cmsApiService.pageGet({"id": pageId}).$promise.then(
$cmsApiService.pageGet({"pageID": pageId}).$promise.then(
function (response) {
var result = response.result || {};
$scope.page = result;
Expand Down
Loading

0 comments on commit 4d3f0f8

Please sign in to comment.