2014-05-04 17:26:43 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
oml.ui.browser = function() {
|
|
|
|
|
|
|
|
var ui = oml.user.ui,
|
|
|
|
|
|
|
|
that = Ox.IconList({
|
|
|
|
centered: true,
|
2014-05-21 00:02:39 +00:00
|
|
|
defaultRatio: oml.config.iconRatio,
|
2014-05-04 17:26:43 +00:00
|
|
|
draggable: true,
|
|
|
|
item: function(data, sort, size) {
|
2014-05-21 00:02:39 +00:00
|
|
|
var color = oml.getIconInfoColor(ui.iconInfo, data).map(function(rgb) {
|
2014-05-12 12:57:47 +00:00
|
|
|
return rgb.concat(0.8);
|
2014-05-04 17:26:43 +00:00
|
|
|
}),
|
2014-05-21 00:02:39 +00:00
|
|
|
ratio = (ui.icons == 'cover' ? data.coverRatio : data.previewRatio)
|
|
|
|
|| oml.config.iconRatio,
|
2014-05-04 17:26:43 +00:00
|
|
|
width = Math.round(ratio >= 1 ? size : size * ratio),
|
|
|
|
height = Math.round(ratio <= 1 ? size : size / ratio),
|
|
|
|
sortKey = sort[0].key,
|
2016-01-17 08:30:16 +00:00
|
|
|
info = Ox.isNull(data[sortKey]) || Ox.isUndefined(data[sortKey])
|
2016-01-14 07:18:41 +00:00
|
|
|
? ''
|
|
|
|
: Ox.contains(['title', 'random'], sortKey)
|
|
|
|
? (data.author || []).join(', ')
|
|
|
|
: Ox.getObjectById(
|
|
|
|
oml.config.sortKeys, sortKey
|
|
|
|
).format(data[sortKey]);
|
2014-05-04 17:26:43 +00:00
|
|
|
size = size || 64;
|
|
|
|
return {
|
2014-05-21 00:02:39 +00:00
|
|
|
extra: ui.showIconInfo ? $('<div>')
|
2014-05-04 17:26:43 +00:00
|
|
|
.css({
|
|
|
|
width: width + 'px',
|
|
|
|
height: Math.round(size / 12.8) + 'px',
|
|
|
|
borderWidth: Math.round(size / 64) + 'px 0',
|
|
|
|
borderStyle: 'solid',
|
2014-05-12 12:57:47 +00:00
|
|
|
borderColor: 'rgba(' + color[2].join(', ') + ')',
|
2014-05-20 00:44:13 +00:00
|
|
|
margin: Math.round(size / 18) + 'px ' + Math.round(width / 2 - 8) + 'px',
|
2014-05-04 17:26:43 +00:00
|
|
|
fontSize: Math.round(size / 16) + 'px',
|
|
|
|
textAlign: 'center',
|
2014-05-12 12:57:47 +00:00
|
|
|
color: 'rgba(' + color[2].join(', ') + ')',
|
2016-01-24 12:36:24 +00:00
|
|
|
backgroundImage: 'linear-gradient(180deg, ' + color.slice(0, 2).map(function(rgba) {
|
2014-05-12 12:57:47 +00:00
|
|
|
return 'rgba(' + rgba.join(', ') + ')';
|
|
|
|
}).join(', ') + ')',
|
2016-01-24 13:32:38 +00:00
|
|
|
MozTransform: 'rotate(45deg)',
|
2014-05-04 17:26:43 +00:00
|
|
|
WebkitTransform: 'rotate(45deg)'
|
|
|
|
})
|
2016-01-08 08:37:34 +00:00
|
|
|
.text(
|
2014-05-21 00:02:39 +00:00
|
|
|
ui.iconInfo == 'extension'
|
2014-05-04 17:26:43 +00:00
|
|
|
? data.extension.toUpperCase()
|
|
|
|
: Ox.formatValue(data.size, 'B')
|
|
|
|
) : null,
|
|
|
|
height: height,
|
|
|
|
id: data.id,
|
2016-01-08 08:37:34 +00:00
|
|
|
info: Ox.encodeHTMLEntities(info),
|
2016-01-13 11:25:13 +00:00
|
|
|
title: Ox.encodeHTMLEntities(data.title || ''),
|
2015-03-07 14:46:59 +00:00
|
|
|
url: '/' + data.id + '/' + ui.icons + '128.jpg?' + data.modified,
|
2014-05-04 17:26:43 +00:00
|
|
|
width: width
|
|
|
|
};
|
|
|
|
},
|
|
|
|
items: function(data, callback) {
|
|
|
|
oml.api.find(Ox.extend(data, {
|
|
|
|
query: ui.find
|
|
|
|
}), callback);
|
|
|
|
},
|
|
|
|
keys: [
|
2015-03-07 14:46:59 +00:00
|
|
|
'author', 'coverRatio', 'extension', 'id', 'mediastate', 'modified',
|
2014-05-21 00:02:39 +00:00
|
|
|
'previewRatio', 'size', 'textsize', 'title'
|
2014-05-04 17:26:43 +00:00
|
|
|
],
|
|
|
|
max: 1,
|
|
|
|
min: 1,
|
|
|
|
orientation: 'horizontal',
|
|
|
|
// FIXME: is this correct?:
|
|
|
|
selected: ui.item ? [ui.item]
|
|
|
|
: ui.listSelection.length ? [ui.listSelection[0]]
|
|
|
|
: [],
|
|
|
|
size: 64,
|
|
|
|
sort: ui.listSort,
|
|
|
|
unique: 'id'
|
|
|
|
})
|
2015-04-21 17:58:06 +00:00
|
|
|
.css({
|
|
|
|
'overflow-y': 'hidden'
|
|
|
|
})
|
2014-05-04 17:26:43 +00:00
|
|
|
.bindEvent({
|
2016-01-07 05:13:42 +00:00
|
|
|
key_control_delete: function() {
|
2016-01-16 07:48:37 +00:00
|
|
|
if (that.value(
|
|
|
|
that.options('selected')[0], 'mediastate'
|
|
|
|
) == 'available') {
|
2016-01-07 05:13:42 +00:00
|
|
|
oml.ui.deleteItemsDialog().open();
|
|
|
|
}
|
|
|
|
},
|
2014-05-18 23:24:04 +00:00
|
|
|
open: function(data) {
|
|
|
|
if (that.value(data.ids[0], 'mediastate') == 'available') {
|
|
|
|
oml.UI.set({itemView: 'book'});
|
|
|
|
}
|
2014-05-04 17:26:43 +00:00
|
|
|
},
|
|
|
|
select: function(data) {
|
2016-01-16 09:29:34 +00:00
|
|
|
if (ui.item && data.ids.length) {
|
|
|
|
oml.UI.set({
|
|
|
|
item: data.ids[0],
|
|
|
|
itemView: 'info',
|
|
|
|
listSelection: data.ids
|
|
|
|
});
|
2016-01-16 09:48:05 +00:00
|
|
|
} else if (ui.item) {
|
|
|
|
// no longer in context after edit
|
|
|
|
oml.api.find({
|
|
|
|
query: {conditions: [], operator: '&'},
|
|
|
|
positions: [ui.item]
|
|
|
|
}, function(result) {
|
|
|
|
if (result.data.positions[ui.item] === void 0) {
|
|
|
|
// no longer in libraries after delete
|
|
|
|
oml.UI.set({
|
|
|
|
find: {conditions: [], operator: '&'},
|
|
|
|
item: '',
|
|
|
|
listSelection: []
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
Ox.Request.clearCache('find');
|
|
|
|
oml.stayInItemView = true;
|
|
|
|
oml.UI.set({
|
|
|
|
find: {conditions: [], operator: '&'},
|
|
|
|
item: ui.item,
|
|
|
|
listSelection: [ui.item]
|
|
|
|
});
|
|
|
|
oml.stayInItemView = false;
|
|
|
|
}
|
|
|
|
});
|
2016-01-08 04:44:12 +00:00
|
|
|
}
|
2014-05-04 17:26:43 +00:00
|
|
|
},
|
2016-01-10 07:31:58 +00:00
|
|
|
toggle: function(data) {
|
|
|
|
oml.UI.set({showBrowser: !data.collapsed});
|
|
|
|
},
|
2014-05-04 17:26:43 +00:00
|
|
|
oml_find: function() {
|
|
|
|
that.reloadList();
|
|
|
|
},
|
2014-05-21 00:02:39 +00:00
|
|
|
oml_iconinfo: function() {
|
|
|
|
that.reloadList(true);
|
|
|
|
},
|
|
|
|
oml_icons: function() {
|
|
|
|
that.reloadList(true);
|
|
|
|
},
|
|
|
|
oml_showiconinfo: function() {
|
|
|
|
that.reloadList(true);
|
|
|
|
},
|
2014-05-04 17:26:43 +00:00
|
|
|
oml_item: function(data) {
|
|
|
|
if (data.value && !data.previousValue) {
|
|
|
|
that.gainFocus();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
oml_listselection: function(data) {
|
|
|
|
if (data.value.length) {
|
|
|
|
that.options({selected: [data.value[0]]});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
oml_listsort: function(data) {
|
|
|
|
that.options({sort: data.value});
|
|
|
|
},
|
|
|
|
oml_sidebarsize: function(data) {
|
|
|
|
that.size(); // FIXME: DOESN'T CENTER
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-05-12 12:57:47 +00:00
|
|
|
oml.enableDragAndDrop(that);
|
|
|
|
|
2014-05-04 17:26:43 +00:00
|
|
|
return that;
|
|
|
|
|
2015-03-07 14:46:59 +00:00
|
|
|
};
|