|
var relatedTasks = angular.module('ssc.relatedTasks', ['SeamlessContent']); |
|
|
|
/** |
|
* Outer 'relatedTasks' directive collects content definitions from its child 'relatedTask' directives |
|
* and in a single request to SeamlessContent gets all content for each task. |
|
* |
|
* <related-tasks type='optional-template-name'> |
|
* <related-task url='Seamless-CMS-URL'>optional description text</related-task> |
|
* <related-task url='Seamless-CMS-URL'>optional description text</related-task> |
|
* </related-tasks> |
|
* |
|
* |
|
*/ |
|
relatedTasks.directive('relatedTasks', ['SeamlessContent', |
|
|
|
function(SeamlessContent){ |
|
|
|
return { |
|
restrict:'AE', |
|
transclude: true, |
|
scope:{}, |
|
templateUrl:'/files/templates/1dcdb6f6-1c5c-4d1f-95cc-8526ead6372d/6b0c5a11-02a2-4536-a886-a2e0612cff58/related-tasks.view.html', |
|
link: function postLink(scope, element, attrs){ |
|
|
|
var fields, |
|
jsonData = [] |
|
|
|
scope.type = attrs.type || 'default'; |
|
|
|
//Select the directive template based on the 'type' attribute of relatedTasks |
|
scope.getTemplate = function(){ |
|
|
|
var type = attrs.type || 'default'; |
|
|
|
//If the specified template type doesn't exist, or it is default |
|
if(!templates[type] || templates[type] == 'default'){ |
|
|
|
return '"' + templates.default + '"'; |
|
|
|
}else{ |
|
|
|
return templates[type]; |
|
} |
|
|
|
}; |
|
|
|
//An array to hold the web service results |
|
scope.results = []; |
|
|
|
//Data request object for the SeamlessContent service |
|
fields = [ |
|
{ "FieldName": "TextArea - Summary", "FieldValue": "" }, |
|
{ "FieldName": "Option - Report It Types", "FieldValue": "" }, |
|
{ "FieldName": "WYSIWYG - Form", "FieldValue": "" }, |
|
{ "FieldName": "WYSIWYG - Body", "FieldValue": "" }, |
|
{ "FieldName": "Link - Form", "FieldValue": "" }, |
|
{ "FieldName": "Text - Reference Number", "FieldValue": "" }, |
|
]; |
|
|
|
//Get object information from Seamless |
|
SeamlessContent.get(scope.items, fields, function(result){ |
|
|
|
//Save content to scope |
|
scope.results = result; |
|
|
|
_.each(scope.result, function(item){ |
|
|
|
if(scope.itemsData[item.PageName].summary){ |
|
|
|
item.TextAreaSummary = scope.itemsData[item.PageName].summary; |
|
|
|
} |
|
|
|
if(scope.itemsData[item.PageName].linkText){ |
|
|
|
item.TextReferenceNumber = scope.itemsData[item.PageName].linkText; |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
}, |
|
controller: function($scope, $element, $attrs){ |
|
|
|
//If $scope.items doesn't exist yet, make it an array |
|
$scope.items = $scope.items || []; |
|
|
|
$scope.itemsData = $scope.itemsData || {}; |
|
|
|
this.addItem = function(item){ |
|
|
|
$scope.items.push(item); |
|
|
|
}; |
|
|
|
this.addItemData = function(id, data){ |
|
|
|
$scope.itemsData[id] = data; |
|
|
|
}; |
|
|
|
} |
|
|
|
}; |
|
|
|
} |
|
|
|
]); |
|
|
|
sscAngular.directive('relatedTask', [ |
|
|
|
function(){ |
|
|
|
return { |
|
restrict:'AE', |
|
require:'^relatedTasks', |
|
transclude:true, |
|
template:'<span ng-transclude></span>', |
|
link: function(scope, element, attrs, relatedTasksCtrl){ |
|
|
|
var pageName = attrs.url.replace('http://cmstest.ssc.nsw.gov.au/','$1dcdb6f6-1c5c-4d1f-95cc-8526ead6372d$/'); |
|
|
|
relatedTasksCtrl.addItem(pageName); |
|
relatedTasksCtrl.addItemData(pageName, {'summary': element[0].innerText}); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
]); |