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,322 +289,123 @@ 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) {
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(); 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({ .css({
position: 'absolute',
left: 0, left: 0,
top: 0, right: '390px',
right: 0, width: '122px',
bottom: 0, height: '122px',
margin: '0 auto 0 auto' borderRadius: '32px',
marginRight: '8px',
cursor: 'pointer',
float: 'left'
}) })
.appendTo($features); .bindEvent({
anyclick: function() {
openItem(item);
}
});
$text = Ox.Label({ $text = Ox.Label({
width: 386 //width: 386 + 122
}) })
.addClass('OxSelectable') .addClass('OxSelectable')
.css({ .css({
position: 'absolute', //position: 'absolute',
left: '24px', left: '24px',
top: '24px', //top: top + 'px',
right: 0, right: 0,
height: '104px', height: 'auto',
borderTopLeftRadius: '32px', padding: '8px 8px 8px 8px',
borderBottomLeftRadius: '32px', borderRadius: '32px',
padding: '8px 8px 8px 130px', marginBottom: '16px',
overflowY: 'auto', overflowY: 'auto',
lineHeight: '14px', lineHeight: '14px',
textOverflow: 'ellipsis', textOverflow: 'ellipsis',
whiteSpace: 'normal' whiteSpace: 'normal'
}) })
.html( .append($icon)
getHTML(items[selected]) .append(
Ox.Element().css({
//padding: '8px',
}).html(getHTML(item))
) )
.appendTo($features); .appendTo($texts);
pandora.createLinks($text); pandora.createLinks($text);
$icon = Ox.Element({ top += 130;
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({
position: 'absolute',
left: 0,
top: '150px',
right: 0,
height: '65px', // 4+57+4
width: '560px', // 16+8+512+8+16
margin: '0 auto 0 auto'
})
.appendTo($features);
$featuresContainer = $('<div>')
.css({
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);
}
});
}
items.forEach(function(item, i) {
$featureBox[i] = $('<div>')
.css({
float: 'left',
width: '57px',
height: '57px',
padding: '2px',
margin: '2px',
borderRadius: '16px',
boxShadow: '0 0 2px ' + (i == selected ? color : 'transparent')
})
.appendTo($featuresContent);
$featureIcon[i] = Ox.Element({
element: '<img>',
tooltip: (
(lists && edits) || (lists && texts) || (edits && texts)
? Ox._(Ox.toTitleCase(item.type)) + ': '
: ''
)
+ Ox.encodeHTMLEntities(item.name)
})
.attr({
src: getImageURL(item)
})
.css({
width: '57px',
height: '57px',
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();
if (item.type == 'custom') {
pandora.URL.push(item.link);
} else {
pandora.UI.set(Ox.extend({ pandora.UI.set(Ox.extend({
section: items[i].type == 'list' ? 'items' : items[i].type + 's',
section: item.type == 'list' ? 'items' : item.type + 's',
page: '' page: ''
}, items[i].type == 'list' ? { }, item.type == 'list' ? {
find: { find: {
conditions: [{ conditions: [{
key: 'list', key: 'list',
value: items[i].user + ':' value: item.contentid,
+ items[i].name,
operator: '==' operator: '=='
}], }],
operator: '&' operator: '&'
} }
} : items[i].type == 'edit' ? { } : item.type == 'collection' ? {
edit: items[i].user + ':' + items[i].name findDocuments: {
conditions: [{
key: 'collection',
value: item.contentid,
operator: '=='
}],
operator: '&'
}
} : item.type == 'edit' ? {
edit: item.contentid
} : { } : {
text: items[i].user + ':' + items[i].name
})); }));
} }
}
function scrollToPosition(i, animate) { function scrollToPosition(i, animate) {
if (i >= 0 && i <= items.length - max && i != position) { if (i >= 0 && i <= items.length - max && i != position) {
@ -637,31 +438,6 @@ 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])
);
}
}
} }
} }

View file

@ -64,6 +64,9 @@ 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
@ -72,8 +75,26 @@ pandora.ui.homeDialog = function() {
) { ) {
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);
} }
@ -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({