Convert and fix codestyle issues
Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
Родитель
eee488d611
Коммит
15827ddba5
|
@ -11,6 +11,8 @@ module.exports = {
|
||||||
n: true,
|
n: true,
|
||||||
OC: true,
|
OC: true,
|
||||||
OCA: true,
|
OCA: true,
|
||||||
|
'$': true,
|
||||||
|
'_': true,
|
||||||
Vue: true,
|
Vue: true,
|
||||||
VueRouter: true
|
VueRouter: true
|
||||||
},
|
},
|
||||||
|
@ -27,6 +29,12 @@ module.exports = {
|
||||||
],
|
],
|
||||||
plugins: ['vue', 'node'],
|
plugins: ['vue', 'node'],
|
||||||
rules: {
|
rules: {
|
||||||
|
// TODO: remove when all fixed
|
||||||
|
'no-unused-vars': 'warn',
|
||||||
|
'no-mixed-operators': 'warn',
|
||||||
|
'camelcase': 'warn',
|
||||||
|
'no-global-assign': 'warn',
|
||||||
|
|
||||||
// space before function ()
|
// space before function ()
|
||||||
'space-before-function-paren': ['error', 'never'],
|
'space-before-function-paren': ['error', 'never'],
|
||||||
// curly braces always space
|
// curly braces always space
|
||||||
|
|
|
@ -38,14 +38,14 @@ $eventDispatcher = \OC::$server->getEventDispatcher();
|
||||||
$eventDispatcher->addListener(
|
$eventDispatcher->addListener(
|
||||||
'OCA\Files::loadAdditionalScripts',
|
'OCA\Files::loadAdditionalScripts',
|
||||||
function() {
|
function() {
|
||||||
\OCP\Util::addScript('richdocuments', 'viewer/viewer');
|
\OCP\Util::addScript('richdocuments', 'viewer');
|
||||||
\OCP\Util::addStyle('richdocuments', 'viewer');
|
\OCP\Util::addStyle('richdocuments', 'viewer');
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
$eventDispatcher->addListener(
|
$eventDispatcher->addListener(
|
||||||
'OCA\Files_Sharing::loadAdditionalScripts',
|
'OCA\Files_Sharing::loadAdditionalScripts',
|
||||||
function() {
|
function() {
|
||||||
\OCP\Util::addScript('richdocuments', 'viewer/viewer');
|
\OCP\Util::addScript('richdocuments', 'viewer');
|
||||||
\OCP\Util::addStyle('richdocuments', 'viewer');
|
\OCP\Util::addStyle('richdocuments', 'viewer');
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
387
src/admin.js
387
src/admin.js
|
@ -1,337 +1,336 @@
|
||||||
/*global OC, $ */
|
/* global OC, $ */
|
||||||
|
|
||||||
var documentsSettings = {
|
var documentsSettings = {
|
||||||
_createExtApp: function() {
|
_createExtApp: function() {
|
||||||
var app1 = document.createElement('div');
|
var app1 = document.createElement('div')
|
||||||
app1.setAttribute('class', 'external-app');
|
app1.setAttribute('class', 'external-app')
|
||||||
|
|
||||||
var appname1 = document.createElement('input');
|
var appname1 = document.createElement('input')
|
||||||
appname1.setAttribute('class', 'external-apps-name');
|
appname1.setAttribute('class', 'external-apps-name')
|
||||||
$(app1).append(appname1);
|
$(app1).append(appname1)
|
||||||
|
|
||||||
var apptoken1 = document.createElement('input');
|
var apptoken1 = document.createElement('input')
|
||||||
apptoken1.setAttribute('class', 'external-apps-token');
|
apptoken1.setAttribute('class', 'external-apps-token')
|
||||||
$(app1).append(apptoken1);
|
$(app1).append(apptoken1)
|
||||||
|
|
||||||
var apptokenbutton = document.createElement('button');
|
var apptokenbutton = document.createElement('button')
|
||||||
apptokenbutton.setAttribute('class', 'external-apps-gen-token-button');
|
apptokenbutton.setAttribute('class', 'external-apps-gen-token-button')
|
||||||
apptokenbutton.innerHTML = 'Generate Token';
|
apptokenbutton.innerHTML = 'Generate Token'
|
||||||
$(app1).append(apptokenbutton);
|
$(app1).append(apptokenbutton)
|
||||||
|
|
||||||
var appremovebutton = document.createElement('button');
|
var appremovebutton = document.createElement('button')
|
||||||
appremovebutton.setAttribute('class', 'external-apps-remove-button');
|
appremovebutton.setAttribute('class', 'external-apps-remove-button')
|
||||||
appremovebutton.innerHTML = 'Remove';
|
appremovebutton.innerHTML = 'Remove'
|
||||||
$(app1).append(appremovebutton);
|
$(app1).append(appremovebutton)
|
||||||
|
|
||||||
return app1;
|
return app1
|
||||||
},
|
},
|
||||||
|
|
||||||
save : function() {
|
save: function() {
|
||||||
$('#wopi_apply, #disable_certificate_verification').attr('disabled', true);
|
$('#wopi_apply, #disable_certificate_verification').attr('disabled', true)
|
||||||
var data = {
|
var data = {
|
||||||
wopi_url: $('#wopi_url').val().replace(/\/$/, ''),
|
wopi_url: $('#wopi_url').val().replace(/\/$/, ''),
|
||||||
disable_certificate_verification: document.getElementById('disable_certificate_verification').checked
|
disable_certificate_verification: document.getElementById('disable_certificate_verification').checked
|
||||||
}
|
}
|
||||||
|
|
||||||
OC.msg.startAction('#documents-admin-msg', t('richdocuments', 'Saving…'));
|
OC.msg.startAction('#documents-admin-msg', t('richdocuments', 'Saving…'))
|
||||||
$.post(
|
$.post(
|
||||||
OC.filePath('richdocuments', 'ajax', 'admin.php'),
|
OC.filePath('richdocuments', 'ajax', 'admin.php'),
|
||||||
data,
|
data,
|
||||||
documentsSettings.afterSave
|
documentsSettings.afterSave
|
||||||
);
|
)
|
||||||
},
|
},
|
||||||
|
|
||||||
saveGroups: function(data) {
|
saveGroups: function(data) {
|
||||||
$.post(
|
$.post(
|
||||||
OC.filePath('richdocuments', 'ajax', 'admin.php'),
|
OC.filePath('richdocuments', 'ajax', 'admin.php'),
|
||||||
data
|
data
|
||||||
);
|
)
|
||||||
},
|
},
|
||||||
|
|
||||||
saveDocFormat: function(format) {
|
saveDocFormat: function(format) {
|
||||||
$.post(
|
$.post(
|
||||||
OC.filePath('richdocuments', 'ajax', 'admin.php'),
|
OC.filePath('richdocuments', 'ajax', 'admin.php'),
|
||||||
{ 'doc_format': format }
|
{ 'doc_format': format }
|
||||||
);
|
)
|
||||||
},
|
},
|
||||||
|
|
||||||
afterSave : function(response){
|
afterSave: function(response) {
|
||||||
$('#wopi_apply, #disable_certificate_verification').attr('disabled', false);
|
$('#wopi_apply, #disable_certificate_verification').attr('disabled', false)
|
||||||
OC.msg.finishedAction('#documents-admin-msg', response);
|
OC.msg.finishedAction('#documents-admin-msg', response)
|
||||||
},
|
},
|
||||||
|
|
||||||
saveExternalApps: function(externalAppsData) {
|
saveExternalApps: function(externalAppsData) {
|
||||||
var data = {
|
var data = {
|
||||||
'external_apps': externalAppsData
|
'external_apps': externalAppsData
|
||||||
};
|
}
|
||||||
|
|
||||||
OC.msg.startAction('#enable-external-apps-section-msg', t('richdocuments', 'Saving…'));
|
OC.msg.startAction('#enable-external-apps-section-msg', t('richdocuments', 'Saving…'))
|
||||||
$.post(
|
$.post(
|
||||||
OC.filePath('richdocuments', 'ajax', 'admin.php'),
|
OC.filePath('richdocuments', 'ajax', 'admin.php'),
|
||||||
data,
|
data,
|
||||||
documentsSettings.afterSaveExternalApps
|
documentsSettings.afterSaveExternalApps
|
||||||
);
|
)
|
||||||
},
|
},
|
||||||
|
|
||||||
saveWebroot: function(value) {
|
saveWebroot: function(value) {
|
||||||
var data = {
|
var data = {
|
||||||
'canonical_webroot': value
|
'canonical_webroot': value
|
||||||
};
|
}
|
||||||
$.post(
|
$.post(
|
||||||
OC.filePath('richdocuments', 'ajax', 'admin.php'),
|
OC.filePath('richdocuments', 'ajax', 'admin.php'),
|
||||||
data
|
data
|
||||||
);
|
)
|
||||||
},
|
},
|
||||||
|
|
||||||
afterSaveExternalApps: function(response) {
|
afterSaveExternalApps: function(response) {
|
||||||
OC.msg.finishedAction('#enable-external-apps-section-msg', response);
|
OC.msg.finishedAction('#enable-external-apps-section-msg', response)
|
||||||
},
|
},
|
||||||
|
|
||||||
initGroups: function() {
|
initGroups: function() {
|
||||||
var selectorPrefixes = [
|
var selectorPrefixes = [
|
||||||
'edit',
|
'edit',
|
||||||
'use'
|
'use'
|
||||||
];
|
]
|
||||||
|
|
||||||
for (i = 0; i < selectorPrefixes.length; i++) {
|
for (var i = 0; i < selectorPrefixes.length; i++) {
|
||||||
var selectorPrefix = selectorPrefixes[i];
|
var selectorPrefix = selectorPrefixes[i]
|
||||||
|
|
||||||
var groups = $('#' + selectorPrefix + '_group_select').val();
|
var groups = $('#' + selectorPrefix + '_group_select').val()
|
||||||
if (groups !== '') {
|
if (groups !== '') {
|
||||||
OC.Settings.setupGroupsSelect($('#' + selectorPrefix + '_group_select'));
|
OC.Settings.setupGroupsSelect($('#' + selectorPrefix + '_group_select'))
|
||||||
$('.' + selectorPrefix + '-groups-enable').attr('checked', 'checked');
|
$('.' + selectorPrefix + '-groups-enable').attr('checked', 'checked')
|
||||||
} else {
|
} else {
|
||||||
$('.' + selectorPrefix + '-groups-enable').attr('checked', null);
|
$('.' + selectorPrefix + '-groups-enable').attr('checked', null)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
initExternalApps: function() {
|
initExternalApps: function() {
|
||||||
var externalAppsRaw = $(document).find('#external-apps-raw').val();
|
var externalAppsRaw = $(document).find('#external-apps-raw').val()
|
||||||
var apps = externalAppsRaw.split(',');
|
var apps = externalAppsRaw.split(',')
|
||||||
for (var i = 0; i < apps.length; ++i) {
|
for (var i = 0; i < apps.length; ++i) {
|
||||||
if (apps[i] !== '') {
|
if (apps[i] !== '') {
|
||||||
var app = apps[i].split(':');
|
var app = apps[i].split(':')
|
||||||
var app1 = this._createExtApp();
|
var app1 = this._createExtApp()
|
||||||
// create a placeholder for adding new app
|
// create a placeholder for adding new app
|
||||||
$('#external-apps-section').append(app1);
|
$('#external-apps-section').append(app1)
|
||||||
$(app1).find('.external-apps-name').val(app[0]);
|
$(app1).find('.external-apps-name').val(app[0])
|
||||||
$(app1).find('.external-apps-token').val(app[1]);
|
$(app1).find('.external-apps-token').val(app[1])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
initialize: function() {
|
initialize: function() {
|
||||||
documentsSettings.initGroups();
|
documentsSettings.initGroups()
|
||||||
documentsSettings.initExternalApps();
|
documentsSettings.initExternalApps()
|
||||||
|
|
||||||
var page = $('#richdocuments');
|
var page = $('#richdocuments')
|
||||||
|
|
||||||
$('#wopi_apply').on('click', documentsSettings.save);
|
$('#wopi_apply').on('click', documentsSettings.save)
|
||||||
|
|
||||||
// destroy or create app name and token fields depending on whether the checkbox is on or off
|
// destroy or create app name and token fields depending on whether the checkbox is on or off
|
||||||
$(document).on('change', '#enable_external_apps_cb-richdocuments', function() {
|
$(document).on('change', '#enable_external_apps_cb-richdocuments', function() {
|
||||||
page.find('#enable-external-apps-section').toggleClass('hidden', !this.checked);
|
page.find('#enable-external-apps-section').toggleClass('hidden', !this.checked)
|
||||||
if (this.checked) {
|
if (this.checked) {
|
||||||
var app1 = documentsSettings._createExtApp();
|
var app1 = documentsSettings._createExtApp()
|
||||||
$('#external-apps-section').append(app1);
|
$('#external-apps-section').append(app1)
|
||||||
} else {
|
} else {
|
||||||
page.find('.external-app').remove();
|
page.find('.external-app').remove()
|
||||||
page.find('#external-apps-raw').val('');
|
page.find('#external-apps-raw').val('')
|
||||||
documentsSettings.saveExternalApps('');
|
documentsSettings.saveExternalApps('')
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
|
||||||
$(document).on('click', '.external-apps-gen-token-button', function() {
|
$(document).on('click', '.external-apps-gen-token-button', function() {
|
||||||
var appToken = page.find('.external-apps-token');
|
var appToken = page.find('.external-apps-token')
|
||||||
|
|
||||||
// generate a random string
|
// generate a random string
|
||||||
var len = 3;
|
var len = 3
|
||||||
var array = new Uint32Array(len);
|
var array = new Uint32Array(len)
|
||||||
window.crypto.getRandomValues(array);
|
window.crypto.getRandomValues(array)
|
||||||
var random = '';
|
var random = ''
|
||||||
for (var i = 0; i < len; ++i) {
|
for (var i = 0; i < len; ++i) {
|
||||||
random += array[i].toString(36);
|
random += array[i].toString(36)
|
||||||
}
|
}
|
||||||
|
|
||||||
// set the token in the field
|
// set the token in the field
|
||||||
appToken.val(random);
|
appToken.val(random)
|
||||||
});
|
})
|
||||||
|
|
||||||
$(document).on('click', '.external-apps-remove-button', function() {
|
$(document).on('click', '.external-apps-remove-button', function() {
|
||||||
$(this).parent().remove();
|
$(this).parent().remove()
|
||||||
});
|
})
|
||||||
|
|
||||||
$(document).on('click', '#external-apps-save-button', function() {
|
$(document).on('click', '#external-apps-save-button', function() {
|
||||||
// read all the data in input fields, save the data in input-raw and send to backedn
|
// read all the data in input fields, save the data in input-raw and send to backedn
|
||||||
var extAppsSection = $(this).parent();
|
var extAppsSection = $(this).parent()
|
||||||
var apps = extAppsSection.find('.external-app');
|
var apps = extAppsSection.find('.external-app')
|
||||||
// convert all values into one single string and store it in raw input field
|
// convert all values into one single string and store it in raw input field
|
||||||
// as well as send the data to server
|
// as well as send the data to server
|
||||||
var raw = '';
|
var raw = ''
|
||||||
for (var i = 0; i < apps.length; ++i) {
|
for (var i = 0; i < apps.length; ++i) {
|
||||||
var appname = $(apps[i]).find('.external-apps-name');
|
var appname = $(apps[i]).find('.external-apps-name')
|
||||||
var apptoken = $(apps[i]).find('.external-apps-token');
|
var apptoken = $(apps[i]).find('.external-apps-token')
|
||||||
raw += appname.val() + ':' + apptoken.val() + ',';
|
raw += appname.val() + ':' + apptoken.val() + ','
|
||||||
}
|
}
|
||||||
|
|
||||||
extAppsSection.find('#external-apps-raw').val(raw);
|
extAppsSection.find('#external-apps-raw').val(raw)
|
||||||
documentsSettings.saveExternalApps(raw);
|
documentsSettings.saveExternalApps(raw)
|
||||||
});
|
})
|
||||||
|
|
||||||
$(document).on('click', '#external-apps-add-button', function() {
|
$(document).on('click', '#external-apps-add-button', function() {
|
||||||
// create a placeholder for adding new app
|
// create a placeholder for adding new app
|
||||||
var app1 = documentsSettings._createExtApp();
|
var app1 = documentsSettings._createExtApp()
|
||||||
$('#external-apps-section').append(app1);
|
$('#external-apps-section').append(app1)
|
||||||
});
|
})
|
||||||
|
|
||||||
$(document).on('click', '#test_wopi_apply', function() {
|
$(document).on('click', '#test_wopi_apply', function() {
|
||||||
var groups = page.find('#test_server_group_select').val();
|
var groups = page.find('#test_server_group_select').val()
|
||||||
var testserver = page.find('#test_wopi_url').val();
|
var testserver = page.find('#test_wopi_url').val()
|
||||||
|
|
||||||
if (groups !== '' && testserver !== '') {
|
if (groups !== '' && testserver !== '') {
|
||||||
documentsSettings.saveTestWopi(groups, testserver);
|
documentsSettings.saveTestWopi(groups, testserver)
|
||||||
} else {
|
} else {
|
||||||
OC.msg.finishedError('#test-documents-admin-msg', 'Both fields required');
|
OC.msg.finishedError('#test-documents-admin-msg', 'Both fields required')
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
|
||||||
$(document).on('change', '.doc-format-ooxml', function() {
|
$(document).on('change', '.doc-format-ooxml', function() {
|
||||||
var ooxml = this.checked;
|
var ooxml = this.checked
|
||||||
documentsSettings.saveDocFormat(ooxml ? 'ooxml' : 'odf');
|
documentsSettings.saveDocFormat(ooxml ? 'ooxml' : 'odf')
|
||||||
});
|
})
|
||||||
|
|
||||||
$(document).on('change', '#edit_group_select', function() {
|
$(document).on('change', '#edit_group_select', function() {
|
||||||
var element = page.find('input.edit-groups-enable');
|
var element = page.find('input.edit-groups-enable')
|
||||||
var groups = $(this).val();
|
var groups = $(this).val()
|
||||||
documentsSettings.saveGroups({edit_groups: groups});
|
documentsSettings.saveGroups({ edit_groups: groups })
|
||||||
});
|
})
|
||||||
|
|
||||||
$(document).on('change', '.edit-groups-enable', function() {
|
$(document).on('change', '.edit-groups-enable', function() {
|
||||||
var $select = page.find('#edit_group_select');
|
var $select = page.find('#edit_group_select')
|
||||||
$select.val('');
|
$select.val('')
|
||||||
|
|
||||||
if (this.checked) {
|
|
||||||
OC.Settings.setupGroupsSelect($select, {
|
|
||||||
placeholder: t('core', 'All')
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
$select.select2('destroy');
|
|
||||||
}
|
|
||||||
|
|
||||||
$select.change();
|
|
||||||
});
|
|
||||||
|
|
||||||
$(document).on('change', '#use_group_select', function() {
|
|
||||||
var element = page.find('input.use-groups-enable');
|
|
||||||
var groups = $(this).val();
|
|
||||||
documentsSettings.saveGroups({use_groups: groups});
|
|
||||||
});
|
|
||||||
|
|
||||||
$(document).on('change', '.use-groups-enable', function() {
|
|
||||||
var $select = page.find('#use_group_select');
|
|
||||||
$select.val('');
|
|
||||||
|
|
||||||
if (this.checked) {
|
if (this.checked) {
|
||||||
OC.Settings.setupGroupsSelect($select, {
|
OC.Settings.setupGroupsSelect($select, {
|
||||||
placeholder: t('core', 'All')
|
placeholder: t('core', 'All')
|
||||||
});
|
})
|
||||||
} else {
|
} else {
|
||||||
$select.select2('destroy');
|
$select.select2('destroy')
|
||||||
}
|
}
|
||||||
|
|
||||||
$select.change();
|
$select.change()
|
||||||
});
|
})
|
||||||
|
|
||||||
|
$(document).on('change', '#use_group_select', function() {
|
||||||
|
var element = page.find('input.use-groups-enable')
|
||||||
|
var groups = $(this).val()
|
||||||
|
documentsSettings.saveGroups({ use_groups: groups })
|
||||||
|
})
|
||||||
|
|
||||||
|
$(document).on('change', '.use-groups-enable', function() {
|
||||||
|
var $select = page.find('#use_group_select')
|
||||||
|
$select.val('')
|
||||||
|
|
||||||
|
if (this.checked) {
|
||||||
|
OC.Settings.setupGroupsSelect($select, {
|
||||||
|
placeholder: t('core', 'All')
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
$select.select2('destroy')
|
||||||
|
}
|
||||||
|
|
||||||
|
$select.change()
|
||||||
|
})
|
||||||
|
|
||||||
$(document).on('change', '#enable_canonical_webroot_cb-richdocuments', function() {
|
$(document).on('change', '#enable_canonical_webroot_cb-richdocuments', function() {
|
||||||
page.find('#enable-canonical-webroot-section').toggleClass('hidden', !this.checked);
|
page.find('#enable-canonical-webroot-section').toggleClass('hidden', !this.checked)
|
||||||
if (!this.checked) {
|
if (!this.checked) {
|
||||||
documentsSettings.saveWebroot('');
|
documentsSettings.saveWebroot('')
|
||||||
} else {
|
} else {
|
||||||
var val = $('#canonical-webroot').val();
|
var val = $('#canonical-webroot').val()
|
||||||
if (val)
|
if (val) { documentsSettings.saveWebroot() }
|
||||||
documentsSettings.saveWebroot();
|
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
|
||||||
$(document).on('change', '#canonical-webroot', function() {
|
$(document).on('change', '#canonical-webroot', function() {
|
||||||
documentsSettings.saveWebroot(this.value);
|
documentsSettings.saveWebroot(this.value)
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Append a new template to the dom
|
* Append a new template to the dom
|
||||||
*
|
*
|
||||||
* @param {Object} data the template data from the template controller response
|
* @param {Object} data the template data from the template controller response
|
||||||
*/
|
*/
|
||||||
function appendTemplateFromData(data) {
|
function appendTemplateFromData(data) {
|
||||||
var template = document.querySelector('.template-model').cloneNode(true);
|
var template = document.querySelector('.template-model').cloneNode(true)
|
||||||
template.className = '';
|
template.className = ''
|
||||||
template.querySelector('img').src = data.preview;
|
template.querySelector('img').src = data.preview
|
||||||
template.querySelector('figcaption').textContent = data.name;
|
template.querySelector('figcaption').textContent = data.name
|
||||||
template.querySelector('.delete-template').href = data.delete;
|
template.querySelector('.delete-template').href = data.delete
|
||||||
|
|
||||||
document.querySelector('#richdocuments-templates > ul').appendChild(template);
|
document.querySelector('#richdocuments-templates > ul').appendChild(template)
|
||||||
template.querySelector('.delete-template').addEventListener('click', deleteTemplate);
|
template.querySelector('.delete-template').addEventListener('click', deleteTemplate)
|
||||||
};
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete template event handler
|
* Delete template event handler
|
||||||
*
|
*
|
||||||
* @param {Event} event
|
* @param {Event} event
|
||||||
*/
|
*/
|
||||||
function deleteTemplate(event) {
|
function deleteTemplate(event) {
|
||||||
event.preventDefault();
|
event.preventDefault()
|
||||||
var emptyElmt = document.querySelector('#richdocuments-templates #emptycontent');
|
var emptyElmt = document.querySelector('#richdocuments-templates #emptycontent')
|
||||||
var tplListElmt = document.querySelector('#richdocuments-templates > ul');
|
var tplListElmt = document.querySelector('#richdocuments-templates > ul')
|
||||||
var elmt = event.target;
|
var elmt = event.target
|
||||||
|
|
||||||
// ensure no request is in progress
|
// ensure no request is in progress
|
||||||
if (elmt.className.indexOf('loading') === -1 && elmt.textContent === '') {
|
if (elmt.className.indexOf('loading') === -1 && elmt.textContent === '') {
|
||||||
var remote = event.target.href;
|
var remote = event.target.href
|
||||||
elmt.classList.add('icon-loading');
|
elmt.classList.add('icon-loading')
|
||||||
elmt.classList.remove('icon-delete');
|
elmt.classList.remove('icon-delete')
|
||||||
|
|
||||||
// send request
|
// send request
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: remote,
|
url: remote,
|
||||||
type: 'DELETE',
|
type: 'DELETE'
|
||||||
})
|
})
|
||||||
.done(function() {
|
.done(function() {
|
||||||
// remove template
|
// remove template
|
||||||
elmt.parentElement.remove();
|
elmt.parentElement.remove()
|
||||||
// is list empty? Only the default template is left
|
// is list empty? Only the default template is left
|
||||||
if (tplListElmt.querySelectorAll('li').length === 1) {
|
if (tplListElmt.querySelectorAll('li').length === 1) {
|
||||||
tplListElmt.classList.add('hidden');
|
tplListElmt.classList.add('hidden')
|
||||||
emptyElmt.classList.remove('hidden');
|
emptyElmt.classList.remove('hidden')
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.fail(function(e) {
|
.fail(function(e) {
|
||||||
// failure, show warning
|
// failure, show warning
|
||||||
elmt.textContent = t('richdocuments', 'Error');
|
elmt.textContent = t('richdocuments', 'Error')
|
||||||
elmt.classList.remove('icon-loading');
|
elmt.classList.remove('icon-loading')
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
elmt.classList.add('icon-delete');
|
elmt.classList.add('icon-delete')
|
||||||
elmt.textContent = '';
|
elmt.textContent = ''
|
||||||
}, 2000);
|
}, 2000)
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Init the upload manager and the delete template handler
|
* Init the upload manager and the delete template handler
|
||||||
*/
|
*/
|
||||||
function initTemplateManager() {
|
function initTemplateManager() {
|
||||||
var inputElmt = document.querySelector('#add-template');
|
var inputElmt = document.querySelector('#add-template')
|
||||||
var buttonElmt = document.querySelector('.icon-add');
|
var buttonElmt = document.querySelector('.icon-add')
|
||||||
var deleteElmts = document.querySelectorAll('.delete-template');
|
var deleteElmts = document.querySelectorAll('.delete-template')
|
||||||
var emptyElmt = document.querySelector('#richdocuments-templates #emptycontent');
|
var emptyElmt = document.querySelector('#richdocuments-templates #emptycontent')
|
||||||
var tplListElmt = document.querySelector('#richdocuments-templates > ul');
|
var tplListElmt = document.querySelector('#richdocuments-templates > ul')
|
||||||
|
|
||||||
deleteElmts.forEach(function(elmt) {
|
deleteElmts.forEach(function(elmt) {
|
||||||
elmt.addEventListener('click', deleteTemplate);
|
elmt.addEventListener('click', deleteTemplate)
|
||||||
});
|
})
|
||||||
|
|
||||||
// fileupload plugin
|
// fileupload plugin
|
||||||
$('#richdocuments-templates').fileupload({
|
$('#richdocuments-templates').fileupload({
|
||||||
|
@ -339,42 +338,42 @@ function initTemplateManager() {
|
||||||
url: OC.generateUrl('apps/richdocuments/template'),
|
url: OC.generateUrl('apps/richdocuments/template'),
|
||||||
type: 'POST',
|
type: 'POST',
|
||||||
|
|
||||||
add: function (e, data) {
|
add: function(e, data) {
|
||||||
// submit on file selection
|
// submit on file selection
|
||||||
data.submit();
|
data.submit()
|
||||||
inputElmt.disabled = true;
|
inputElmt.disabled = true
|
||||||
buttonElmt.className = 'icon-loading-small';
|
buttonElmt.className = 'icon-loading-small'
|
||||||
},
|
},
|
||||||
|
|
||||||
submit: function(e, data) {
|
submit: function(e, data) {
|
||||||
data.formData = _.extend(data.formData || {}, {
|
data.formData = _.extend(data.formData || {}, {
|
||||||
requesttoken: OC.requestToken
|
requesttoken: OC.requestToken
|
||||||
});
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
success: function(e, data) {
|
success: function(e, data) {
|
||||||
inputElmt.disabled = false;
|
inputElmt.disabled = false
|
||||||
buttonElmt.className = 'icon-add';
|
buttonElmt.className = 'icon-add'
|
||||||
// add template to dom
|
// add template to dom
|
||||||
appendTemplateFromData(e.data);
|
appendTemplateFromData(e.data)
|
||||||
tplListElmt.classList.remove('hidden');
|
tplListElmt.classList.remove('hidden')
|
||||||
emptyElmt.classList.add('hidden');
|
emptyElmt.classList.add('hidden')
|
||||||
},
|
},
|
||||||
|
|
||||||
fail: function(e, data) {
|
fail: function(e, data) {
|
||||||
// failure, show warning
|
// failure, show warning
|
||||||
buttonElmt.className = 'icon-add';
|
buttonElmt.className = 'icon-add'
|
||||||
buttonElmt.textContent = t('richdocuments', 'An error occurred');
|
buttonElmt.textContent = t('richdocuments', 'An error occurred')
|
||||||
// TODO: add error message from server
|
// TODO: add error message from server
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
inputElmt.disabled = false;
|
inputElmt.disabled = false
|
||||||
buttonElmt.textContent = '';
|
buttonElmt.textContent = ''
|
||||||
}, 2000);
|
}, 2000)
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
$(document).ready(function(){
|
$(document).ready(function() {
|
||||||
documentsSettings.initialize();
|
documentsSettings.initialize()
|
||||||
initTemplateManager();
|
initTemplateManager()
|
||||||
});
|
})
|
||||||
|
|
1028
src/document.js
1028
src/document.js
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -1,63 +1,62 @@
|
||||||
$(function () {
|
$(function() {
|
||||||
|
|
||||||
$('[data-toggle="tooltip"]').tooltip();
|
$('[data-toggle="tooltip"]').tooltip()
|
||||||
|
|
||||||
var PersonalSettings = function () {
|
var PersonalSettings = function() {
|
||||||
this.templateInput = document.getElementById('templateInputField');
|
this.templateInput = document.getElementById('templateInputField')
|
||||||
this.templateSelectButton = document.getElementById('templateSelectButton');
|
this.templateSelectButton = document.getElementById('templateSelectButton')
|
||||||
this.templateResetButton = document.getElementById('templateResetButton');
|
this.templateResetButton = document.getElementById('templateResetButton')
|
||||||
|
|
||||||
var self = this;
|
var self = this
|
||||||
this.templateSelectButton.addEventListener('click', function() {
|
this.templateSelectButton.addEventListener('click', function() {
|
||||||
OC.dialogs.filepicker(t('richdocuments', 'Select a personal template folder'), function(datapath, returntype) {
|
OC.dialogs.filepicker(t('richdocuments', 'Select a personal template folder'), function(datapath, returntype) {
|
||||||
self.updateSetting(datapath);
|
self.updateSetting(datapath)
|
||||||
}, false, 'httpd/unix-directory', true, OC.dialogs.FILEPICKER_TYPE_CHOOSE);
|
}, false, 'httpd/unix-directory', true, OC.dialogs.FILEPICKER_TYPE_CHOOSE)
|
||||||
});
|
})
|
||||||
|
|
||||||
this.templateResetButton.addEventListener('click', this.resetSettings.bind(this));
|
this.templateResetButton.addEventListener('click', this.resetSettings.bind(this))
|
||||||
};
|
}
|
||||||
|
|
||||||
PersonalSettings.prototype.updateSetting = function (path) {
|
PersonalSettings.prototype.updateSetting = function(path) {
|
||||||
var self = this;
|
var self = this
|
||||||
this._updateSetting({templateFolder: path}, function() {
|
this._updateSetting({ templateFolder: path }, function() {
|
||||||
self.templateInput.value = path;
|
self.templateInput.value = path
|
||||||
}, function () {
|
}, function() {
|
||||||
|
|
||||||
});
|
})
|
||||||
};
|
}
|
||||||
|
|
||||||
PersonalSettings.prototype.resetSettings = function() {
|
PersonalSettings.prototype.resetSettings = function() {
|
||||||
var self = this;
|
var self = this
|
||||||
this._updateSetting({templateFolder: ''}, function() {
|
this._updateSetting({ templateFolder: '' }, function() {
|
||||||
self.templateInput.value = '';
|
self.templateInput.value = ''
|
||||||
}, function () {
|
}, function() {
|
||||||
|
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
PersonalSettings.prototype._updateSetting = function(data, successCallback, errorCallback) {
|
PersonalSettings.prototype._updateSetting = function(data, successCallback, errorCallback) {
|
||||||
OC.msg.startAction('#documents-admin-msg', t('richdocuments', 'Saving…'));
|
OC.msg.startAction('#documents-admin-msg', t('richdocuments', 'Saving…'))
|
||||||
var request = new XMLHttpRequest();
|
var request = new XMLHttpRequest()
|
||||||
request.open('POST', OC.filePath('richdocuments', 'ajax', 'personal.php'), true);
|
request.open('POST', OC.filePath('richdocuments', 'ajax', 'personal.php'), true)
|
||||||
request.setRequestHeader("Content-Type", "application/json");
|
request.setRequestHeader('Content-Type', 'application/json')
|
||||||
request.setRequestHeader("requesttoken", OC.requestToken);
|
request.setRequestHeader('requesttoken', OC.requestToken)
|
||||||
request.onload = function() {
|
request.onload = function() {
|
||||||
if (request.status >= 200 && request.status < 400) {
|
if (request.status >= 200 && request.status < 400) {
|
||||||
var response = JSON.parse(request.response);
|
var response = JSON.parse(request.response)
|
||||||
OC.msg.finishedAction('#documents-admin-msg', response);
|
OC.msg.finishedAction('#documents-admin-msg', response)
|
||||||
successCallback(response);
|
successCallback(response)
|
||||||
} else {
|
} else {
|
||||||
errorCallback(this.response);
|
errorCallback(this.response)
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
request.onerror = function() {
|
request.onerror = function() {
|
||||||
errorCallback(this.response);
|
errorCallback(this.response)
|
||||||
};
|
}
|
||||||
|
|
||||||
request.send(JSON.stringify(data));
|
request.send(JSON.stringify(data))
|
||||||
}
|
}
|
||||||
|
|
||||||
new PersonalSettings();
|
return new PersonalSettings()
|
||||||
|
})
|
||||||
});
|
|
||||||
|
|
372
src/viewer.js
372
src/viewer.js
|
@ -1,51 +1,48 @@
|
||||||
/* globals FileList, OCA.Files.fileActions, oc_debug */
|
function getSearchParam(name) {
|
||||||
|
var results = new RegExp('[?&]' + name + '=([^&#]*)').exec(window.location.href)
|
||||||
function getSearchParam(name){
|
if (results === null) {
|
||||||
var results = new RegExp('[\?&]' + name + '=([^&#]*)').exec(window.location.href);
|
return null
|
||||||
if (results === null){
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
return decodeURI(results[1]) || 0;
|
return decodeURI(results[1]) || 0
|
||||||
}
|
}
|
||||||
|
|
||||||
var preload_type = getSearchParam('richdocuments_create');
|
var preloadType = getSearchParam('richdocuments_create')
|
||||||
var preload_filename = getSearchParam('richdocuments_filename');
|
var preloadFilename = getSearchParam('richdocuments_filename')
|
||||||
var Preload = {
|
var Preload = {
|
||||||
create: {
|
create: {
|
||||||
type: preload_type,
|
type: preloadType,
|
||||||
filename: preload_filename,
|
filename: preloadFilename
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
var odfViewer = {
|
var odfViewer = {
|
||||||
isDocuments : false,
|
isDocuments: false,
|
||||||
nextcloudVersion: 0,
|
nextcloudVersion: 0,
|
||||||
receivedLoading: false,
|
receivedLoading: false,
|
||||||
supportedMimes: OC.getCapabilities().richdocuments.mimetypes.concat(OC.getCapabilities().richdocuments.mimetypesNoDefaultOpen),
|
supportedMimes: OC.getCapabilities().richdocuments.mimetypes.concat(OC.getCapabilities().richdocuments.mimetypesNoDefaultOpen),
|
||||||
excludeMimeFromDefaultOpen: OC.getCapabilities().richdocuments.mimetypesNoDefaultOpen,
|
excludeMimeFromDefaultOpen: OC.getCapabilities().richdocuments.mimetypesNoDefaultOpen,
|
||||||
register : function() {
|
register: function() {
|
||||||
odfViewer.nextcloudVersion = parseInt(OC.config.version.split('.')[0]);
|
odfViewer.nextcloudVersion = parseInt(OC.config.version.split('.')[0])
|
||||||
var i,
|
var i, mime
|
||||||
mime;
|
var editActionName = 'Edit with ' + OC.getCapabilities().richdocuments.productName
|
||||||
var editActionName = 'Edit with ' + OC.getCapabilities().richdocuments.productName;
|
|
||||||
for (i = 0; i < odfViewer.supportedMimes.length; ++i) {
|
for (i = 0; i < odfViewer.supportedMimes.length; ++i) {
|
||||||
mime = odfViewer.supportedMimes[i];
|
mime = odfViewer.supportedMimes[i]
|
||||||
OCA.Files.fileActions.register(
|
OCA.Files.fileActions.register(
|
||||||
mime,
|
mime,
|
||||||
editActionName,
|
editActionName,
|
||||||
OC.PERMISSION_UPDATE | OC.PERMISSION_READ,
|
OC.PERMISSION_UPDATE | OC.PERMISSION_READ,
|
||||||
OC.imagePath('core', 'actions/rename'),
|
OC.imagePath('core', 'actions/rename'),
|
||||||
odfViewer.onEdit,
|
odfViewer.onEdit,
|
||||||
t('richdocuments', 'Edit with {productName}', { productName: OC.getCapabilities().richdocuments.productName })
|
t('richdocuments', 'Edit with {productName}', { productName: OC.getCapabilities().richdocuments.productName })
|
||||||
);
|
)
|
||||||
if (odfViewer.excludeMimeFromDefaultOpen.indexOf(mime) === -1) {
|
if (odfViewer.excludeMimeFromDefaultOpen.indexOf(mime) === -1) {
|
||||||
OCA.Files.fileActions.setDefault(mime, editActionName);
|
OCA.Files.fileActions.setDefault(mime, editActionName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
dispatch : function(filename){
|
dispatch: function(filename) {
|
||||||
odfViewer.onEdit(filename);
|
odfViewer.onEdit(filename)
|
||||||
},
|
},
|
||||||
|
|
||||||
getNewDocumentFromTemplateUrl: function(templateId, fileName, fileDir, fillWithTemplate) {
|
getNewDocumentFromTemplateUrl: function(templateId, fileName, fileDir, fillWithTemplate) {
|
||||||
|
@ -57,19 +54,19 @@ var odfViewer = {
|
||||||
dir: fileDir,
|
dir: fileDir,
|
||||||
requesttoken: OC.requestToken
|
requesttoken: OC.requestToken
|
||||||
}
|
}
|
||||||
);
|
)
|
||||||
},
|
},
|
||||||
|
|
||||||
onEdit : function(fileName, context) {
|
onEdit: function(fileName, context) {
|
||||||
if(context) {
|
if (context) {
|
||||||
var fileDir = context.dir;
|
var fileDir = context.dir
|
||||||
var fileId = context.fileId || context.$file.attr('data-id');
|
var fileId = context.fileId || context.$file.attr('data-id')
|
||||||
var templateId = context.templateId;
|
var templateId = context.templateId
|
||||||
}
|
}
|
||||||
odfViewer.receivedLoading = false;
|
odfViewer.receivedLoading = false
|
||||||
|
|
||||||
var viewer;
|
var viewer
|
||||||
if($('#isPublic').val() === '1') {
|
if ($('#isPublic').val() === '1') {
|
||||||
viewer = OC.generateUrl(
|
viewer = OC.generateUrl(
|
||||||
'apps/richdocuments/public?shareToken={shareToken}&fileName={fileName}&requesttoken={requesttoken}&fileId={fileId}',
|
'apps/richdocuments/public?shareToken={shareToken}&fileName={fileName}&requesttoken={requesttoken}&fileId={fileId}',
|
||||||
{
|
{
|
||||||
|
@ -78,11 +75,11 @@ var odfViewer = {
|
||||||
fileId: fileId,
|
fileId: fileId,
|
||||||
requesttoken: OC.requestToken
|
requesttoken: OC.requestToken
|
||||||
}
|
}
|
||||||
);
|
)
|
||||||
} else {
|
} else {
|
||||||
// We are dealing with a template
|
// We are dealing with a template
|
||||||
if (typeof(templateId) !== 'undefined') {
|
if (typeof (templateId) !== 'undefined') {
|
||||||
viewer = this.getNewDocumentFromTemplateUrl(templateId, fileName, fileDir);
|
viewer = this.getNewDocumentFromTemplateUrl(templateId, fileName, fileDir)
|
||||||
} else {
|
} else {
|
||||||
viewer = OC.generateUrl(
|
viewer = OC.generateUrl(
|
||||||
'apps/richdocuments/index?fileId={fileId}&requesttoken={requesttoken}',
|
'apps/richdocuments/index?fileId={fileId}&requesttoken={requesttoken}',
|
||||||
|
@ -91,117 +88,116 @@ var odfViewer = {
|
||||||
dir: fileDir,
|
dir: fileDir,
|
||||||
requesttoken: OC.requestToken
|
requesttoken: OC.requestToken
|
||||||
}
|
}
|
||||||
);
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(context) {
|
if (context) {
|
||||||
FileList.setViewerMode(true);
|
FileList.setViewerMode(true)
|
||||||
FileList.setPageTitle(fileName);
|
FileList.setPageTitle(fileName)
|
||||||
FileList.showMask();
|
FileList.showMask()
|
||||||
}
|
}
|
||||||
|
|
||||||
OC.addStyle('richdocuments', 'mobile');
|
OC.addStyle('richdocuments', 'mobile')
|
||||||
|
|
||||||
var $iframe = $('<iframe id="richdocumentsframe" nonce="' + btoa(OC.requestToken) + '" scrolling="no" allowfullscreen src="'+viewer+'" />');
|
var $iframe = $('<iframe id="richdocumentsframe" nonce="' + btoa(OC.requestToken) + '" scrolling="no" allowfullscreen src="' + viewer + '" />')
|
||||||
odfViewer.loadingTimeout = setTimeout(function() {
|
odfViewer.loadingTimeout = setTimeout(function() {
|
||||||
if (!odfViewer.receivedLoading) {
|
if (!odfViewer.receivedLoading) {
|
||||||
odfViewer.onClose();
|
odfViewer.onClose()
|
||||||
OC.Notification.showTemporary(t('richdocuments', 'Failed to load {productName} - please try again later', {productName: OC.getCapabilities().richdocuments.productName || 'Collabora Online'}));
|
OC.Notification.showTemporary(t('richdocuments', 'Failed to load {productName} - please try again later', { productName: OC.getCapabilities().richdocuments.productName || 'Collabora Online' }))
|
||||||
}
|
}
|
||||||
}, 15000);
|
}, 15000)
|
||||||
$iframe.src = viewer;
|
$iframe.src = viewer
|
||||||
|
|
||||||
$('body').css('overscroll-behavior-y', 'none');
|
$('body').css('overscroll-behavior-y', 'none')
|
||||||
var viewport = document.querySelector("meta[name=viewport]");
|
var viewport = document.querySelector('meta[name=viewport]')
|
||||||
viewport.setAttribute('content', 'width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no');
|
viewport.setAttribute('content', 'width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no')
|
||||||
if ($('#isPublic').val()) {
|
if ($('#isPublic').val()) {
|
||||||
// force the preview to adjust its height
|
// force the preview to adjust its height
|
||||||
$('#preview').append($iframe).css({height: '100%'});
|
$('#preview').append($iframe).css({ height: '100%' })
|
||||||
$('body').css({height: '100%'});
|
$('body').css({ height: '100%' })
|
||||||
$('#content').addClass('full-height');
|
$('#content').addClass('full-height')
|
||||||
$('footer').addClass('hidden');
|
$('footer').addClass('hidden')
|
||||||
$('#imgframe').addClass('hidden');
|
$('#imgframe').addClass('hidden')
|
||||||
$('.directLink').addClass('hidden');
|
$('.directLink').addClass('hidden')
|
||||||
$('.directDownload').addClass('hidden');
|
$('.directDownload').addClass('hidden')
|
||||||
$('#controls').addClass('hidden');
|
$('#controls').addClass('hidden')
|
||||||
$('#content').addClass('loading');
|
$('#content').addClass('loading')
|
||||||
} else {
|
} else {
|
||||||
$('body').css('overflow', 'hidden');
|
$('body').css('overflow', 'hidden')
|
||||||
$('#app-content').append($iframe);
|
$('#app-content').append($iframe)
|
||||||
$iframe.hide();
|
$iframe.hide()
|
||||||
if ($('header').length) {
|
if ($('header').length) {
|
||||||
var $button = $('<div class="richdocuments-sharing"><a class="icon-shared icon-white"></a></div>');
|
var $button = $('<div class="richdocuments-sharing"><a class="icon-shared icon-white"></a></div>')
|
||||||
$('.header-right').prepend($button);
|
$('.header-right').prepend($button)
|
||||||
$button.on('click', function() {
|
$button.on('click', function() {
|
||||||
if ($('#app-sidebar').is(':visible')) {
|
if ($('#app-sidebar').is(':visible')) {
|
||||||
OC.Apps.hideAppSidebar();
|
OC.Apps.hideAppSidebar()
|
||||||
return;
|
return
|
||||||
}
|
}
|
||||||
var frameFilename = $('#richdocumentsframe')[0].contentWindow.documentsMain.fileName;
|
var frameFilename = $('#richdocumentsframe')[0].contentWindow.documentsMain.fileName
|
||||||
FileList.showDetailsView(frameFilename ? frameFilename : fileName, 'shareTabView');
|
FileList.showDetailsView(frameFilename || fileName, 'shareTabView')
|
||||||
OC.Apps.showAppSidebar();
|
OC.Apps.showAppSidebar()
|
||||||
});
|
})
|
||||||
$('.searchbox').hide();
|
$('.searchbox').hide()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$('#app-content #controls').addClass('hidden');
|
$('#app-content #controls').addClass('hidden')
|
||||||
},
|
},
|
||||||
|
|
||||||
onClose: function() {
|
onClose: function() {
|
||||||
clearTimeout(odfViewer.loadingTimeout)
|
clearTimeout(odfViewer.loadingTimeout)
|
||||||
if(typeof FileList !== "undefined") {
|
if (typeof FileList !== 'undefined') {
|
||||||
FileList.setViewerMode(false);
|
FileList.setViewerMode(false)
|
||||||
FileList.reload();
|
FileList.reload()
|
||||||
FileList.setPageTitle();
|
|
||||||
}
|
}
|
||||||
odfViewer.receivedLoading = false;
|
odfViewer.receivedLoading = false
|
||||||
$('link[href*="richdocuments/css/mobile"]').remove();
|
$('link[href*="richdocuments/css/mobile"]').remove()
|
||||||
$('#app-content #controls').removeClass('hidden');
|
$('#app-content #controls').removeClass('hidden')
|
||||||
$('#richdocumentsframe').remove();
|
$('#richdocumentsframe').remove()
|
||||||
$('.richdocuments-sharing').remove();
|
$('.richdocuments-sharing').remove()
|
||||||
$('#richdocuments-avatars').remove();
|
$('#richdocuments-avatars').remove()
|
||||||
$('#richdocuments-actions').remove();
|
$('#richdocuments-actions').remove()
|
||||||
$('.searchbox').show();
|
$('.searchbox').show()
|
||||||
$('body').css('overflow', 'auto');
|
$('body').css('overflow', 'auto')
|
||||||
|
|
||||||
if ($('#isPublic').val()) {
|
if ($('#isPublic').val()) {
|
||||||
$('#content').removeClass('full-height');
|
$('#content').removeClass('full-height')
|
||||||
$('footer').removeClass('hidden');
|
$('footer').removeClass('hidden')
|
||||||
$('#imgframe').removeClass('hidden');
|
$('#imgframe').removeClass('hidden')
|
||||||
$('.directLink').removeClass('hidden');
|
$('.directLink').removeClass('hidden')
|
||||||
$('.directDownload').removeClass('hidden');
|
$('.directDownload').removeClass('hidden')
|
||||||
}
|
}
|
||||||
|
|
||||||
OC.Util.History.replaceState();
|
OC.Util.History.replaceState()
|
||||||
},
|
},
|
||||||
|
|
||||||
registerFilesMenu: function(response) {
|
registerFilesMenu: function(response) {
|
||||||
var ooxml = response.doc_format === 'ooxml';
|
var ooxml = response.doc_format === 'ooxml'
|
||||||
|
|
||||||
var docExt, spreadsheetExt, presentationExt;
|
var docExt, spreadsheetExt, presentationExt
|
||||||
var docMime, spreadsheetMime, presentationMime;
|
var docMime, spreadsheetMime, presentationMime
|
||||||
if (ooxml) {
|
if (ooxml) {
|
||||||
docExt = 'docx';
|
docExt = 'docx'
|
||||||
spreadsheetExt = 'xlsx';
|
spreadsheetExt = 'xlsx'
|
||||||
presentationExt = 'pptx';
|
presentationExt = 'pptx'
|
||||||
docMime = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document';
|
docMime = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'
|
||||||
spreadsheetMime = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
|
spreadsheetMime = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
|
||||||
presentationMime = 'application/vnd.openxmlformats-officedocument.presentationml.presentation';
|
presentationMime = 'application/vnd.openxmlformats-officedocument.presentationml.presentation'
|
||||||
} else {
|
} else {
|
||||||
docExt = 'odt';
|
docExt = 'odt'
|
||||||
spreadsheetExt = 'ods';
|
spreadsheetExt = 'ods'
|
||||||
presentationExt = 'odp';
|
presentationExt = 'odp'
|
||||||
docMime = 'application/vnd.oasis.opendocument.text';
|
docMime = 'application/vnd.oasis.opendocument.text'
|
||||||
spreadsheetMime = 'application/vnd.oasis.opendocument.spreadsheet';
|
spreadsheetMime = 'application/vnd.oasis.opendocument.spreadsheet'
|
||||||
presentationMime = 'application/vnd.oasis.opendocument.presentation';
|
presentationMime = 'application/vnd.oasis.opendocument.presentation'
|
||||||
}
|
}
|
||||||
|
|
||||||
(function(OCA){
|
(function(OCA) {
|
||||||
OCA.FilesLOMenu = {
|
OCA.FilesLOMenu = {
|
||||||
attach: function(newFileMenu) {
|
attach: function(newFileMenu) {
|
||||||
var self = this;
|
var self = this
|
||||||
|
|
||||||
newFileMenu.addMenuEntry({
|
newFileMenu.addMenuEntry({
|
||||||
id: 'add-' + docExt,
|
id: 'add-' + docExt,
|
||||||
|
@ -211,12 +207,12 @@ var odfViewer = {
|
||||||
fileType: 'x-office-document',
|
fileType: 'x-office-document',
|
||||||
actionHandler: function(filename) {
|
actionHandler: function(filename) {
|
||||||
if (OC.getCapabilities().richdocuments.templates) {
|
if (OC.getCapabilities().richdocuments.templates) {
|
||||||
self._openTemplatePicker('document', docMime, filename);
|
self._openTemplatePicker('document', docMime, filename)
|
||||||
} else {
|
} else {
|
||||||
self._createDocument(docMime, filename);
|
self._createDocument(docMime, filename)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
|
||||||
newFileMenu.addMenuEntry({
|
newFileMenu.addMenuEntry({
|
||||||
id: 'add-' + spreadsheetExt,
|
id: 'add-' + spreadsheetExt,
|
||||||
|
@ -226,12 +222,12 @@ var odfViewer = {
|
||||||
fileType: 'x-office-spreadsheet',
|
fileType: 'x-office-spreadsheet',
|
||||||
actionHandler: function(filename) {
|
actionHandler: function(filename) {
|
||||||
if (OC.getCapabilities().richdocuments.templates) {
|
if (OC.getCapabilities().richdocuments.templates) {
|
||||||
self._openTemplatePicker('spreadsheet', spreadsheetMime, filename);
|
self._openTemplatePicker('spreadsheet', spreadsheetMime, filename)
|
||||||
} else {
|
} else {
|
||||||
self._createDocument(spreadsheetMime, filename);
|
self._createDocument(spreadsheetMime, filename)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
|
||||||
newFileMenu.addMenuEntry({
|
newFileMenu.addMenuEntry({
|
||||||
id: 'add-' + presentationExt,
|
id: 'add-' + presentationExt,
|
||||||
|
@ -241,45 +237,45 @@ var odfViewer = {
|
||||||
fileType: 'x-office-presentation',
|
fileType: 'x-office-presentation',
|
||||||
actionHandler: function(filename) {
|
actionHandler: function(filename) {
|
||||||
if (OC.getCapabilities().richdocuments.templates) {
|
if (OC.getCapabilities().richdocuments.templates) {
|
||||||
self._openTemplatePicker('presentation', presentationMime, filename);
|
self._openTemplatePicker('presentation', presentationMime, filename)
|
||||||
} else {
|
} else {
|
||||||
self._createDocument(presentationMime, filename);
|
self._createDocument(presentationMime, filename)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
_createDocument: function(mimetype, filename) {
|
_createDocument: function(mimetype, filename) {
|
||||||
OCA.Files.Files.isFileNameValid(filename);
|
OCA.Files.Files.isFileNameValid(filename)
|
||||||
filename = FileList.getUniqueName(filename);
|
filename = FileList.getUniqueName(filename)
|
||||||
|
|
||||||
$.post(
|
$.post(
|
||||||
OC.generateUrl('apps/richdocuments/ajax/documents/create'),
|
OC.generateUrl('apps/richdocuments/ajax/documents/create'),
|
||||||
{ mimetype : mimetype, filename: filename, dir: $('#dir').val() },
|
{ mimetype: mimetype, filename: filename, dir: $('#dir').val() },
|
||||||
function(response){
|
function(response) {
|
||||||
if (response && response.status === 'success'){
|
if (response && response.status === 'success') {
|
||||||
FileList.add(response.data, {animate: true, scrollTo: true});
|
FileList.add(response.data, { animate: true, scrollTo: true })
|
||||||
} else {
|
} else {
|
||||||
OC.dialogs.alert(response.data.message, t('core', 'Could not create file'));
|
OC.dialogs.alert(response.data.message, t('core', 'Could not create file'))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
)
|
||||||
},
|
},
|
||||||
|
|
||||||
_createDocumentFromTemplate: function(templateId, mimetype, filename) {
|
_createDocumentFromTemplate: function(templateId, mimetype, filename) {
|
||||||
OCA.Files.Files.isFileNameValid(filename);
|
OCA.Files.Files.isFileNameValid(filename)
|
||||||
filename = FileList.getUniqueName(filename);
|
filename = FileList.getUniqueName(filename)
|
||||||
odfViewer.onEdit(filename, {
|
odfViewer.onEdit(filename, {
|
||||||
fileId: -1,
|
fileId: -1,
|
||||||
dir: $('#dir').val(),
|
dir: $('#dir').val(),
|
||||||
templateId: templateId
|
templateId: templateId
|
||||||
});
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
_openTemplatePicker: function(type, mimetype, filename) {
|
_openTemplatePicker: function(type, mimetype, filename) {
|
||||||
var self = this;
|
var self = this
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: OC.linkToOCS('apps/richdocuments/api/v1/templates', 2) + type,
|
url: OC.linkToOCS('apps/richdocuments/api/v1/templates', 2) + type,
|
||||||
dataType: 'json'
|
dataType: 'json'
|
||||||
}).then(function(response) {
|
}).then(function(response) {
|
||||||
self._buildTemplatePicker(response.ocs.data)
|
self._buildTemplatePicker(response.ocs.data)
|
||||||
|
@ -288,127 +284,125 @@ var odfViewer = {
|
||||||
text: t('core', 'Cancel'),
|
text: t('core', 'Cancel'),
|
||||||
classes: 'cancel',
|
classes: 'cancel',
|
||||||
click: function() {
|
click: function() {
|
||||||
$(this).ocdialog('close');
|
$(this).ocdialog('close')
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
text: t('richdocuments', 'Create'),
|
text: t('richdocuments', 'Create'),
|
||||||
classes: 'primary',
|
classes: 'primary',
|
||||||
click: function() {
|
click: function() {
|
||||||
var templateId = this.dataset.templateId;
|
var templateId = this.dataset.templateId
|
||||||
self._createDocumentFromTemplate(templateId, mimetype, filename);
|
self._createDocumentFromTemplate(templateId, mimetype, filename)
|
||||||
$(this).ocdialog('close');
|
$(this).ocdialog('close')
|
||||||
}
|
}
|
||||||
}];
|
}]
|
||||||
|
|
||||||
$('#template-picker').ocdialog({
|
$('#template-picker').ocdialog({
|
||||||
closeOnEscape: true,
|
closeOnEscape: true,
|
||||||
modal: true,
|
modal: true,
|
||||||
buttons: buttonlist
|
buttons: buttonlist
|
||||||
});
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
_buildTemplatePicker: function(data) {
|
_buildTemplatePicker: function(data) {
|
||||||
var self = this;
|
var self = this
|
||||||
return $.get(OC.filePath('richdocuments', 'templates', 'templatePicker.html'), function(tmpl) {
|
return $.get(OC.filePath('richdocuments', 'templates', 'templatePicker.html'), function(tmpl) {
|
||||||
$tmpl = $(tmpl);
|
var $tmpl = $(tmpl)
|
||||||
// init template picker
|
// init template picker
|
||||||
var $dlg = $tmpl.octemplate({
|
var $dlg = $tmpl.octemplate({
|
||||||
dialog_name: 'template-picker',
|
dialog_name: 'template-picker',
|
||||||
dialog_title: t('richdocuments','Select template'),
|
dialog_title: t('richdocuments', 'Select template')
|
||||||
});
|
})
|
||||||
|
|
||||||
// create templates list
|
// create templates list
|
||||||
var templates = _.values(data)
|
var templates = _.values(data)
|
||||||
templates.forEach(function(template) {
|
templates.forEach(function(template) {
|
||||||
self._appendTemplateFromData($dlg[0], template);
|
self._appendTemplateFromData($dlg[0], template)
|
||||||
})
|
})
|
||||||
|
|
||||||
$('body').append($dlg);
|
$('body').append($dlg)
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
_appendTemplateFromData: function(dlg, data) {
|
_appendTemplateFromData: function(dlg, data) {
|
||||||
var self = this;
|
var template = dlg.querySelector('.template-model').cloneNode(true)
|
||||||
var template = dlg.querySelector('.template-model').cloneNode(true);
|
template.className = ''
|
||||||
template.className = '';
|
template.querySelector('img').src = OC.generateUrl('apps/richdocuments/template/preview/' + data.id)
|
||||||
template.querySelector('img').src = OC.generateUrl('apps/richdocuments/template/preview/'+data.id);
|
template.querySelector('h2').textContent = data.name
|
||||||
template.querySelector('h2').textContent = data.name;
|
|
||||||
template.onclick = function() {
|
template.onclick = function() {
|
||||||
dlg.dataset.templateId = data.id;
|
dlg.dataset.templateId = data.id
|
||||||
};
|
}
|
||||||
if (!dlg.dataset.templateId) {
|
if (!dlg.dataset.templateId) {
|
||||||
dlg.dataset.templateId = data.id;
|
dlg.dataset.templateId = data.id
|
||||||
}
|
}
|
||||||
|
|
||||||
dlg.querySelector('.template-container').appendChild(template);
|
dlg.querySelector('.template-container').appendChild(template)
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
})(OCA);
|
})(OCA)
|
||||||
|
|
||||||
OC.Plugins.register('OCA.Files.NewFileMenu', OCA.FilesLOMenu);
|
OC.Plugins.register('OCA.Files.NewFileMenu', OCA.FilesLOMenu)
|
||||||
|
|
||||||
// Open the template picker if there was a create parameter detected on load
|
// Open the template picker if there was a create parameter detected on load
|
||||||
if (!!(Preload.create && Preload.create.type && Preload.create.filename)) {
|
if (Preload.create && Preload.create.type && Preload.create.filename) {
|
||||||
var mimetype;
|
var mimetype
|
||||||
var ext;
|
var ext
|
||||||
switch (Preload.create.type) {
|
switch (Preload.create.type) {
|
||||||
case 'document':
|
case 'document':
|
||||||
mimetype = docMime;
|
mimetype = docMime
|
||||||
ext = docExt;
|
ext = docExt
|
||||||
break;
|
break
|
||||||
case 'spreadsheet':
|
case 'spreadsheet':
|
||||||
mimetype = spreadsheetMime;
|
mimetype = spreadsheetMime
|
||||||
ext = spreadsheetExt;
|
ext = spreadsheetExt
|
||||||
break;
|
break
|
||||||
case 'presentation':
|
case 'presentation':
|
||||||
mimetype = presentationMime;
|
mimetype = presentationMime
|
||||||
ext = presentationExt;
|
ext = presentationExt
|
||||||
break;
|
break
|
||||||
}
|
}
|
||||||
OCA.FilesLOMenu._openTemplatePicker(Preload.create.type, mimetype, Preload.create.filename + '.' + ext);
|
OCA.FilesLOMenu._openTemplatePicker(Preload.create.type, mimetype, Preload.create.filename + '.' + ext)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
// register file actions and menu
|
// register file actions and menu
|
||||||
if ( typeof OCA !== 'undefined'
|
if (typeof OCA !== 'undefined'
|
||||||
&& typeof OCA.Files !== 'undefined'
|
&& typeof OCA.Files !== 'undefined'
|
||||||
&& typeof OCA.Files.fileActions !== 'undefined'
|
&& typeof OCA.Files.fileActions !== 'undefined'
|
||||||
) {
|
) {
|
||||||
// check if texteditor app is enabled and loaded...
|
// check if texteditor app is enabled and loaded...
|
||||||
if (_.isUndefined(OCA.Files_Texteditor)) {
|
if (_.isUndefined(OCA.Files_Texteditor)) {
|
||||||
// it is not, so we do open text files with this app too.
|
// it is not, so we do open text files with this app too.
|
||||||
odfViewer.supportedMimes.push('text/plain');
|
odfViewer.supportedMimes.push('text/plain')
|
||||||
}
|
}
|
||||||
|
|
||||||
// notice: when changing 'supportedMimes' interactively (e.g. dev console),
|
// notice: when changing 'supportedMimes' interactively (e.g. dev console),
|
||||||
// register() needs to be re-run to re-register the fileActions.
|
// register() needs to be re-run to re-register the fileActions.
|
||||||
odfViewer.register();
|
odfViewer.register()
|
||||||
|
|
||||||
$.get(OC.filePath('richdocuments', 'ajax', 'settings.php')).done(function(settings) {
|
$.get(OC.filePath('richdocuments', 'ajax', 'settings.php')).done(function(settings) {
|
||||||
odfViewer.registerFilesMenu(settings);
|
odfViewer.registerFilesMenu(settings)
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Open documents if a public page is opened for a supported mimetype
|
// Open documents if a public page is opened for a supported mimetype
|
||||||
if ($('#isPublic').val() && odfViewer.supportedMimes.indexOf($('#mimetype').val()) !== -1) {
|
if ($('#isPublic').val() && odfViewer.supportedMimes.indexOf($('#mimetype').val()) !== -1) {
|
||||||
odfViewer.onEdit($('#filename').val());
|
odfViewer.onEdit($('#filename').val())
|
||||||
}
|
}
|
||||||
|
|
||||||
// listen to message from the viewer for closing/loading actions
|
// listen to message from the viewer for closing/loading actions
|
||||||
window.addEventListener('message', function(e) {
|
window.addEventListener('message', function(e) {
|
||||||
if (e.data === 'close') {
|
if (e.data === 'close') {
|
||||||
odfViewer.onClose();
|
odfViewer.onClose()
|
||||||
} else if(e.data === 'loading') {
|
} else if (e.data === 'loading') {
|
||||||
odfViewer.receivedLoading = true;
|
odfViewer.receivedLoading = true
|
||||||
$('#richdocumentsframe').show();
|
$('#content').removeClass('loading')
|
||||||
$('#content').removeClass('loading');
|
FileList.hideMask()
|
||||||
FileList.hideMask();
|
|
||||||
}
|
}
|
||||||
}, false);
|
}, false)
|
||||||
});
|
})
|
||||||
|
|
|
@ -18,12 +18,12 @@ module.exports = {
|
||||||
},
|
},
|
||||||
module: {
|
module: {
|
||||||
rules: [
|
rules: [
|
||||||
/*{
|
{
|
||||||
test: /\.(js|vue)$/,
|
test: /\.(js|vue)$/,
|
||||||
exclude: /node_modules/,
|
exclude: /node_modules/,
|
||||||
use: 'eslint-loader',
|
use: 'eslint-loader',
|
||||||
enforce: 'pre'
|
enforce: 'pre'
|
||||||
},*/
|
},
|
||||||
{
|
{
|
||||||
test: /\.css$/,
|
test: /\.css$/,
|
||||||
use: [
|
use: [
|
||||||
|
|
Загрузка…
Ссылка в новой задаче