diff --git a/pandora/item/models.py b/pandora/item/models.py index 02719167..ca014163 100644 --- a/pandora/item/models.py +++ b/pandora/item/models.py @@ -151,7 +151,7 @@ class Item(models.Model): if 'id' in data: #FIXME: check if id is valid and exists and move/merge items accordingly del data['id'] - if 'id' in data: + if 'groups' in data: groups = data.pop('groups') self.groups.exclude(name__in=groups).delete() for g in groups: @@ -159,8 +159,7 @@ class Item(models.Model): self.groups.add(group) for key in data: if key != 'id': - setattr(self.data, key, data[key]) - self.data.save() + self.data[key] = data[key] self.save() def reviews(self): diff --git a/pandora/item/views.py b/pandora/item/views.py index 648bb39d..99da4bda 100644 --- a/pandora/item/views.py +++ b/pandora/item/views.py @@ -334,7 +334,7 @@ def editItem(request): data = json.loads(request.POST['data']) item = get_object_or_404_json(models.Item, itemId=data['id']) if item.editable(request.user): - response = json_response(status=501, text='not implemented') + response = json_response(status=200, text='ok') item.edit(data) else: response = json_response(status=403, text='permissino denied') diff --git a/static/js/pandora.js b/static/js/pandora.js index 2ccf8e1d..35c0969f 100755 --- a/static/js/pandora.js +++ b/static/js/pandora.js @@ -1727,13 +1727,58 @@ pandora.api.getItem(app.user.ui.item, function(result) { if (app.user.ui.itemView == 'info') { //Ox.print('result.data.item', result.data.item) - $.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)) - ); - }); + if (app.user.level == 'admin') { + var $form, + $edit = new Ox.Element() + .append($form = new Ox.FormElementGroup({ + 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') { var video = result.data.item.stream, 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; },