Skip to content
This repository has been archived by the owner on Sep 16, 2021. It is now read-only.

Commit

Permalink
Sekce produkty
Browse files Browse the repository at this point in the history
  • Loading branch information
JakubMrozek committed Aug 3, 2013
1 parent 13df10a commit 9c437db
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 18 deletions.
5 changes: 5 additions & 0 deletions apiary.apib
Expand Up @@ -572,6 +572,11 @@ PUT /products/{id}/images
< Content-Type: application/json


Odstranění produktu s ID {id}
DELETE /products/{id}
< 204


--
Parametry
--
Expand Down
15 changes: 13 additions & 2 deletions public/js/controllers/ProductDetail.js
@@ -1,4 +1,4 @@
angular.module('zdrojak.controller').controller('ProductDetailCtrl', ['$scope', '$routeParams', '$window', 'api', 'uploadFile', function($scope, $routeParams, $window, api, uploadFile) {
angular.module('zdrojak.controller').controller('ProductDetailCtrl', ['$scope', '$routeParams', '$location', '$window', 'api', 'uploadFile', function($scope, $routeParams, $location, $window, api, uploadFile) {
$scope.imgs = [];
$scope.progress = 0;
$scope.product = api.product.show({id: $routeParams.id});
Expand Down Expand Up @@ -41,6 +41,17 @@ angular.module('zdrojak.controller').controller('ProductDetailCtrl', ['$scope',

$scope.pbar = true;
api.product.upload({id: $routeParams.id, upload: upload}, complete, error, cancel, progress);
}
};

$scope.update = function() {
api.product.update({id: $routeParams.id}, $scope.product);
};

$scope.remove = function() {
if (!window.confirm('Chcete skutečně produkt smazat?')) return;
api.product.remove({id: $routeParams.id}, function(){
$location.url('/admin/products');
});
};

}]);
37 changes: 31 additions & 6 deletions public/js/directives/inline.js
Expand Up @@ -23,6 +23,10 @@ function inlineFactory(template) {
var content;
var updated;

scope.command = function(command, text) {
document.execCommand (command, false, text);
};

function send(e) {
var newContent = element.text().trim();
if (newContent !== '') {
Expand Down Expand Up @@ -60,9 +64,6 @@ function inlineFactory(template) {
}


/**
* <inline model='page.text' action='update'/>
*/

angular.module('zdrojak.directive').directive('inline', inlineFactory(
'<span>' +
Expand All @@ -71,13 +72,37 @@ angular.module('zdrojak.directive').directive('inline', inlineFactory(
'</span>'
));

/**
* <inline model='page.text' action='update'/>
*/


angular.module('zdrojak.directive').directive('inlineSelect', inlineFactory(
'<span>' +
'<span ng-hide="mode">{{options[model]}}</span>' +
'<select ng-model="model" ng-show="mode" ng-options="k as v for (k,v) in options" required></select>' +
'</span>'
));

/**
* <inline model='page.text' action='update'/>
*/

angular.module('zdrojak.directive').directive('inlineTextarea', inlineFactory(
'<span>' +
'<span ng-hide="mode">{{model}}</span>' +
'<textarea ng-show="mode" ng-model="model" required></textarea>' +
'</span>'
));



angular.module('zdrojak.directive').directive('inlineWysiwyg', inlineFactory(
'<span>' +
'<span ng-hide="mode" ng-bind-html-unsafe="model"></span>' +
'<div ng-show="mode">' +
'<p>' +
'<button ng-click="command(\'bold\')" style="font-weight:bold">B</button>' +
'<button ng-click="command(\'italic\')" style="font-style: italic">I</button>' +
'</p>' +
'<div contenteditable="true" ng-bind-html-unsafe="model"></div>' +
'</div>' +
'</span>'
));
29 changes: 19 additions & 10 deletions public/partials/admin/product-detail.html
Expand Up @@ -5,31 +5,38 @@ <h1>{{product.name}}</h1>
<tbody>
<tr>
<th>Kód</th>
<td>{{product.code}}</td>
</tr>
<tr>
<th>URL</th>
<td>{{product.url}}</td>
<td><inline model='product.code' action='update'></inline></td>
</tr>
<tr>
<th>Perex</th>
<td>{{product.perex}}</td>
<td><inline-textarea model='product.perex' action='update'></inline-textarea></td>
</tr>
<tr>
<th>Text</th>
<td ng-bind-html-unsafe="product.text"></td>
<td><inline-wysiwyg model='product.text' action='update'></inline-wysiwyg>
</td>
</tr>
<tr>
<th>Cena</th>
<td>{{product.price | currency}}</td>
<td><inline model='product.price' action='update'></inline></td>
</tr>
<tr>
<th>DPH</th>
<td>{{product.dph}}%</td>
<td><inline model='product.dph' action='update'></inline>%</td>
</tr>
</tbody>
</table>

<hr>

<table class="table table-striped">
<tr ng-repeat="parameter in product.parameters">
<th> {{parameter.name}} </th>
<td> {{parameter.values | join: ' / '}} </td>
</tr>
</table>


</div>
<div class="span4 well">
<h3>Obrázky</h3>
Expand All @@ -47,4 +54,6 @@ <h3>Obrázky</h3>
</div>
</div>
</div>
</div>
</div>

<p><a class="btn" ng-click="remove()">Smazat</a></p>
16 changes: 16 additions & 0 deletions test/frontend/apiary.js
Expand Up @@ -446,6 +446,22 @@ var apiary = [
"body": ""
}
]
},
{
"description": "Odstranění produktu s ID {id}",
"method": "DELETE",
"url": "/products/{id}",
"request": {
"headers": {},
"body": ""
},
"responses": [
{
"status": 204,
"headers": {},
"body": ""
}
]
}
]
},
Expand Down

0 comments on commit 9c437db

Please sign in to comment.