openmedialibrary/static/js/itemViewButtons.js

73 lines
1.8 KiB
JavaScript
Raw Normal View History

2014-05-04 17:26:43 +00:00
'use strict';
oml.ui.itemViewButtons = function() {
var ui = oml.user.ui,
that = Ox.ButtonGroup({
buttons: [
{
id: 'info',
title: 'iconlist',
tooltip: Ox._('View Info')
},
{
id: 'book',
title: 'book',
tooltip: Ox._('Read Book')
}
],
selectable: true,
style: 'squared',
type: 'image'
}).css({
float: 'left',
margin: '4px 2px'
})
.bindEvent({
change: function(data) {
oml.UI.set({itemView: data.value});
},
oml_item: function() {
if (ui.item) {
2014-05-17 11:45:57 +00:00
that.updateElement();
2014-05-04 17:26:43 +00:00
} else {
that.disableButton('book');
}
},
oml_itemview: function(data) {
2014-05-17 11:45:57 +00:00
that.updateElement();
2014-05-04 17:26:43 +00:00
}
});
2014-05-17 11:45:57 +00:00
that.updateElement = function() {
2014-05-04 17:26:43 +00:00
var item = ui.item;
that.options({
disabled: ui.itemView != 'book',
value: ui.itemView
});
oml.api.get({
id: item,
keys: ['mediastate']
}, function(result) {
if (item == ui.item) {
that[
result.data.mediastate == 'available'
? 'enableButton' : 'disableButton'
]('book');
}
});
return that;
};
oml.bindEvent({
transfer: function(data) {
if (data.id == ui.item && data.progress == 1) {
that.enableButton('book');
}
}
});
2014-05-17 11:45:57 +00:00
return that.updateElement();
2014-05-04 17:26:43 +00:00
};