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