diff options
author | Pranav Kant <pranav913@gmail.com> | 2017-09-27 09:53:06 +0300 |
---|---|---|
committer | Andras Timar <andras.timar@collabora.com> | 2017-09-27 09:53:06 +0300 |
commit | 21504eb5a895c1c80f937e1b5eeb5ecdf89c8711 (patch) | |
tree | b56162db3eebb87475a6c593aa4c5507ccb0205f /js/admin.js | |
parent | d80a97af3a6e0d009eeadfed75ee8a64cc3a1920 (diff) |
support for external apps (#124)1.12.35
Diffstat (limited to 'js/admin.js')
-rw-r--r-- | js/admin.js | 128 |
1 files changed, 128 insertions, 0 deletions
diff --git a/js/admin.js b/js/admin.js index 81e1c0cd..58162f69 100644 --- a/js/admin.js +++ b/js/admin.js @@ -1,6 +1,31 @@ /*global OC, $ */ var documentsSettings = { + _createExtApp: function() { + 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 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 appremovebutton = document.createElement('button'); + appremovebutton.setAttribute('class', 'external-apps-remove-button'); + appremovebutton.innerHTML = 'Remove'; + $(app1).append(appremovebutton); + + return app1; + }, + save : function() { $('#wopi_apply').attr('disabled', true); var data = { @@ -38,6 +63,23 @@ var documentsSettings = { 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...')); + $.post( + OC.filePath('richdocuments', 'ajax', 'admin.php'), + data, + documentsSettings.afterSaveExternalApps + ); + }, + + afterSaveExternalApps: function(response) { + OC.msg.finishedAction('#enable-external-apps-section-msg', response); + }, + initEditGroups: function() { var groups = $('#edit_group_select').val(); if (groups !== '') { @@ -48,11 +90,97 @@ var documentsSettings = { } }, + initExternalApps: function() { + 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(); + // 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]); + } + } + }, + initialize: function() { documentsSettings.initEditGroups(); + documentsSettings.initExternalApps(); $('#wopi_apply').on('click', documentsSettings.save); + // 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() { + var page = $(this).parent(); + + page.find('#enable-external-apps-section').toggleClass('hidden', !this.checked); + if (this.checked) { + var app1 = documentsSettings._createExtApp(); + $('#external-apps-section').append(app1); + } else { + page.find('.external-app').remove(); + page.find('#external-apps-raw').val(''); + documentsSettings.saveExternalApps(''); + } + }); + + $(document).on('click', '.external-apps-gen-token-button', function() { + var appSection = $(this).parent(); + var appToken = appSection.find('.external-apps-token'); + + // generate a random string + 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); + } + + // set the token in the field + appToken.val(random); + }); + + $(document).on('click', '.external-apps-remove-button', function() { + $(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'); + // convert all values into one single string and store it in raw input field + // as well as send the data to server + 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() + ','; + } + + 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); + }); + + $(document).on('click', '#test_wopi_apply', function() { + var groups = $(this).parent().find('#test_server_group_select').val(); + var testserver = $(this).parent().find('#test_wopi_url').val(); + + if (groups !== '' && testserver !== '') { + documentsSettings.saveTestWopi(groups, testserver); + } else { + 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'); |