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

Commit

Permalink
Merge e1f14e7 into d9c8a96
Browse files Browse the repository at this point in the history
  • Loading branch information
thnkloud9 committed Sep 7, 2015
2 parents d9c8a96 + e1f14e7 commit 9d10cd9
Show file tree
Hide file tree
Showing 10 changed files with 1,812 additions and 2 deletions.
2 changes: 2 additions & 0 deletions app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,8 @@
<script src="scripts/controllers/editorial-comments.js"></script>
<script src="scripts/directives/editorial-comment.js"></script>
<script src="scripts/services/editorial-comments.js"></script>
<script src="scripts/services/ArticlesList.js"></script>
<script src="scripts/controllers/pane-articles-lists.js"></script>
<!-- endbuild -->
</body>
</html>
204 changes: 204 additions & 0 deletions app/scripts/controllers/pane-articles-lists.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
'use strict';

/**
* AngularJS controller for the ArticlesLists pane.
*
* @class PaneArticlesListsCtrl
*/
angular.module('authoringEnvironmentApp').controller('PaneArticlesListsCtrl', [
'$q',
'$scope',
'article',
'modalFactory',
'ArticlesList',
'toaster',
'TranslationService',
function (
$q,
$scope,
articleService,
modalFactory,
ArticlesList,
toaster,
TranslationService) {
var article = articleService.articleInstance,
// all existing articlesLists to choose from
availableArticlesLists = [],
// avilableArticlesLists initialized yet?
articlesListListRetrieved = false;

$scope.selectedArticlesLists = [];
// articlesList assignment in progress?
$scope.assigningArticlesLists = false;

$scope.select2Options = {
minimumInputLength: 3,
query: ArticlesList.liveSearchQuery
};

$scope.newArticlesList = {
title: ''
};

// retrieve all articlesLists assigned to the article
$scope.assignedArticlesLists = ArticlesList.getAllByArticle(
article.articleId, article.language
);

/**
* Resets all new articlesList form fields and validation errors.
*
* @method clearNewArticlesListForm
*/
$scope.clearNewArticlesListForm = function () {
$scope.newArticlesList.title = '';
$scope.newArticlesList.parentArticlesList = null;
$scope.addArticlesList.articlesListTitle
.$setValidity('duplicate', true);
};

/**
* Clears the list of currently selected articlesLists.
*
* @method clearSelectedArticlesLists
*/
$scope.clearSelectedArticlesLists = function () {
while ($scope.selectedArticlesLists.length > 0) {
$scope.selectedArticlesLists.pop();
}
};

/**
* Finds a list of articlesLists that can be assigned to
* the article based on the search query. ArticlesLists that
* are already selected or assigned to
* the article are excluded from search results.
*
* @method findArticlesLists
* @param query {String} articlesLists search query
* @return {Object} promise object which is resolved with (filtered)
* search results
*/
$scope.findArticlesLists = function (query) {
var deferred = $q.defer(),
ignored = {},
filtered;

// build a list of articlesList IDs to exclude from results
// (i.e. articlesLists that are already selected and/or
// assigned to the article)
$scope.selectedArticlesLists.forEach(function (item) {
ignored[item.id] = true;
});
$scope.assignedArticlesLists.forEach(function (item) {
ignored[item.id] = true;
});

// articlesLists list is long, thus we only retrieve it once
if (!articlesListListRetrieved) {
availableArticlesLists = ArticlesList.getAll(article.language);
}

availableArticlesLists.$promise.then(function () {
articlesListListRetrieved = true;
query = query.toLowerCase();

filtered = _.filter(availableArticlesLists, function (item) {
return (
!(item.id in ignored) &&
item.title.toLowerCase().indexOf(query) >= 0
);
});

deferred.resolve(filtered);
});

return deferred.promise;
};

/**
* Assigns all currently selected articlesLists to the article and
* then clears the selected articlesLists list.
*
* @method assignSelectedToArticle
*/
$scope.assignSelectedToArticle = function () {
$scope.assigningArticlesLists = true;

ArticlesList.addToArticle(
article.articleId,
article.language,
$scope.selectedArticlesLists
).then(function (articlesLists) {
articlesLists.forEach(function (item) {
$scope.assignedArticlesLists.push(item);
});
$scope.clearSelectedArticlesLists();
toaster.add({
type: 'sf-info',
message: TranslationService.trans(
'aes.msgs.articleslists.assign.success'
)
});
}, function () {
toaster.add({
type: 'sf-error',
message: TranslationService.trans(
'aes.msgs.articleslists.assign.error'
)
});
}).finally(function () {
$scope.assigningArticlesLists = false;
});

// XXX: what about errors, e.g. 409 Conflict?
};

/**
* Asks user to confirm unassigning a articlesList from the article
* then unassignes the articlesList, if the action is confirmed.
*
* @method confirmUnassignArticlesList
* @param articlesList {Object} articlesList to unassign
*/
$scope.confirmUnassignArticlesList = function (articlesList) {
var modal,
title,
text;

title = TranslationService.trans(
'aes.msgs.articleslists.unassign.popupHead'
);
text = TranslationService.trans(
'aes.msgs.articleslists.unassign.popup'
);

modal = modalFactory.confirmLight(title, text);

modal.result.then(function () {
return articlesList.removeFromArticle(
article.articleId,
article.language,
articlesList).then(function () {
_.remove(
$scope.assignedArticlesLists,
{id: articlesList.id}
);
toaster.add({
type: 'sf-info',
message: TranslationService.trans(
'aes.msgs.articleslists.unassign.success'
)
});
}, function () {
toaster.add({
type: 'sf-error',
message: TranslationService.trans(
'aes.msgs.articleslists.unassign.error'
)
});
});
}, $q.reject);
};
}
]);
12 changes: 12 additions & 0 deletions app/scripts/localization/translations.js
Original file line number Diff line number Diff line change
Expand Up @@ -358,11 +358,15 @@
Translator.add("aes.label.pinarticle", "Pin article", "messages", "en");
Translator.add("aes.label.switches", "Switches", "messages", "en");
Translator.add("aes.label.topics", "Topics", "messages", "en");
Translator.add("aes.label.articleslists", "Articles Lists", "messages", "en");
Translator.add("aes.label.addtopic", "Add new topic", "messages", "en");
Translator.add("aes.label.selectparent", "select parent topic", "messages", "en");
Translator.add("aes.label.addexistingtopics", "Add existing topic(s)", "messages", "en");
Translator.add("aes.label.addexistingarticleslists", "Add existing articless list(s)", "messages", "en");
Translator.add("aes.label.topicname", "Topic name", "messages", "en");
Translator.add("aes.label.articleslistname", "Articles list name", "messages", "en");
Translator.add("aes.label.assignedtopics", "Assigned Topics", "messages", "en");
Translator.add("aes.label.assignedarticleslists", "Assigned Articles Lists", "messages", "en");
Translator.add("aes.label.customfields", "Custom fields", "messages", "en");
Translator.add("aes.label.nofields", "There are no metadata fields for this type of article", "messages", "en");
Translator.add("aes.label.searchmedia", "Search Media Archive", "messages", "en");
Expand Down Expand Up @@ -570,6 +574,14 @@
Translator.add("aes.msgs.topics.unassign.popup", "Should you change your mind, the topic can always be re-assigned again.", "messages", "en");
Translator.add("aes.msgs.topics.unassign.success", "Topic(s) unassigned successfully.", "messages", "en");
Translator.add("aes.msgs.topics.unassign.error", "Failed to unassign topic(s) from the article.", "messages", "en");
Translator.add("aes.msgs.articleslists.add.success", "The articles list(s) have been added and assigned successfully to this article.", "messages", "en");
Translator.add("aes.msgs.articleslists.add.error", "Failed to add and assign new articles list(s) to the article.", "messages", "en");
Translator.add("aes.msgs.articleslists.assign.success", "The articles list has been assigned successfully to this article", "messages", "en");
Translator.add("aes.msgs.articleslists.assign.error", "Assigning the articles list to this article failed.", "messages", "en");
Translator.add("aes.msgs.articleslists.unassign.popupHead", "Do you really want to unassign this articles list from the article?", "messages", "en");
Translator.add("aes.msgs.articleslists.unassign.popup", "Should you change your mind, the articles list can always be re-assigned again.", "messages", "en");
Translator.add("aes.msgs.articleslists.unassign.success", "Articles List(s) unassigned successfully.", "messages", "en");
Translator.add("aes.msgs.articleslists.unassign.error", "Failed to unassign articles list(s) from the article.", "messages", "en");
Translator.add("aes.msgs.slideshows.unassign.popupHead", "Do you really want to unassign this slideshow from the article?", "messages", "en");
Translator.add("aes.msgs.slideshows.unassign.popup", "Should you change your mind, the slideshow can always be re-assigned again.", "messages", "en");
Translator.add("aes.msgs.slideshows.unassign.success", "Slideshow unassigned successfully.", "messages", "en");
Expand Down
2 changes: 1 addition & 1 deletion app/scripts/routing/fos_js_routes.js

Large diffs are not rendered by default.

Loading

0 comments on commit 9d10cd9

Please sign in to comment.