pandora/static/js/item.js

206 lines
8.2 KiB
JavaScript
Raw Permalink Normal View History

2012-02-03 09:15:38 +00:00
'use strict';
2011-05-25 19:42:45 +00:00
pandora.ui.item = function() {
2011-09-17 07:07:59 +00:00
var isVideoView = [
2012-04-17 08:03:11 +00:00
'timeline', 'player', 'editor'
].indexOf(pandora.user.ui.itemView) > -1,
item = pandora.user.ui.item,
that = Ox.Element(),
videopointsEvent = 'pandora_videopoints.' + item.toLowerCase();
2011-09-17 07:07:59 +00:00
2011-08-06 13:34:56 +00:00
pandora.api.get({
id: pandora.user.ui.item,
2016-10-03 10:45:52 +00:00
keys: isVideoView ? Ox.unique(pandora.VIDEO_OPTIONS_KEYS.concat(pandora.site.itemTitleKeys)) : []
2017-11-04 09:53:27 +00:00
}, pandora.user.ui.itemView == 'info' && pandora.hasCapability('canEditMetadata') ? 0 : -1, function(result) {
2011-09-17 07:07:59 +00:00
if (pandora.user.ui.item != item) {
return;
}
2011-09-17 07:07:59 +00:00
if (result.status.code == 200) {
2011-11-09 22:32:54 +00:00
// we want to cache the title in any way, so that after closing
// a dialog and getting to this item, the title is correct
2016-10-04 22:00:03 +00:00
var documentTitle = pandora.getWindowTitle(result.data);
2011-11-09 22:32:54 +00:00
document.title = pandora.getPageTitle(document.location.pathname) || documentTitle;
2011-09-17 07:07:59 +00:00
}
2011-10-30 21:05:57 +00:00
pandora.$ui.itemTitle
.options({title: '<b>' + pandora.getItemTitle(result.data, true) + '</b>'})
2011-10-30 21:05:57 +00:00
.show();
2012-04-17 12:03:16 +00:00
// fixme: layers have value, subtitles has text?
isVideoView && Ox.extend(result.data, pandora.getVideoOptions(result.data));
2011-10-22 21:03:28 +00:00
if (!result.data.rendered && [
2012-04-17 08:03:11 +00:00
'clips', 'timeline', 'player', 'editor', 'map', 'calendar'
2011-10-22 21:03:28 +00:00
].indexOf(pandora.user.ui.itemView) > -1) {
2016-11-30 10:07:09 +00:00
var html = Ox._('Sorry, <i>{0}</i>'
+ ' currently doesn\'t have '
+ (['a', 'e', 'i', 'o'].indexOf(
pandora.user.ui.itemView.slice(0, 1)
) > -1 ? 'an': 'a') + ' '
+'{1} view.', [result.data.title, Ox._(pandora.user.ui.itemView)]);
2019-11-12 17:50:07 +00:00
var note = Ox.Element()
.css({marginTop: '32px', fontSize: '12px', textAlign: 'center'})
pandora.$ui.contentPanel.replaceElement(1, note);
2020-02-06 10:25:02 +00:00
if (pandora.user.username == result.data.user || pandora.hasCapability('canSeeAllTasks')) {
2019-11-12 17:50:07 +00:00
pandora.api.getTasks({
user: pandora.hasCapability('canSeeAllTasks') ? '' : pandora.user.username
}, function(result_) {
var tasks = result_.data.items.filter(function(task) { return task.item == item})
2020-02-06 10:25:02 +00:00
if (tasks.length > 0) {
2019-11-12 17:50:07 +00:00
html = Ox._(
'<i>{0}</i> is currently processed. '
+ '{1} view will be available in a moment.',
[result.data.title, Ox._(pandora.user.ui.itemView)]
)
}
note.html(html)
})
} else {
note.html(html)
}
2016-11-30 10:07:09 +00:00
pandora.site.itemViews.filter(function(view) {
return view.id == 'documents';
}).length && pandora.api.get({
id: pandora.user.ui.item,
keys: ['numberofdocuments']
}, function(result) {
if (result.data.numberofdocuments) {
var $text = Ox.Element()
.css({marginTop: '32px', fontSize: '12px', textAlign: 'center'})
.html(
html
+ '<br>'
2017-01-25 20:47:47 +00:00
+ Ox._('There {0} <a href="{1}">{2}</a>', [
(result.data.numberofdocuments == 1 ? 'is' : 'are'),
2016-11-30 10:07:09 +00:00
'/' + pandora.user.ui.item + '/documents',
Ox.formatCount(result.data.numberofdocuments, 'document')
])
)
pandora.$ui.contentPanel.replaceElement(1, $text);
pandora.createLinks($text);
}
});
result.data.parts > 0 && pandora.updateStatus(pandora.user.ui.item);
2011-06-06 15:48:11 +00:00
} else if (pandora.user.ui.itemView == 'info') {
2012-04-24 08:21:54 +00:00
pandora.$ui.contentPanel.replaceElement(1,
pandora.$ui.item = pandora.ui.infoView(result.data)
.bindEvent({
resize: function() {
pandora.$ui.item.resizeElement && pandora.$ui.item.resizeElement();
2011-05-25 19:42:45 +00:00
}
2012-04-24 08:21:54 +00:00
})
);
!result.data.rendered && result.data.parts > 0 && pandora.updateStatus(pandora.user.ui.item);
2013-05-27 12:29:43 +00:00
} else if (pandora.user.ui.itemView == 'documents') {
pandora.$ui.contentPanel.replaceElement(1,
pandora.$ui.documents = pandora.ui.documentsPanel({
editable: result.data.editable,
isItemView: true
})
2013-05-27 12:29:43 +00:00
);
2011-05-25 19:42:45 +00:00
2013-03-02 06:39:28 +00:00
} else if (pandora.user.ui.itemView == 'player') {
2011-09-30 10:33:45 +00:00
pandora.$ui.contentPanel.replaceElement(1,
2013-03-02 06:39:28 +00:00
pandora.$ui.player = pandora.ui.player(result.data)
2011-09-30 10:33:45 +00:00
);
2013-03-02 06:39:28 +00:00
} else if (pandora.user.ui.itemView == 'editor') {
2012-04-17 08:03:11 +00:00
pandora.$ui.contentPanel.replaceElement(1,
2013-03-02 06:39:28 +00:00
pandora.$ui.editor = pandora.ui.editor(result.data)
2012-04-17 08:03:11 +00:00
);
2013-03-02 06:39:28 +00:00
} else if (pandora.user.ui.itemView == 'timeline') {
2012-04-17 06:31:44 +00:00
pandora.$ui.contentPanel.replaceElement(1,
2013-03-02 06:39:28 +00:00
pandora.$ui.timeline = pandora.ui.timeline(result.data)
2012-04-17 06:31:44 +00:00
);
2011-09-17 07:07:59 +00:00
2013-03-02 06:39:28 +00:00
} else if (pandora.user.ui.itemView == 'clips') {
2011-10-30 09:49:12 +00:00
pandora.$ui.contentPanel.replaceElement(1,
2013-03-02 06:39:28 +00:00
pandora.ui.clipsView(result.data.videoRatio)
2011-10-30 09:49:12 +00:00
);
} else if (pandora.user.ui.itemView == 'map') {
2012-04-17 06:31:44 +00:00
pandora.$ui.contentPanel.replaceElement(1,
pandora.ui.navigationView('map', result.data.videoRatio)
);
} else if (pandora.user.ui.itemView == 'calendar') {
2012-04-17 06:31:44 +00:00
pandora.$ui.contentPanel.replaceElement(1,
pandora.ui.navigationView('calendar', result.data.videoRatio)
);
2011-09-28 17:32:03 +00:00
} else if (pandora.user.ui.itemView == 'data') {
2012-04-24 08:21:54 +00:00
pandora.$ui.item = Ox.TreeList({
2011-09-28 17:32:03 +00:00
data: result.data,
2014-09-26 12:12:25 +00:00
width: pandora.$ui.mainPanel.size(1) - Ox.UI.SCROLLBAR_SIZE
2012-04-24 08:21:54 +00:00
});
pandora.$ui.contentPanel.replaceElement(1,
Ox.Container().append(pandora.$ui.item)
);
} else if (pandora.user.ui.itemView == 'media') {
2011-06-06 15:48:11 +00:00
pandora.$ui.contentPanel.replaceElement(1,
2014-02-13 11:54:30 +00:00
pandora.$ui.item = pandora.ui.mediaView(result.data)
2011-05-25 19:42:45 +00:00
);
2011-09-17 07:07:59 +00:00
2011-06-06 18:40:24 +00:00
} else if (pandora.user.ui.itemView == 'frames' || pandora.user.ui.itemView == 'posters') {
2011-06-06 18:40:24 +00:00
pandora.$ui.contentPanel.replaceElement(1,
pandora.$ui.item = pandora.ui.PostersView().bindEvent({
2011-06-07 03:17:36 +00:00
resize: function() {
pandora.$ui.item.resizeElement();
2011-06-07 03:17:36 +00:00
}
})
2011-06-06 18:40:24 +00:00
);
2011-05-25 19:42:45 +00:00
}
if (isVideoView && result.data.rendered) {
// handle links in annotations
pandora.$ui[pandora.user.ui.itemView].bindEvent(
videopointsEvent,
function(data, event, element) {
var options = {};
if (pandora.user.ui.item && event == videopointsEvent) {
//Ox.print('DATA.VALUE', JSON.stringify(data.value));
if (data && data.value && data.value.annotation) {
options.selected = pandora.user.ui.item + '/' + data.value.annotation;
} else {
// if annotation got set to something other than '',
// points and position will be set in consequence,
// so lets try to keep events from looping
['annotation', 'in', 'out', 'position'].forEach(function(key) {
if (!Ox.isUndefined(data.value[key])) {
options[key == 'annotation' ? 'selected' : key] = data.value[key];
}
});
}
pandora.$ui[pandora.user.ui.itemView].options(options);
}
}
);
}
2011-05-25 19:42:45 +00:00
});
2011-09-17 07:07:59 +00:00
2011-05-25 19:42:45 +00:00
return that;
2011-09-17 07:07:59 +00:00
2011-05-25 19:42:45 +00:00
};