// vim: et:ts=4:sw=4:sts=4:ft=javascript 'use strict'; pandora.ui.documentsDialog = function(options) { options = options || {}; var dialogHeight = Math.round((window.innerHeight - 48) * 0.9), dialogWidth = Math.round(window.innerWidth * 0.9), itemWidth = 272 + Ox.UI.SCROLLBAR_SIZE, selected = null, $reloadButton = Ox.Button({ disabled: true, title: 'redo', tooltip: Ox._('Reload'), type: 'image' }) .css({float: 'left', margin: '4px 2px 4px 4px'}) .bindEvent({ click: function() { $reloadButton.options({disabled: true}); Ox.Request.clearCache('findDocuments'); $list.reloadList(true); } }), $userCheckbox = Ox.Checkbox({ title: Ox._('Only show my documents'), value: false }) .css({float: 'left', margin: '4px 2px'}) .bindEvent({ change: function(data) { data.value ? $robotsCheckbox.show() : $robotsCheckbox.hide().options({value: false}); updateList(); } }), $findSelect = Ox.Select({ items: [ {id: 'all', title: Ox._('Find: All')}, {id: 'user', title: Ox._('Find: Username')}, {id: 'file', title: Ox._('Find: Filename')} ], overlap: 'right', type: 'image' }) .bindEvent({ change: function(data) { $findInput.value() && updateList(); $findInput.options({placeholder: data.title}); } }), $findInput = Ox.Input({ changeOnKeypress: true, clear: true, placeholder: Ox._('Find: All'), width: 192 }) .bindEvent({ change: updateList }), $findElement = Ox.FormElementGroup({ elements: [ $findSelect, $findInput ] }) .css({float: 'right', margin: '4px'}), $list = Ox.TableList({ columns: [ { id: 'user', operator: '+', title: Ox._('Username'), visible: true, width: 128 }, { align: 'right', id: 'name', operator: '+', title: Ox._('Filename'), visible: true, width: 256 }, { id: 'extension', operator: '+', title: Ox._('Extension'), visible: true, width: 64 }, { align: 'right', format: function(value) { return Ox.formatValue(value, 'B'); }, id: 'size', operator: '-', title: Ox._('Size'), visible: true, width: 64 }, { align: 'right', id: 'matches', operator: '-', title: Ox._('Matches'), visible: true, width: 64 }, { id: 'description', operator: '+', title: Ox._('Description'), visible: true, width: 256 }, { align: 'right', format: function(value) { return Ox.formatDate(value, '%F %T'); }, id: 'created', operator: '-', title: Ox._('Created'), visible: true, width: 144 }, { align: 'right', format: function(value) { return Ox.formatDate(value, '%F %T'); }, id: 'modified', operator: '-', title: Ox._('Modified'), visible: true, width: 144 } ], columnsVisible: true, items: pandora.api.findDocuments, keys: ['ratio'], query: {conditions: [], operator: '&'}, scrollbarVisible: true, sort: [{key: 'user', operator: '+'}], unique: 'id' }) .bindEvent({ init: function(data) { $status.html( Ox.toTitleCase(Ox.formatCount(data.items, 'file')) ); }, load: function() { $reloadButton.options({disabled: false}); }, select: function(data) { selected = data.ids[0]; selectFile(); options.callback && $doneButton.options({ disabled: !data.ids.length }); } }), $embedButton = Ox.Button({ title: 'embed', tooltip: Ox._('Embed'), type: 'image' }) .css({ float: 'left', margin: '4px 2px 4px 4px' }) .bindEvent({ click: function() { pandora.ui.embedDocumentDialog( $list.options('selected')[0] ).open(); } }), $closeButton = Ox.Button({ title: 'close', tooltip: Ox._('Close'), type: 'image' }) .css({ float: 'left', margin: '4px 4px 4px 2px' }) .bindEvent({ click: function() { $list.options({selected: []}); } }), $item = Ox.Element().css({overflowY: 'scroll'}), $preview, $form, $itemToolbar = Ox.Bar({size: 24}), $deleteButton = Ox.Button({ title: Ox._('Delete Document...'), width: 128 }) .css({float: 'left', margin: '4px'}) .hide() .bindEvent({ click: deleteFile }) .appendTo($itemToolbar), $doneButton = Ox.Button({ disabled: !!options.callback, id: 'done', title: options.callback ? Ox._('Select') : Ox._('Done'), width: 48 }).bindEvent({ click: function() { options.callback && options.callback($list.options('selected')); that.close(); } }), $uploadButton = Ox.FileButton({ maxFiles: 1, title: Ox._('Upload Document...'), width: 128 }) .css({float: 'right', margin: '4px'}) .bindEvent({ click: uploadFile }) .appendTo($itemToolbar), $content = Ox.SplitPanel({ elements: [ { element: Ox.SplitPanel({ elements: [ { element: Ox.Bar({size: 24}) .append($reloadButton) .append($userCheckbox) .append($findElement), size: 24 }, { element: $list } ], orientation: 'vertical' }) }, { element: Ox.SplitPanel({ elements: [ { element: Ox.Bar({size: 24}) .append($itemLabel), size: 24 }, { element: $item }, { element: $itemToolbar, size: 24 } ], orientation: 'vertical' }) .bindEvent({ resize: setWidth }), resizable: true, resize: [ 272 + Ox.UI.SCROLLBAR_SIZE, 400 + Ox.UI.SCROLLBAR_SIZE, 528 + Ox.UI.SCROLLBAR_SIZE ], size: 272 + Ox.UI.SCROLLBAR_SIZE } ], orientation: 'horizontal' }), $itemLabel = Ox.Label({ textAlign: 'center', title: Ox._('No document selected'), width: getLabelWidth() }) .css({ float: 'left', margin: '4px' }), that = Ox.Dialog({ buttons: [$doneButton], closeButton: true, content: $content, height: dialogHeight, maximizeButton: true, minHeight: 256, minWidth: 512, padding: 0, removeOnClose: true, title: Ox._('Manage Documents'), width: dialogWidth }), $status = $('