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

Commit

Permalink
Merge 879ca6b into d9c8a96
Browse files Browse the repository at this point in the history
  • Loading branch information
takeit committed Sep 29, 2015
2 parents d9c8a96 + 879ca6b commit 1ff2097
Show file tree
Hide file tree
Showing 14 changed files with 1,815 additions and 5 deletions.
Binary file modified app/images/side-tab-icons.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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>
278 changes: 278 additions & 0 deletions app/scripts/controllers/pane-articles-lists.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,278 @@
(function () {
'use strict';

/**
* Constructor function for the articles lists modal controller.
*
* @class ModalCtrl
*/
function ModalCtrl($modalInstance, $sce, info, $rootScope) {
var self = this,
url;

switch(info.action) {
case 'edit':
url = [
AES_SETTINGS.API.rootURI,
'/admin/playlists/',
info.articleId,
'/',
info.language,
'/editor-view/', info.articlesListId
].join('');

break;
case 'attach':
url = [
AES_SETTINGS.API.rootURI,
'/admin/playlists/',
info.articleId,
'/',
info.language,
'/editor-view'
].join('');

break;
default:
url = '';
}

self.url = $sce.trustAsResourceUrl(url);

/**
* Closes the modal.
*
* @method close
*/
self.close = function () {
$rootScope.$broadcast('close-articles-lists-modal');
$modalInstance.close();
};
}

/**
* AngularJS controller for the ArticlesLists pane.
*
* @class PaneArticlesListsCtrl
*/
angular.module('authoringEnvironmentApp')
.controller('PaneArticlesListsCtrl', [
'$q',
'$scope',
'$modal',
'article',
'modalFactory',
'ArticlesList',
'toaster',
'TranslationService',
function (
$q,
$scope,
$modal,
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
);

/**
* Open iframe to the articles lists editor in newscoop admin.
*
* @method openArticlesListsEditor
*/
$scope.openArticlesListsEditor = function (
action,
articlesListId
) {
$modal.open({
templateUrl: 'views/modal-articles-lists-editor.html',
controller: ModalCtrl,
controllerAs: 'modalArticlesListsEditorCtrl',
windowClass: 'featuredArticlesModal',
resolve: {
info: function () {
return {
articleId: article.articleId,
language: article.language,
action: action,
articlesListId: articlesListId
};
}
}
});
};

/**
* 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", "Featured 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 an article to the existing list(s)", "messages", "en");
Translator.add("aes.label.topicname", "Topic name", "messages", "en");
Translator.add("aes.label.assignedtopics", "Assigned Topics", "messages", "en");
Translator.add("aes.label.assignedarticleslists", "Assigned Lists", "messages", "en");
Translator.add("aes.label.unassignarticleslist", "Unassign an article from the Featured Articles List", "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 1ff2097

Please sign in to comment.