temporary metadata editing

This commit is contained in:
j 2011-02-25 13:12:56 +01:00
parent 7fa5bb309a
commit dbdf12945d
3 changed files with 57 additions and 12 deletions

View file

@ -151,7 +151,7 @@ class Item(models.Model):
if 'id' in data: if 'id' in data:
#FIXME: check if id is valid and exists and move/merge items accordingly #FIXME: check if id is valid and exists and move/merge items accordingly
del data['id'] del data['id']
if 'id' in data: if 'groups' in data:
groups = data.pop('groups') groups = data.pop('groups')
self.groups.exclude(name__in=groups).delete() self.groups.exclude(name__in=groups).delete()
for g in groups: for g in groups:
@ -159,8 +159,7 @@ class Item(models.Model):
self.groups.add(group) self.groups.add(group)
for key in data: for key in data:
if key != 'id': if key != 'id':
setattr(self.data, key, data[key]) self.data[key] = data[key]
self.data.save()
self.save() self.save()
def reviews(self): def reviews(self):

View file

@ -334,7 +334,7 @@ def editItem(request):
data = json.loads(request.POST['data']) data = json.loads(request.POST['data'])
item = get_object_or_404_json(models.Item, itemId=data['id']) item = get_object_or_404_json(models.Item, itemId=data['id'])
if item.editable(request.user): if item.editable(request.user):
response = json_response(status=501, text='not implemented') response = json_response(status=200, text='ok')
item.edit(data) item.edit(data)
else: else:
response = json_response(status=403, text='permissino denied') response = json_response(status=403, text='permissino denied')

View file

@ -1727,13 +1727,58 @@
pandora.api.getItem(app.user.ui.item, function(result) { pandora.api.getItem(app.user.ui.item, function(result) {
if (app.user.ui.itemView == 'info') { if (app.user.ui.itemView == 'info') {
//Ox.print('result.data.item', result.data.item) //Ox.print('result.data.item', result.data.item)
$.get('/static/html/itemInfo.html', {}, function(template) { if (app.user.level == 'admin') {
//Ox.print(template); var $form,
app.$ui.contentPanel.replace(1, $edit = new Ox.Element()
app.$ui.item = new Ox.Element('div') .append($form = new Ox.FormElementGroup({
.append($.tmpl(template, result.data.item)) elements: Ox.map(app.config.itemKeys, function(key) {
); return new Ox.Input({
}); id: key.id,
label: key.title,
labelWidth: 100,
value: result.data.item[key.id],
type: 'text',
width: 500
});
}),
separators: [
{title: '', width: 0}
]
}))
.append(new Ox.Button({
title: 'Save',
type: 'text'
}).bindEvent({
click: function(event, data) {
var values = $form.value();
var changed = {};
Ox.map(app.config.itemKeys, function(key, i) {
if(values[i] && values[i] != ''+result.data.item[key.id]) {
if(Ox.isArray(key.type) && key.type[0] == 'string')
changed[key.id] = values[i].split(', ');
else
changed[key.id] = values[i];
}
});
if(changed) {
pandora.api.editItem(Ox.extend(changed, {id: app.user.ui.item}), function(result) {
//fixme just reload parts that need reloading
window.location.reload();
});
}
}
}));
app.$ui.contentPanel.replace(1, app.$ui.item = $edit);
} else {
$.get('/static/html/itemInfo.html', {}, function(template) {
//Ox.print(template);
app.$ui.contentPanel.replace(1,
app.$ui.item = new Ox.Element('div')
.append($.tmpl(template, result.data.item))
);
});
}
} else if (app.user.ui.itemView == 'player') { } else if (app.user.ui.itemView == 'player') {
var video = result.data.item.stream, var video = result.data.item.stream,
subtitles = result.data.item.layers.subtitles, subtitles = result.data.item.layers.subtitles,
@ -1865,7 +1910,8 @@
}) })
); );
} }
app.$ui.total.html(result.data.item.title + ' (' + result.data.item.director.join(', ') + ')') var director = result.data.item.director?' ('+result.data.item.director.join(', ')+')':'';
app.$ui.total.html(result.data.item.title + director);
}); });
return that; return that;
}, },