Skip to content

Commit

Permalink
improvements to topics
Browse files Browse the repository at this point in the history
  • Loading branch information
takeit committed Nov 25, 2014
1 parent 81dbef5 commit 837f11b
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ public function addAction(Request $request)
'status' => true,
'message' => $translator->trans('topics.added', array(), 'topics'),
'topicId' => $node->getId(),
'topicTitle' => $node->getTitle()
'topicTitle' => $node->getTitle(),
'locale' => $request->getLocale()
);
} else {
$response = array(
Expand Down
18 changes: 18 additions & 0 deletions newscoop/src/Newscoop/NewscoopBundle/Form/Type/TopicType.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,24 @@ public function buildForm(FormBuilderInterface $builder, array $options)
),
'error_bubbling' => true
));
$builder->add('locale', null, array(
'required' => false,
'constraints' => array(
new Assert\Length(array(
'max' => 5,
))
),
'error_bubbling' => true
));
$builder->add('lastLocale', null, array(
'required' => false,
'constraints' => array(
new Assert\Length(array(
'max' => 5,
))
),
'error_bubbling' => true
));
$builder->add('description', 'textarea', array('required' => false));
$builder->add('parent', null, array('required' => false));
}
Expand Down
48 changes: 43 additions & 5 deletions newscoop/src/Newscoop/NewscoopBundle/Resources/public/js/tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,35 @@ app.controller('treeCtrl', function($scope, TopicsFactory, $filter) {
}
};

var updateAfterAddSubtopic = function (children, id, response) {
if (children) {
for (var i = 0; i < children.length; i++) {
if (children[i].id == id) {
if (children[i].__children == undefined) {
console.log(children[i]);
children[i]['__children'] = [{id: response.topicId, locale: response.locale, title: response.topicTitle }];
children[i]['__children'][0]['translations'] = [{locale: response.locale, field: "title", content: response.topicTitle }];
} else {
console.log(children[i].__children);
children[i].__children.push({
id: response.topicId,
locale: response.locale,
title: response.topicTitle,
translations: [{locale: response.locale, field: "title", content: response.topicTitle }]
});
//children[i].__children.translations.push([{locale: response.locale, field: "title", content: response.topicTitle }]);
}
return children[i];
}

var found = updateAfterAddSubtopic(children[i].__children, id, response);
if (found) {
return found;
}
}
}
};

var removeTopicId = null;
$scope.removeTopicAlert = function(topicId) {
removeTopicId = topicId;
Expand All @@ -138,8 +167,9 @@ app.controller('treeCtrl', function($scope, TopicsFactory, $filter) {
$scope.removeTopic = function() {
TopicsFactory.deleteTopic(removeTopicId).success(function (response) {
if (response.status) {
$('#removeAlert').modal('hide');
flashMessage(response.message);
updateList($scope.data, topicId);
updateList($scope.data, removeTopicId);
} else {
flashMessage(response.message, 'error');
}
Expand Down Expand Up @@ -192,22 +222,30 @@ app.controller('treeCtrl', function($scope, TopicsFactory, $filter) {
$scope.subtopicForm = {};
$scope.addNewTopic = function(topicId, event) {
var addFormData = {
topic: {
title: $scope.formData.title,
},
topic: {},
_csrf_token: token
}

if (topicId !== undefined) {
addFormData.topic["title"] = $scope.subtopicForm.title;
addFormData.topic["parent"] = topicId;
} else {
addFormData.topic["title"] = $scope.formData.title;
}

TopicsFactory.addTopic(addFormData).success(function (response) {
if (response.status) {
flashMessage(response.message);
if (topicId == undefined) {
$scope.data.push({ id: response.topicId, title: response.topicTitle });
$scope.data.push({
id: response.topicId,
title: response.topicTitle,
root: response.topicId,
translations: [{ content: response.topicTitle, locale: response.locale}]
});

} else {
updateAfterAddSubtopic($scope.data, topicId, response)
}
$scope.formData = null;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
<a data-nodrag ng-click="startEditing(this)" class="pointer"><span title="{{ 'topics.btn.edit'|trans }}" class="glyphicon glyphicon-pencil"></span></a>
<a data-nodrag ng-click="removeTopicAlert(node.id)" data-toggle="modal" data-target="#removeAlert" class="pointer"><span title="{{ 'topics.btn.remove'|trans }}" class="glyphicon glyphicon-trash"></span></a>
</div>
<span ng-if="node.translations.length == 1" ng-bind-html="node.translations[0].content | highlight:pattern | trust" class="ng-binding"></span>
<span ng-if="node.translations.length == 1" ng-bind-html="node.translations[0].content | highlight:pattern | trust" class="ng-binding"></span></span>
<span ng-if="node.translations.length > 1" ng-bind-html="node.title | highlight:pattern | trust" class="ng-binding"></span>
<div class="node-edit-div" data-nodrag ng-show="editing">
<div class="form-group">
Expand Down Expand Up @@ -106,7 +106,7 @@
</div>
</div>
<ul class="list-group" ng-if="!languageCode" ng-model="node.translations">
<li class="list-group-item" ng-repeat="node in node.translations" ng-if="node.locale != '{{ app.request.locale }}'" ng-hide="!treeFilter(node, pattern, supportedFields) && !dim" ng-class="{'filtered-out':!treeFilter(node, pattern, supportedFields) && dim}">
<li class="list-group-item" ng-repeat="node in node.translations" ng-hide="!treeFilter(node, pattern, supportedFields) && !dim" ng-class="{'filtered-out':!treeFilter(node, pattern, supportedFields) && dim}">
<span class="badge" style="float: left;">{[{ node.locale }]}</span>
<span ng-bind-html="node.content | highlight:pattern | trust" class="ng-binding"></span>
<div class="pull-right action-buttons">
Expand All @@ -133,7 +133,7 @@
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">{{ 'topics.btn.close'|trans }}</span></button>
<h4 class="modal-title" id="myModalLabel">{{ 'topics.alerts.beforedelete'|trans }}</h4>
</div>
<div class="modal-body" style="font-size: 14px;">
Expand Down

0 comments on commit 837f11b

Please sign in to comment.