addEdit + addList = addFolderItem
This commit is contained in:
parent
336acb326f
commit
faf6917d4b
1 changed files with 116 additions and 85 deletions
|
@ -12,37 +12,23 @@ pandora.addItem = function() {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
pandora.addEdit = function(options) {
|
pandora.addEdit = function() {
|
||||||
var $folderList = pandora.$ui.folderList.personal;
|
// addEdit(isSmart, isFrom) or addEdit(edit) [=duplicate]
|
||||||
options = options || {};
|
pandora.addFolderItem.apply(null, ['edit'].concat(Ox.slice(arguments)));
|
||||||
pandora.api.addEdit(options, function(result) {
|
|
||||||
reloadFolder(result.data.id);
|
|
||||||
});
|
|
||||||
function reloadFolder(newId) {
|
|
||||||
pandora.$ui.folder[0].options({collapsed: false});
|
|
||||||
Ox.Request.clearCache('findEdits');
|
|
||||||
$folderList.bindEventOnce({
|
|
||||||
load: function(data) {
|
|
||||||
$folderList.gainFocus()
|
|
||||||
.options({selected: [newId]})
|
|
||||||
.editCell(newId, 'name', true);
|
|
||||||
pandora.UI.set(pandora.user.ui.section.slice(0, -1), newId);
|
|
||||||
}
|
|
||||||
}).reloadList();
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
pandora.addList = function() {
|
pandora.addFolderItem = function(section) {
|
||||||
// addList(isSmart, isFrom) or addList(list) [=duplicate]
|
// addFolderItem(section, isSmart, isFrom)
|
||||||
|
// or addFolderItem(section, list) [=duplicate]
|
||||||
var $folderList = pandora.$ui.folderList.personal,
|
var $folderList = pandora.$ui.folderList.personal,
|
||||||
isDuplicate = arguments.length == 1,
|
isDuplicate = arguments.length == 2,
|
||||||
isSmart, isFrom, list, listData, data;
|
isItems = section == 'items',
|
||||||
pandora.UI.set({
|
isSmart, isFrom, list, listData, data,
|
||||||
showSidebar: true
|
ui = pandora.user.ui;
|
||||||
});
|
pandora.UI.set({showSidebar: true});
|
||||||
if (!isDuplicate) {
|
if (!isDuplicate) {
|
||||||
isSmart = arguments[0];
|
isSmart = arguments[1];
|
||||||
isFrom = arguments[1];
|
isFrom = arguments[2];
|
||||||
data = {
|
data = {
|
||||||
name: Ox._('Untitled'),
|
name: Ox._('Untitled'),
|
||||||
status: 'private',
|
status: 'private',
|
||||||
|
@ -50,14 +36,16 @@ pandora.addList = function() {
|
||||||
};
|
};
|
||||||
if (isFrom) {
|
if (isFrom) {
|
||||||
if (!isSmart) {
|
if (!isSmart) {
|
||||||
data.items = pandora.user.ui.listSelection;
|
data.items = isItems
|
||||||
|
? ui.listSelection
|
||||||
|
: ui.edits[ui.edit].selection;
|
||||||
} else {
|
} else {
|
||||||
data.query = pandora.user.ui.find;
|
data.query = ui.find;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
addList();
|
addList();
|
||||||
} else {
|
} else {
|
||||||
list = arguments[0];
|
list = arguments[1];
|
||||||
listData = pandora.getListData();
|
listData = pandora.getListData();
|
||||||
data = {
|
data = {
|
||||||
name: listData.name,
|
name: listData.name,
|
||||||
|
@ -67,19 +55,19 @@ pandora.addList = function() {
|
||||||
if (data.type == 'smart') {
|
if (data.type == 'smart') {
|
||||||
data.query = listData.query;
|
data.query = listData.query;
|
||||||
}
|
}
|
||||||
pandora.api.findLists({
|
pandora.api[isItems ? 'findLists' : 'findEdits']({
|
||||||
query: {conditions: [{key: 'id', value: list, operator: '=='}]},
|
query: {conditions: [{key: 'id', value: list, operator: '=='}]},
|
||||||
keys: ['description']
|
keys: ['description']
|
||||||
}, function(result) {
|
}, function(result) {
|
||||||
data.description = result.data.items[0].description;
|
data.description = result.data.items[0].description;
|
||||||
if (data.type == 'static') {
|
if (data.type == 'static') {
|
||||||
var query = {
|
var query;
|
||||||
|
if (isItems) {
|
||||||
|
query = {
|
||||||
conditions: [{key: 'list', value: list, operator: '=='}],
|
conditions: [{key: 'list', value: list, operator: '=='}],
|
||||||
operator: '&'
|
operator: '&'
|
||||||
};
|
};
|
||||||
pandora.api.find({
|
pandora.api.find({query: query}, function(result) {
|
||||||
query: query
|
|
||||||
}, function(result) {
|
|
||||||
if (result.data.items) {
|
if (result.data.items) {
|
||||||
pandora.api.find({
|
pandora.api.find({
|
||||||
query: query,
|
query: query,
|
||||||
|
@ -96,31 +84,66 @@ pandora.addList = function() {
|
||||||
addList();
|
addList();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
pandora.api.getEdit({id: list}, function(result) {
|
||||||
|
var items = result.data.clips.map(function(clip) {
|
||||||
|
return Ox.extend({
|
||||||
|
item: clip.item
|
||||||
|
}, clip.annotation ? {
|
||||||
|
annotation: clip.annotation
|
||||||
|
} : {
|
||||||
|
'in': clip['in'],
|
||||||
|
out: clip.out
|
||||||
|
});
|
||||||
|
});
|
||||||
|
addList(items);
|
||||||
|
});
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
addList();
|
addList();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
function addList(items) {
|
function addList(items) {
|
||||||
pandora.api.addList(data, function(result) {
|
pandora.api[isItems ? 'addList' : 'addEdit'](data, function(result) {
|
||||||
var newList = result.data.id;
|
var newList = result.data.id;
|
||||||
if (items) {
|
if (items) {
|
||||||
|
if (isItems) {
|
||||||
pandora.api.addListItems({
|
pandora.api.addListItems({
|
||||||
list: newList,
|
list: newList,
|
||||||
items: items
|
items: items
|
||||||
}, function() {
|
}, function() {
|
||||||
getPosterFrames(newList);
|
getPosterFrames(newList);
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
pandora.api.addClips({
|
||||||
|
clips: items,
|
||||||
|
edit: newList
|
||||||
|
}, function(result) {
|
||||||
|
getPosterFrames(newList);
|
||||||
|
});
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
getPosterFrames(newList);
|
getPosterFrames(newList);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
function getPosterFrames(newList) {
|
function getPosterFrames(newList) {
|
||||||
var sortKey = Ox.getObjectById(pandora.site.itemKeys, 'votes')
|
var query,
|
||||||
? 'votes'
|
sortKey = Ox.getObjectById(pandora.site.itemKeys, 'votes')
|
||||||
: 'timesaccessed';
|
? 'votes' : 'timesaccessed';
|
||||||
if (!isDuplicate) {
|
if (!isDuplicate) {
|
||||||
|
(isItems ? Ox.noop : pandora.api.getEdit)({id: newList}, function(result) {
|
||||||
|
Ox.print('RESULT::::', result.data)
|
||||||
|
query = isItems ? {
|
||||||
|
conditions: [{key: 'list', value: newList, operator: '=='}],
|
||||||
|
operator: '&'
|
||||||
|
} : {
|
||||||
|
conditions: Ox.unique(result.data.clips.map(function(clips) {
|
||||||
|
return {key: 'id', value: clip.item, operator: '=='};
|
||||||
|
})),
|
||||||
|
operator: '|'
|
||||||
|
};
|
||||||
pandora.api.find({
|
pandora.api.find({
|
||||||
query: {
|
query: {
|
||||||
conditions: [{key: 'list', value: newList, operator: '=='}],
|
conditions: [{key: 'list', value: newList, operator: '=='}],
|
||||||
|
@ -141,9 +164,10 @@ pandora.addList = function() {
|
||||||
? [posterFrames[0], posterFrames[1], posterFrames[2], posterFrames[0]]
|
? [posterFrames[0], posterFrames[1], posterFrames[2], posterFrames[0]]
|
||||||
: posterFrames;
|
: posterFrames;
|
||||||
setPosterFrames(newList, posterFrames);
|
setPosterFrames(newList, posterFrames);
|
||||||
})
|
});
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
pandora.api.findLists({
|
pandora.api[isItems ? 'findLists' : 'findEdits']({
|
||||||
query: {
|
query: {
|
||||||
conditions: [{key: 'id', value: list, operator: '=='}],
|
conditions: [{key: 'id', value: list, operator: '=='}],
|
||||||
operator: '&'
|
operator: '&'
|
||||||
|
@ -155,7 +179,7 @@ pandora.addList = function() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function setPosterFrames(newList, posterFrames) {
|
function setPosterFrames(newList, posterFrames) {
|
||||||
pandora.api.editList({
|
pandora.api[isItems ? 'editList' : 'editEdit']({
|
||||||
id: newList,
|
id: newList,
|
||||||
posterFrames: posterFrames
|
posterFrames: posterFrames
|
||||||
}, function() {
|
}, function() {
|
||||||
|
@ -164,23 +188,30 @@ pandora.addList = function() {
|
||||||
}
|
}
|
||||||
function reloadFolder(newList) {
|
function reloadFolder(newList) {
|
||||||
pandora.$ui.folder[0].options({collapsed: false});
|
pandora.$ui.folder[0].options({collapsed: false});
|
||||||
Ox.Request.clearCache('findLists');
|
Ox.Request.clearCache(isItems ? 'findLists' : 'findEdits');
|
||||||
$folderList.bindEventOnce({
|
$folderList.bindEventOnce({
|
||||||
load: function() {
|
load: function() {
|
||||||
$folderList.gainFocus()
|
$folderList.gainFocus()
|
||||||
.options({selected: [newList]})
|
.options({selected: [newList]})
|
||||||
.editCell(newList, 'name', true);
|
.editCell(newList, 'name', true);
|
||||||
pandora.UI.set({
|
pandora.UI.set(isItems ? {
|
||||||
find: {
|
find: {
|
||||||
conditions: [{key: 'list', value: newList, operator: '=='}],
|
conditions: [{key: 'list', value: newList, operator: '=='}],
|
||||||
operator: '&'
|
operator: '&'
|
||||||
}
|
}
|
||||||
|
} : {
|
||||||
|
edit: newList
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}).reloadList();
|
}).reloadList();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
pandora.addList = function() {
|
||||||
|
// addList(isSmart, isFrom) or addList(list) [=duplicate]
|
||||||
|
pandora.addFolderItem.apply(null, ['items'].concat(Ox.slice(arguments)));
|
||||||
|
};
|
||||||
|
|
||||||
pandora.addText = function(options) {
|
pandora.addText = function(options) {
|
||||||
var $folderList = pandora.$ui.folderList.personal;
|
var $folderList = pandora.$ui.folderList.personal;
|
||||||
options = options || {};
|
options = options || {};
|
||||||
|
@ -1583,7 +1614,7 @@ pandora.getSpan = function(state, val, callback) {
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
pandora.api.getEdit({id: state.item, keys: ['clips']}, function(result) {
|
pandora.api.getEdit({id: state.item, keys: ['clips']}, function(result) {
|
||||||
if (Ox.getObjectById(result.data.clips, val)) {
|
if (result.data.clips && Ox.getObjectById(result.data.clips, val)) {
|
||||||
state.span = val;
|
state.span = val;
|
||||||
}
|
}
|
||||||
callback();
|
callback();
|
||||||
|
|
Loading…
Reference in a new issue