(
/**
* Contains the functionalities related to the notice board page.
*
* @module notice_board
* @author Joonas Konki
* @author Anu Koskela
* @author Mikko Kuhno
* @author Henrik Paananen
* @author Atte Räty
* @license BSD 3-clause, see LICENSE for more details.
* @copyright 2015 Kepler project authors
*/
function(){
var noticeBoardDiv = null;
/**
* Initialises the notice board content with the given notices.
* @memberof module:notice_board
* @param {object} notes - The notes to be displayed on the notice board.
*/
function initNoticeBoard(notes){
noticeBoardDiv.empty();
for (var i = 0; i < notes.length; i++) {
var note = notes[i];
var createTime = kepler.formatDatetime(note.created_at);
var noteDiv = $('<div>').addClass('list-group-item');
noteDiv.addClass('note');
var noteHeaderDiv = $('<h4>').addClass("list-group-item-heading");
noteHeaderDiv.addClass("note-header");
var titleSpan = $("<span>").text(note.title);
noteHeaderDiv.append(titleSpan);
var noteCreatedSpan = $('<span>').addClass('created-time');
noteCreatedSpan.text(createTime);
noteHeaderDiv.append(noteCreatedSpan);
var creatorSpan = $("<span>").addClass('creator-name');
creatorSpan.text(note.creator);
noteHeaderDiv.append(creatorSpan);
var noteMessageDiv = $('<div>').addClass("list-group-item-text");
noteMessageDiv.addClass('note-message');
noteMessageDiv.append($('<p>').text(note.message));
noteDiv.append(noteHeaderDiv);
noteDiv.append(noteMessageDiv);
if (note.modified_at) {
var modifyTime = kepler.formatDatetime(note.modified_at);
var modifiedDiv = $('<div>').addClass('modify-info');
var modifiedTimeDiv = $('<span>').addClass('modified-time');
modText = kepler.translate('note.last_modified');
modifiedTimeDiv.text(modText + ": " + modifyTime);
modifiedDiv.append(modifiedTimeDiv);
if (note.modifier) {
var modifierDiv = $('<span>').addClass('modifier-name');
modifierDiv.text(note.modifier);
modifiedDiv.append(modifierDiv);
}
noteDiv.append(modifiedDiv);
if (note.modified_at === note.created_at)
modifiedDiv.css('visibility', 'hidden');
}
noticeBoardDiv.append(noteDiv);
}
}
/**
* Updates the notice board view.
* @memberof module:notice_board
*/
function reloadNoticeBoard() {
kepler.getNoticeBoard(function (data) {
initNoticeBoard(data.notes);
});
}
/**
* This is executed after the HTML page has been loaded.
* This is a common procedure of all of the client-side modules to
* initialise the page content.
* @memberof module:notice_board
*/
function doc_ready(){
$("#navNoticeBoard").addClass("active");
noticeBoardDiv = $('#noticeBoard');
reloadNoticeBoard();
}
$(document).ready(doc_ready);
}());