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,99 +28,106 @@ 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);
$title = Ox.Editable({ if (index == -1) {
editable: isEditable, index = 0;
tooltip: isEditable ? pandora.getEditTooltip() : '', }
value: items[index].title $left.empty();
}) if (items.length) {
.css({ $title = Ox.Editable({
display: 'inline-block', editable: isEditable,
fontWeight: 'bold', tooltip: isEditable ? pandora.getEditTooltip() : '',
fontSize: '16px', value: items[index].title
MozUserSelect: 'text', })
WebkitUserSelect: 'text' .css({
}) display: 'inline-block',
.bindEvent({ fontWeight: 'bold',
submit: function(data) { fontSize: '16px',
editItem('title', data.value); MozUserSelect: 'text',
} WebkitUserSelect: 'text'
}) })
.appendTo($left); .bindEvent({
$('<div>').css({height: '2px'}).appendTo($left); submit: function(data) {
$date = Ox.Editable({ editItem('title', data.value);
editable: isEditable, }
format: function(value) { })
return Ox.formatDate(value, '%B %e, %Y'); .appendTo($left);
}, $('<div>').css({height: '2px'}).appendTo($left);
tooltip: isEditable ? pandora.getEditTooltip() : '', $date = Ox.Editable({
value: items[index].date editable: isEditable,
}) format: function(value) {
.css({ return Ox.formatDate(value, '%B %e, %Y');
display: 'inline-block', },
fontSize: '9px', tooltip: isEditable ? pandora.getEditTooltip() : '',
MozUserSelect: 'text', value: items[index].date
WebkitUserSelect: 'text' })
}) .css({
.bindEvent({ display: 'inline-block',
submit: function(data) { fontSize: '9px',
editItem('date', data.value); MozUserSelect: 'text',
} WebkitUserSelect: 'text'
}) })
.appendTo($left); .bindEvent({
$('<div>').css({height: '8px'}).appendTo($left); submit: function(data) {
$text = Ox.Editable({ editItem('date', data.value);
clickLink: pandora.clickLink, }
editable: isEditable, })
maxHeight: height - 96, .appendTo($left);
placeholder: Ox._('No text'), $('<div>').css({height: '8px'}).appendTo($left);
tooltip: isEditable ? pandora.getEditTooltip() : '', $text = Ox.Editable({
type: 'textarea', clickLink: pandora.clickLink,
value: items[index].text, editable: isEditable,
width: width - 512 maxHeight: height - 96,
}) placeholder: Ox._('No text'),
.css({ tooltip: isEditable ? pandora.getEditTooltip() : '',
MozUserSelect: 'text', type: 'textarea',
WebkitUserSelect: 'text' value: items[index].text,
}) width: width - 512
.bindEvent({ })
submit: function(data) { .css({
editItem('text', data.value); MozUserSelect: 'text',
} WebkitUserSelect: 'text'
}) })
.appendTo($left); .bindEvent({
submit: function(data) {
editItem('text', data.value);
}
})
.appendTo($left);
}
} }
function renderList() { function renderList() {
@ -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;
}; };