Initial commit

This commit is contained in:
Alfred Egger 2019-06-12 16:14:52 +02:00
commit ff7217c38c
9 changed files with 1019 additions and 0 deletions

27
js/printer.plugin.js Normal file
View file

@ -0,0 +1,27 @@
(function() {
OCA.Printer = OCA.Printer || {};
/**
* @namespace
*/
OCA.Printer.Util = {
/**
* Initialize the Printer plugin.
*
* @param {OCA.Files.FileList} fileList file list to be extended
*/
attach: function(fileList) {
if (fileList.id === 'trashbin' || fileList.id === 'files.public') {
return;
}
fileList.registerTabView(new OCA.Printer.PrinterTabView('printerTabView', {}));
}
};
})();
OC.Plugins.register('OCA.Files.FileList', OCA.Printer.Util);

150
js/printer.tabview.js Normal file
View file

@ -0,0 +1,150 @@
(function() {
var PrinterTabView = OCA.Files.DetailTabView.extend({
id: 'printerTabView',
className: 'tab printerTabView',
/**
* get label of tab
*/
getLabel: function() {
return t('printer', 'Printer');
},
/**
* get icon of tab
*/
getIcon: function() {
return 'icon-info';
},
/**
* Renders this details view
*
* @abstract
*/
render: function() {
this._renderSelectList(this.$el);
this.delegateEvents({
'change #choose-algorithm': '_onChangeEvent'
});
},
_renderSelectList: function($el) {
$el.html('<div class="get-checksum">'
+ '<select id="choose-algorithm">'
+ '<option value="">' + t('checksum', 'Choose Algorithm') + '</option>'
+ '<option value="md5">MD5</option>'
+ '<option value="sha1">SHA1</option>'
+ '<option value="sha256">SHA256</option>'
+ '<option value="sha384">SHA384</option>'
+ '<option value="sha512">SHA512</option>'
+ '<option value="crc32">CRC32</option>'
+ '</select></div>'
);
},
/**
* show tab only on files
*/
canDisplay: function(fileInfo) {
if(fileInfo != null) {
if(!fileInfo.isDirectory()) {
return true;
}
}
return false;
},
/**
* ajax callback for generating md5 hash
*/
check: function(fileInfo, algorithmType) {
// skip call if fileInfo is null
if(null == fileInfo) {
_self.updateDisplay({
response: 'error',
msg: t('printer', 'No fileinfo provided.')
});
return;
}
var url = OC.generateUrl('/apps/printer/printfile'),
data = {source: fileInfo.getFullPath(), type: algorithmType},
_self = this;
$.ajax({
type: 'GET',
url: url,
dataType: 'json',
data: data,
async: true,
success: function(data) {
_self.updateDisplay(data, algorithmType);
}
});
},
/**
* display message from ajax callback
*/
updateDisplay: function(data, algorithmType) {
var msg = '';
if('success' == data.response) {
msg = algorithmType + ': ' + data.msg;
}
if('error' == data.response) {
msg = data.msg;
}
msg += '<br><br><a id="reload-checksum" class="icon icon-history" style="display:block" href=""></a>';
this.delegateEvents({
'click #reload-checksum': '_onReloadEvent'
});
this.$el.find('.get-checksum').html(msg);
},
/**
* changeHandler
*/
_onChangeEvent: function(ev) {
var algorithmType = $(ev.currentTarget).val();
if(algorithmType != '') {
this.$el.html('<div style="text-align:center; word-wrap:break-word;" class="get-checksum"><p><img src="'
+ OC.imagePath('core','loading.gif')
+ '"><br><br></p><p>'
+ t('printer', 'Printing document ...')
+ '</p></div>');
this.check(this.getFileInfo(), algorithmType);
}
},
_onReloadEvent: function(ev) {
ev.preventDefault();
this._renderSelectList(this.$el);
this.delegateEvents({
'change #choose-algorithm': '_onChangeEvent'
});
}
});
OCA.Printer = OCA.Primter || {};
OCA.Printer.PrinterTabView = PrinterTabView;
})();