call home

This commit is contained in:
j 2017-02-09 03:50:27 +00:00
parent 71d72c611d
commit dc5fd74d9f
4 changed files with 141 additions and 346 deletions

View file

@ -81,7 +81,7 @@ class Item(models.Model):
'index': self.index, 'index': self.index,
} }
j.update(self.data) j.update(self.data)
if 'contentid' in j and (not keys or 'content' in keys): if 'contentid' in j:
content_keys = [ content_keys = [
'description', 'description',
'modified', 'modified',

View file

@ -394,17 +394,7 @@ pandora.ui.home = function() {
} }
function getHTML(item) { function getHTML(item) {
if (item.type == 'custom') { return '<b>' + Ox.encodeHTMLEntities(item.title) + '</b><br><br>' + item.text;
return '<b>' + item.title + '</b><br><br>' + item.text;
}
return '<b>'
+ (
(lists && edits) || (lists && texts) || (edits && texts)
? Ox._(Ox.toTitleCase(item.type)) + ': '
: ''
)
+ Ox.encodeHTMLEntities(item.title) + '</b><br><br>'
+ item.text;
} }
function getTooltip(item) { function getTooltip(item) {

View file

@ -289,321 +289,122 @@ pandora.ui.home = function() {
sort: [{key: 'position', operator: '+'}] sort: [{key: 'position', operator: '+'}]
}, },
items, lists, edits, texts; items, lists, edits, texts;
pandora.api.findLists(find, function(result) { pandora.api.getHomeItems({active: true}, function(result) {
lists = result.data.items.length; items = result.data.items;
items = result.data.items.map(function(item) { lists = 1;
return Ox.extend(item, {type: 'list'}); edits = 1;
}); texts = 1;
pandora.api.findEdits(find, function(result) { show();
edits = result.data.items.length;
items = items.concat(result.data.items.map(function(item) {
return Ox.extend(item, {type: 'edit'});
}));
pandora.api.findTexts(find, function(result) {
texts = result.data.items.length;
items = items.concat(result.data.items.map(function(item) {
return Ox.extend(item, {type: 'text'});
}));
$features.empty();
show();
});
});
}); });
function show() { function show() {
var counter = 0, max = 8, mouse = false, position = 0, selected = 0, var counter = 0, max = 8, mouse = false, position = 0, selected = 0,
color = Ox.Theme() == 'oxlight' ? 'rgb(0, 0, 0)' color = Ox.Theme() == 'oxlight' ? 'rgb(0, 0, 0)'
: Ox.Theme() == 'oxmedium' ? 'rgb(0, 0, 0)' : Ox.Theme() == 'oxmedium' ? 'rgb(0, 0, 0)'
: 'rgb(255, 255, 255)', : 'rgb(255, 255, 255)',
$label, $icon, $text, $label, $texts,
$featuresBox, $featuresContainer, $featuresContent, $featuresBox, $featuresContainer, $featuresContent,
$featureBox = [], $featureIcon = [], $featureBox = [], $featureIcon = [],
$previousButton, $nextButton; $previousButton, $nextButton;
if (items.length) { if (items.length) {
$label = Ox.Label({ $features.empty();
textAlign: 'center', $texts = Ox.Element().appendTo($features);
title: '<b>' + Ox._('Featured ' + ( var top = 24;
lists == 1 && edits == 0 && texts == 0 ? 'List' items.forEach(function(item) {
: lists == 0 && edits == 1 && texts == 0 ? 'Edit' var $text, $icon;
: lists == 0 && edits == 0 && texts == 1 ? 'Text' $icon = Ox.Element({
: edits == 0 && texts == 0 ? 'Lists' element: '<img>',
: lists == 0 && texts == 0 ? 'Edits' tooltip: getTooltip(item)
: lists == 0 && edits == 0 ? 'Texts' })
: texts == 0 ? 'Lists and Edits' .attr({
: edits == 0 ? 'Lists and Texts' src: item.image
: lists == 0 ? 'Edits and Texts' })
: 'Lists, Edits and Texts'
)) + '</b>',
width: 512
})
.css({
position: 'absolute',
left: 0,
top: 0,
right: 0,
bottom: 0,
margin: '0 auto 0 auto'
})
.appendTo($features);
$text = Ox.Label({
width: 386
})
.addClass('OxSelectable')
.css({
position: 'absolute',
left: '24px',
top: '24px',
right: 0,
height: '104px',
borderTopLeftRadius: '32px',
borderBottomLeftRadius: '32px',
padding: '8px 8px 8px 130px',
overflowY: 'auto',
lineHeight: '14px',
textOverflow: 'ellipsis',
whiteSpace: 'normal'
})
.html(
getHTML(items[selected])
)
.appendTo($features);
pandora.createLinks($text);
$icon = Ox.Element({
element: '<img>',
tooltip: getTooltip(items[selected])
})
.attr({
src: getImageURL(items[selected])
})
.css({
position: 'absolute',
left: 0,
top: '24px',
right: '390px',
width: '122px',
height: '122px',
borderRadius: '32px',
margin: '0 auto 0 auto',
cursor: 'pointer'
})
.bindEvent({
anyclick: function() {
openItem(selected);
}
})
.appendTo($features);
if (items.length > 1) {
$featuresBox = $('<div>')
.css({ .css({
position: 'absolute',
left: 0, left: 0,
top: '150px', right: '390px',
right: 0, width: '122px',
height: '65px', // 4+57+4 height: '122px',
width: '560px', // 16+8+512+8+16 borderRadius: '32px',
margin: '0 auto 0 auto' marginRight: '8px',
cursor: 'pointer',
float: 'left'
}) })
.appendTo($features); .bindEvent({
$featuresContainer = $('<div>') anyclick: function() {
.css({ openItem(item);
position: 'absolute',
left: '20px',
right: '20px',
height: '65px',
width: '520px',
overflow: 'hidden'
})
.appendTo($featuresBox);
$featuresContent = $('<div>')
.css({
position: 'absolute',
width: items.length * 65 + 'px',
height: '65px',
marginLeft: items.length < max
? (max - items.length) * 65 / 2 + 'px'
: 0
})
.appendTo($featuresContainer);
if (items.length > max) {
$previousButton = Ox.Button({
title: 'left',
type: 'image'
})
.addClass(position > 0 ? 'visible' : '')
.css({
position: 'absolute',
left: 0,
top: '25px',
opacity: 0
})
.hide()
.bindEvent({
mousedown: function() {
counter = 0;
scrollToPosition(position - 1, true);
},
mouserepeat: function() {
// fixme: arbitrary
if (counter++ % 5 == 0) {
scrollToPosition(position - 1, false);
}
}
})
.appendTo($featuresBox);
$nextButton = Ox.Button({
title: 'right',
type: 'image'
})
.addClass(position < items.length - 1 ? 'visible' : '')
.css({
position: 'absolute',
right: 0,
top: '25px',
opacity: 0
})
.hide()
.bindEvent({
mousedown: function() {
counter = 0;
scrollToPosition(position + 1, true);
},
mouserepeat: function() {
// fixme: arbitrary
if (counter++ % 5 == 0) {
scrollToPosition(position + 1, false);
}
}
})
.appendTo($featuresBox);
$featuresBox.on({
mouseenter: function() {
mouse = true;
$('.visible').show().stop().animate({
opacity: 1
}, 250);
},
mouseleave: function() {
mouse = false;
$('.visible').stop().animate({
opacity: 0
}, 250, function() {
$(this).hide();
});
},
mousewheel: function(e, delta, deltaX, deltaY) {
// fixme: arbitrary
scrollToPosition(position + Math.round(deltaX * 2), true);
} }
}); });
} $text = Ox.Label({
items.forEach(function(item, i) { //width: 386 + 122
$featureBox[i] = $('<div>') })
.css({ .addClass('OxSelectable')
float: 'left', .css({
width: '57px', //position: 'absolute',
height: '57px', left: '24px',
padding: '2px', //top: top + 'px',
margin: '2px', right: 0,
borderRadius: '16px', height: 'auto',
boxShadow: '0 0 2px ' + (i == selected ? color : 'transparent') padding: '8px 8px 8px 8px',
}) borderRadius: '32px',
.appendTo($featuresContent); marginBottom: '16px',
$featureIcon[i] = Ox.Element({ overflowY: 'auto',
element: '<img>', lineHeight: '14px',
tooltip: ( textOverflow: 'ellipsis',
(lists && edits) || (lists && texts) || (edits && texts) whiteSpace: 'normal'
? Ox._(Ox.toTitleCase(item.type)) + ': ' })
: '' .append($icon)
) .append(
+ Ox.encodeHTMLEntities(item.name) Ox.Element().css({
}) //padding: '8px',
.attr({ }).html(getHTML(item))
src: getImageURL(item)
}) )
.css({ .appendTo($texts);
width: '57px', pandora.createLinks($text);
height: '57px', top += 130;
borderRadius: '16px', });
cursor: 'pointer'
})
.bindEvent({
doubleclick: function() {
openItem(i);
},
singleclick: function() {
selectItem(i);
}
})
.appendTo($featureBox[i]);
});
self.keydown = function(e) {
var key = Ox.KEYS[e.keyCode];
if (!Ox.Focus.focusedElementIsInput()) {
if (key == 'left' && selected > 0) {
selectItem(selected - 1);
} else if (key == 'up' && selected > 0) {
selectItem(0);
} else if (key == 'right' && selected < items.length - 1) {
selectItem(selected + 1);
} else if (key == 'down' && selected < items.length - 1) {
selectItem(items.length - 1);
}
}
};
Ox.$document.on({keydown: self.keydown});
}
$space = $('<div>')
.css({
position: 'absolute',
top: items.length == 0 ? '0px'
: items.length == 1 ? '150px'
: '215px',
width: '560px',
height: '80px'
})
.appendTo($features);
$features.animate({opacity: 1}, 250); $features.animate({opacity: 1}, 250);
} }
function getHTML(item) { function getHTML(item) {
return '<b>' return '<b>' + Ox.encodeHTMLEntities(item.title) + '</b><br><br>' + item.text;
+ (
(lists && edits) || (lists && texts) || (edits && texts)
? Ox._(Ox.toTitleCase(item.type)) + ': '
: ''
)
+ Ox.encodeHTMLEntities(item.name) + '</b><br><br>'
+ item.description;
}
function getImageURL(item) {
return '/' + item.type + '/' + item.user
+ ':' + encodeURIComponent(item.name) + '/icon256.jpg?' + item.modified;
} }
function getTooltip(item) { function getTooltip(item) {
return Ox._('View {0}', [Ox._(Ox.toTitleCase(item.type))]) return Ox._('View {0}', [Ox._(Ox.toTitleCase(item.title))])
} }
function openItem(i) { function openItem(item) {
that.fadeOutScreen(); that.fadeOutScreen();
pandora.UI.set(Ox.extend({ if (item.type == 'custom') {
section: items[i].type == 'list' ? 'items' : items[i].type + 's', pandora.URL.push(item.link);
page: '' } else {
}, items[i].type == 'list' ? { pandora.UI.set(Ox.extend({
find: {
conditions: [{ section: item.type == 'list' ? 'items' : item.type + 's',
key: 'list', page: ''
value: items[i].user + ':' }, item.type == 'list' ? {
+ items[i].name, find: {
operator: '==' conditions: [{
}], key: 'list',
operator: '&' value: item.contentid,
} operator: '=='
} : items[i].type == 'edit' ? { }],
edit: items[i].user + ':' + items[i].name operator: '&'
} : { }
text: items[i].user + ':' + items[i].name } : item.type == 'collection' ? {
})); findDocuments: {
conditions: [{
key: 'collection',
value: item.contentid,
operator: '=='
}],
operator: '&'
}
} : item.type == 'edit' ? {
edit: item.contentid
} : {
}));
}
} }
function scrollToPosition(i, animate) { function scrollToPosition(i, animate) {
@ -637,32 +438,7 @@ pandora.ui.home = function() {
} }
} }
function selectItem(i) { }
if (i >= 0 && i <= items.length - 1 && i != selected) {
$featureBox[selected].css({
boxShadow: 'none'
});
selected = i;
$featureBox[selected].css({
boxShadow: '0 0 2px ' + color
});
if (selected < position) {
scrollToPosition(selected, true);
} else if (selected > position + max - 1) {
scrollToPosition(selected - max + 1, true);
}
$icon.attr({
src: getImageURL(items[selected])
}).options({
tooltip: getTooltip(items[selected])
});
$text.html(
getHTML(items[selected])
);
}
}
}
} }
that.fadeInScreen = function() { that.fadeInScreen = function() {

View file

@ -53,7 +53,7 @@ pandora.ui.homeDialog = function() {
renderForm(item); renderForm(item);
} }
}); });
}); });
function editItem(id, key, value) { function editItem(id, key, value) {
var title = $title.value(); var title = $title.value();
@ -64,16 +64,37 @@ pandora.ui.homeDialog = function() {
var link = $linkInput.value(); var link = $linkInput.value();
} else { } else {
var name = $nameInput.value(); var name = $nameInput.value();
title = true;
text = true;
key = 'contentid';
} }
if ( if (
!title || !text !title || !text
|| (type == 'custom' && (!image || !link)) || (type == 'custom' && (!image || !link))
|| (type != 'custom' && !name) || (type != 'custom' && !name)
) { ) {
return; return;
} }
pandora.api.editHomeItem(Ox.extend({id: id}, key, value), function(result) { Ox.print('id', id, 'k', key, 'v', value);
// ... var data = {id: id};
data[key] = value;
if (key == 'contentid') {
data.type = type;
}
pandora.api.editHomeItem(data, function(result) {
Ox.Request.clearCache(); // FIXME: too much?
items.some(function(item) {
if (item.id == id) {
item[key] = value;
if (key == 'contentid') {
item.image = result.data.image;
item.text = result.data.text;
item.title = result.data.title;
renderItem(item);
}
return true;
};
});
}); });
} }
@ -174,8 +195,8 @@ pandora.ui.homeDialog = function() {
}).css({ }).css({
margin: '8px' margin: '8px'
}).bindEvent({ }).bindEvent({
change: function(data) { change: function(data_) {
var item = {type: data.value}; var item = {id: data.id, type: data_.value};
renderItem(item); renderItem(item);
renderForm(item, true); renderForm(item, true);
} }
@ -189,8 +210,8 @@ pandora.ui.homeDialog = function() {
}).css({ }).css({
margin: '8px' margin: '8px'
}).bindEvent({ }).bindEvent({
change: function(data) { change: function(data_) {
editItem(data.id, 'image', data.value); editItem(data.id, 'image', data_.value);
} }
}).appendTo($form); }).appendTo($form);
$linkInput = Ox.Input({ $linkInput = Ox.Input({
@ -201,8 +222,8 @@ pandora.ui.homeDialog = function() {
}).css({ }).css({
margin: '8px' margin: '8px'
}).bindEvent({ }).bindEvent({
change: function(data) { change: function(data_) {
editItem(data.id, 'link', data.value); editItem(data.id, 'link', data_.value);
} }
}).appendTo($form); }).appendTo($form);
} else { } else {
@ -217,8 +238,8 @@ pandora.ui.homeDialog = function() {
}).css({ }).css({
margin: '8px' margin: '8px'
}).bindEvent({ }).bindEvent({
change: function(data) { change: function(data_) {
editItem(data.id, 'name', data.value); editItem(data.id, 'name', data_.value);
} }
}).appendTo($form); }).appendTo($form);
} }
@ -265,8 +286,9 @@ pandora.ui.homeDialog = function() {
fontSize: '13px', fontSize: '13px',
fontWeight: 'bold' fontWeight: 'bold'
}).bindEvent({ }).bindEvent({
submit: function(data) { submit: function(data_) {
editItem(data.id, 'title', data.value); editItem(data.id, 'title', data_.value);
//fixme: update list
} }
}).appendTo($container); }).appendTo($container);
$text = Ox.EditableContent({ $text = Ox.EditableContent({
@ -277,8 +299,8 @@ pandora.ui.homeDialog = function() {
}).css({ }).css({
margin: '0 12px 0 0' margin: '0 12px 0 0'
}).bindEvent({ }).bindEvent({
submit: function(data) { submit: function(data_) {
editItem(data.id, 'text', data.value); editItem(data.id, 'text', data_.value);
} }
}).appendTo($item); }).appendTo($item);
} }
@ -299,7 +321,7 @@ pandora.ui.homeDialog = function() {
}) })
}, },
visible: true, visible: true,
width: 16, width: 16,
}, },
{ {
id: 'title', id: 'title',
@ -341,6 +363,13 @@ pandora.ui.homeDialog = function() {
}, },
selectbefore: function() { selectbefore: function() {
// ... // ...
},
move: function(data) {
pandora.api.sortHomeItems({
ids: data.ids
}, function() {
Ox.Request.clearCache('HomeItems');
});
} }
}) })
.css({ .css({
@ -351,4 +380,4 @@ pandora.ui.homeDialog = function() {
return that; return that;
}; };