news: add urls for news entries

This commit is contained in:
rolux 2013-07-11 18:16:31 +00:00
parent 3c64d8ac2d
commit 7efac1756c

View file

@ -10,21 +10,15 @@ pandora.ui.news = function(width, height) {
.css({position: 'absolute', top: '16px', right: '16px', width: '192px'}) .css({position: 'absolute', top: '16px', right: '16px', width: '192px'})
.appendTo(that), .appendTo(that),
backgroundColor = Ox.Theme() == 'oxlight' ? 'rgb(224, 224, 224)' backgroundColor = Ox.Theme() == 'oxlight' ? 'rgb(224, 224, 224)'
: Ox.Theme() == 'oxmedium' ? 'rgb(128, 128, 128)' : 'rgb(32, 32, 32)', : Ox.Theme() == 'oxmedium' ? 'rgb(128, 128, 128)'
: 'rgb(32, 32, 32)',
isEditable = pandora.site.capabilities.canEditSitePages[pandora.user.level], isEditable = pandora.site.capabilities.canEditSitePages[pandora.user.level],
items = [], items = [],
selected,
$text; $text;
pandora.api.getNews({}, function(result) { pandora.api.getNews(function(result) {
items = result.data.items; items = result.data.items;
if (items.length) { selectItem();
selected = items[0].id;
renderItem();
renderList();
} else if (isEditable) {
addItem();
}
}); });
function addItem() { function addItem() {
@ -34,39 +28,45 @@ pandora.ui.news = function(width, height) {
text: '' text: ''
}, function(result) { }, function(result) {
items.splice(0, 0, result.data); items.splice(0, 0, result.data);
selected = result.data.id; pandora.UI.set({'part.news': result.data.id});
renderItem();
renderList();
}); });
} }
function editItem(key, value) { function editItem(key, value) {
var data = {id: selected}, var data = {id: pandora.user.ui.part.news},
index = Ox.getIndexById(items, selected); index = Ox.getIndexById(items, pandora.user.ui.part.news);
if (index == -1) {
index = 0;
}
data[key] = value; data[key] = value;
pandora.api.editNews(data, function(result) { pandora.api.editNews(data, function(result) {
Ox.print('DATA:::', result.data);
items[index] = result.data; items[index] = result.data;
Ox.print('ITEMS:::', items);
['title', 'date'].indexOf(key) > -1 && renderList(); ['title', 'date'].indexOf(key) > -1 && renderList();
}); });
} }
function removeItem() { function removeItem() {
var index = Ox.getIndexById(items, selected); var index = Ox.getIndexById(items, pandora.user.ui.part.news);
if (index == -1) {
index = 0;
}
items.splice(index, 1); items.splice(index, 1);
pandora.api.removeNews({id: selected}, function(result) { pandora.api.removeNews({id: pandora.user.ui.part.news}, function(result) {
// ... pandora.UI.set({
'part.news': items.length == 0 ? ''
: items[Math.min(index, items.length - 1)].id
});
}); });
selected = items[0].id;
renderItem();
renderList();
} }
function renderItem() { function renderItem() {
$left.empty();
var $title, $date, var $title, $date,
index = Ox.getIndexById(items, selected); index = Ox.getIndexById(items, pandora.user.ui.part.news);
if (index == -1) {
index = 0;
}
$left.empty();
if (items.length) {
$title = Ox.Editable({ $title = Ox.Editable({
editable: isEditable, editable: isEditable,
tooltip: isEditable ? pandora.getEditTooltip() : '', tooltip: isEditable ? pandora.getEditTooltip() : '',
@ -128,6 +128,7 @@ pandora.ui.news = function(width, height) {
}) })
.appendTo($left); .appendTo($left);
} }
}
function renderList() { function renderList() {
$right.empty(); $right.empty();
@ -159,6 +160,7 @@ pandora.ui.news = function(width, height) {
items.sort(function(a, b) { items.sort(function(a, b) {
return a.date < b.date ? 1 : a.date > b.date ? -1 : 0; return a.date < b.date ? 1 : a.date > b.date ? -1 : 0;
}).forEach(function(item, i) { }).forEach(function(item, i) {
Ox.print('??', i, item.id)
Ox.Element() Ox.Element()
.addClass('item') .addClass('item')
.css({ .css({
@ -166,7 +168,8 @@ pandora.ui.news = function(width, height) {
padding: '4px 8px 5px 8px', padding: '4px 8px 5px 8px',
borderRadius: '8px', borderRadius: '8px',
margin: '2px', margin: '2px',
backgroundColor: item.id == selected ? backgroundColor : '', backgroundColor: item.id == pandora.user.ui.part.news
? backgroundColor : '',
cursor: 'pointer' cursor: 'pointer'
}) })
.html( .html(
@ -177,16 +180,18 @@ pandora.ui.news = function(width, height) {
) )
.bindEvent({ .bindEvent({
anyclick: function() { anyclick: function() {
selected = item.id; pandora.UI.set('part.news', item.id);
$('.item').css({backgroundColor: 'transparent'});
this.css({backgroundColor: backgroundColor});
renderItem();
} }
}) })
.appendTo($right); .appendTo($right);
}); });
} }
function selectItem() {
renderItem();
renderList();
}
that.resize = function(data) { that.resize = function(data) {
width = data.width; width = data.width;
height = data.height; height = data.height;
@ -194,6 +199,10 @@ pandora.ui.news = function(width, height) {
$text.css({width: width - 512}); $text.css({width: width - 512});
}; };
that.bindEvent({
'pandora_part.news': selectItem
});
return that; return that;
}; };