This repository has been archived by the owner on Sep 3, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
1,141 additions
and
5 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,192 @@ | ||
(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', | ||
'$modal', | ||
'$scope', | ||
'article', | ||
'modalFactory', | ||
'ArticlesList', | ||
'toaster', | ||
'TranslationService', | ||
function ( | ||
$q, | ||
$modal, | ||
$scope, | ||
articleService, | ||
modalFactory, | ||
ArticlesList, | ||
toaster, | ||
TranslationService) { | ||
var self = this, | ||
article = articleService.articleInstance; | ||
|
||
// retrieve all articlesLists assigned to the article | ||
self.assignedArticlesLists = ArticlesList.getAllByArticle( | ||
article.articleId, article.language | ||
); | ||
|
||
$scope.$on('close-articles-lists-modal', function(event) { | ||
ArticlesList.getAllByArticle( | ||
article.articleId, article.language | ||
).$promise.then(function (data) { | ||
// removes list from assignedArticlesLists | ||
// if the list doesn't exist in the response data | ||
angular.forEach( | ||
self.assignedArticlesLists, | ||
function (value, key) { | ||
if (!_.some(data, {id: value.id})) { | ||
_.remove( | ||
self.assignedArticlesLists, | ||
{id: value.id} | ||
); | ||
} | ||
} | ||
); | ||
|
||
// adds a new list to assignedArticlesLists | ||
// if it does't exist already | ||
angular.forEach(data, function(value, key) { | ||
if (!_.some( | ||
self.assignedArticlesLists, | ||
{id: value.id} | ||
)) { | ||
self.assignedArticlesLists.push(value); | ||
} | ||
}); | ||
}); | ||
}); | ||
|
||
/** | ||
* Open iframe to the articles lists editor in newscoop admin. | ||
* | ||
* @method openArticlesListsEditor | ||
*/ | ||
self.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.languageData.id, | ||
action: action, | ||
articlesListId: articlesListId | ||
}; | ||
} | ||
} | ||
}); | ||
}; | ||
|
||
/** | ||
* 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 | ||
*/ | ||
self.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( | ||
self.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); | ||
}; | ||
} | ||
]); | ||
|
||
}()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
'use strict'; | ||
|
||
/** | ||
* A factory which creates an article articlesList model. | ||
* | ||
* @class ArticlesList | ||
*/ | ||
angular.module('authoringEnvironmentApp').factory('ArticlesList', [ | ||
'$http', | ||
'$q', | ||
function ( | ||
$http, | ||
$q) { | ||
var ArticlesList = function () {}; // articlesList constructor | ||
|
||
/** | ||
* Converts raw data object to a ArticlesList instance. | ||
* | ||
* @method createFromApiData | ||
* @param data {Object} raw object containing articlesList data | ||
* @return {Object} created ArticlesList instance | ||
*/ | ||
ArticlesList.createFromApiData = function (data) { | ||
var articlesList = new ArticlesList(); | ||
|
||
articlesList.id = parseInt(data.id); | ||
articlesList.title = data.title; | ||
articlesList.notes = (data.notes) ? data.notes : null; | ||
articlesList.maxItems = | ||
(data.maxItems) ? parseInt(data.maxItems) : null; | ||
articlesList.text = articlesList.title; | ||
|
||
return articlesList; | ||
}; | ||
|
||
/** | ||
* Retrieves a list of all articlesLists assigned to a specific article. | ||
* | ||
* Initially, an empty array is returned, which is later filled with | ||
* data on successful server response. At that point the given promise | ||
* is resolved (exposed as a $promise property of the returned array). | ||
* | ||
* @method getAllByArticle | ||
* @param number {Number} article ID | ||
* @param language {String} article language code, e.g. 'de' | ||
* @return {Object} array of article articlesLists | ||
*/ | ||
ArticlesList.getAllByArticle = function (number, language) { | ||
var articlesLists = [], | ||
deferredGet = $q.defer(), | ||
url; | ||
|
||
articlesLists.$promise = deferredGet.promise; | ||
|
||
url = Routing.generate( | ||
'newscoop_gimme_articles_getarticle_language_playlists', | ||
{number: number, language: language}, | ||
true | ||
); | ||
|
||
$http.get(url) | ||
.success(function (response) { | ||
response.items.forEach(function (item) { | ||
item = ArticlesList.createFromApiData(item); | ||
articlesLists.push(item); | ||
}); | ||
deferredGet.resolve(articlesLists); | ||
}).error(function (responseBody) { | ||
deferredGet.reject(responseBody); | ||
}); | ||
|
||
return articlesLists; | ||
}; | ||
|
||
/** | ||
* Unassignes articlesList from article. | ||
* | ||
* @method removeFromArticle | ||
* @param number {Number} article ID | ||
* @param language {String} article language code (e.g. 'de') | ||
* @return {Object} promise object that is resolved on successful server | ||
* response and rejected on server error response | ||
*/ | ||
ArticlesList.prototype.removeFromArticle = function( | ||
number, | ||
language, | ||
articlesList) { | ||
var deferred = $q.defer(), | ||
linkHeader; | ||
|
||
linkHeader = [ | ||
'<', | ||
Routing.generate( | ||
'newscoop_gimme_articles_getarticle', | ||
{number: number, language: language}, | ||
false | ||
), | ||
'; rel="article">' | ||
].join(''); | ||
|
||
$http({ | ||
url: Routing.generate( | ||
'newscoop_gimme_articles_lists_unlinkarticle', | ||
{id: articlesList.id}, | ||
true | ||
), | ||
method: 'UNLINK', | ||
headers: {link: linkHeader} | ||
}) | ||
.success(function () { | ||
deferred.resolve(); | ||
}) | ||
.error(function (responseBody) { | ||
deferred.reject(responseBody); | ||
}); | ||
|
||
return deferred.promise; | ||
}; | ||
|
||
return ArticlesList; | ||
} | ||
]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.