From b9bc2417e7a8dc81feb0abe20359bedaf864f790 Mon Sep 17 00:00:00 2001 From: "John Molakvoæ (skjnldsv)" Date: Wed, 25 Sep 2019 18:19:42 +0200 Subject: Comply to eslint MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: John Molakvoæ (skjnldsv) --- core/src/OC/admin.js | 2 +- core/src/OC/appconfig.js | 25 +- core/src/OC/apps.js | 88 +-- core/src/OC/appsettings.js | 18 +- core/src/OC/backbone-webdav.js | 213 +++--- core/src/OC/backbone.js | 14 +- core/src/OC/capabilities.js | 2 +- core/src/OC/constants.js | 4 +- core/src/OC/contactsmenu.js | 258 +++---- core/src/OC/currentuser.js | 2 +- core/src/OC/dialogs.js | 1277 +++++++++++++++++----------------- core/src/OC/eventsource.js | 115 +-- core/src/OC/get_set.js | 13 +- core/src/OC/host.js | 8 +- core/src/OC/index.js | 49 +- core/src/OC/l10n-registry.js | 32 +- core/src/OC/l10n.js | 379 +++++----- core/src/OC/legacy-loader.js | 5 +- core/src/OC/menu.js | 28 +- core/src/OC/msg.js | 30 +- core/src/OC/navigation.js | 6 +- core/src/OC/notification.js | 65 +- core/src/OC/password-confirmation.js | 82 +-- core/src/OC/path.js | 24 +- core/src/OC/plugins.js | 34 +- core/src/OC/query-string.js | 19 +- core/src/OC/requesttoken.js | 13 +- core/src/OC/routing.js | 62 +- core/src/OC/search.js | 14 +- core/src/OC/util-history.js | 111 ++- core/src/OC/util.js | 181 ++--- core/src/OC/xhr-error.js | 29 +- 32 files changed, 1605 insertions(+), 1597 deletions(-) (limited to 'core/src/OC') diff --git a/core/src/OC/admin.js b/core/src/OC/admin.js index 565af9946f7..008016645d9 100644 --- a/core/src/OC/admin.js +++ b/core/src/OC/admin.js @@ -24,7 +24,7 @@ const isAdmin = !!window._oc_isadmin /** * Returns whether the current user is an administrator * - * @return {bool} true if the user is an admin, false otherwise + * @returns {bool} true if the user is an admin, false otherwise * @since 9.0.0 */ export const isUserAdmin = () => isAdmin diff --git a/core/src/OC/appconfig.js b/core/src/OC/appconfig.js index 1248475ce77..37fc3ca420d 100644 --- a/core/src/OC/appconfig.js +++ b/core/src/OC/appconfig.js @@ -1,3 +1,4 @@ +/* eslint-disable */ /** * @copyright Copyright (c) 2016 Joas Schilling * @@ -18,7 +19,7 @@ * */ -import {getValue, setValue, getApps, getKeys, deleteKey} from '../OCP/appconfig' + import { getValue, setValue, getApps, getKeys, deleteKey } from '../OCP/appconfig' export const appConfig = window.oc_appconfig || {} @@ -30,42 +31,42 @@ export const AppConfig = { /** * @deprecated Use OCP.AppConfig.getValue() instead */ - getValue: function (app, key, defaultValue, callback) { + getValue: function(app, key, defaultValue, callback) { getValue(app, key, defaultValue, { success: callback - }); + }) }, /** * @deprecated Use OCP.AppConfig.setValue() instead */ - setValue: function (app, key, value) { - setValue(app, key, value); + setValue: function(app, key, value) { + setValue(app, key, value) }, /** * @deprecated Use OCP.AppConfig.getApps() instead */ - getApps: function (callback) { + getApps: function(callback) { getApps({ success: callback - }); + }) }, /** * @deprecated Use OCP.AppConfig.getKeys() instead */ - getKeys: function (app, callback) { + getKeys: function(app, callback) { getKeys(app, { success: callback - }); + }) }, /** * @deprecated Use OCP.AppConfig.deleteKey() instead */ - deleteKey: function (app, key) { - deleteKey(app, key); + deleteKey: function(app, key) { + deleteKey(app, key) } -}; +} diff --git a/core/src/OC/apps.js b/core/src/OC/apps.js index d476e74c811..f94059a4212 100644 --- a/core/src/OC/apps.js +++ b/core/src/OC/apps.js @@ -8,26 +8,26 @@ * @copyright Bernhard Posselt 2014 */ -import $ from 'jquery'; +import $ from 'jquery' -var dynamicSlideToggleEnabled = false; +var dynamicSlideToggleEnabled = false const Apps = { - enableDynamicSlideToggle: function () { - dynamicSlideToggleEnabled = true; + enableDynamicSlideToggle: function() { + dynamicSlideToggleEnabled = true } -}; +} /** * Shows the #app-sidebar and add .with-app-sidebar to subsequent siblings * * @param {Object} [$el] sidebar element to show, defaults to $('#app-sidebar') */ -Apps.showAppSidebar = function ($el) { - var $appSidebar = $el || $('#app-sidebar'); - $appSidebar.removeClass('disappear').show(); - $('#app-content').trigger(new $.Event('appresized')); -}; +Apps.showAppSidebar = function($el) { + var $appSidebar = $el || $('#app-sidebar') + $appSidebar.removeClass('disappear').show() + $('#app-content').trigger(new $.Event('appresized')) +} /** * Shows the #app-sidebar and removes .with-app-sidebar from subsequent @@ -35,11 +35,11 @@ Apps.showAppSidebar = function ($el) { * * @param {Object} [$el] sidebar element to hide, defaults to $('#app-sidebar') */ -Apps.hideAppSidebar = function ($el) { - var $appSidebar = $el || $('#app-sidebar'); - $appSidebar.hide().addClass('disappear'); - $('#app-content').trigger(new $.Event('appresized')); -}; +Apps.hideAppSidebar = function($el) { + var $appSidebar = $el || $('#app-sidebar') + $appSidebar.hide().addClass('disappear') + $('#app-content').trigger(new $.Event('appresized')) +} /** * Provides a way to slide down a target area through a button and slide it @@ -51,40 +51,40 @@ Apps.hideAppSidebar = function ($el) { *
I'm sliding up
*/ export const registerAppsSlideToggle = () => { - var buttons = $('[data-apps-slide-toggle]'); + var buttons = $('[data-apps-slide-toggle]') if (buttons.length === 0) { - $('#app-navigation').addClass('without-app-settings'); + $('#app-navigation').addClass('without-app-settings') } - $(document).click(function (event) { + $(document).click(function(event) { if (dynamicSlideToggleEnabled) { - buttons = $('[data-apps-slide-toggle]'); + buttons = $('[data-apps-slide-toggle]') } - buttons.each(function (index, button) { + buttons.each(function(index, button) { - var areaSelector = $(button).data('apps-slide-toggle'); - var area = $(areaSelector); + var areaSelector = $(button).data('apps-slide-toggle') + var area = $(areaSelector) - function hideArea () { - area.slideUp(OC.menuSpeed * 4, function () { - area.trigger(new $.Event('hide')); - }); - area.removeClass('opened'); - $(button).removeClass('opened'); + function hideArea() { + area.slideUp(OC.menuSpeed * 4, function() { + area.trigger(new $.Event('hide')) + }) + area.removeClass('opened') + $(button).removeClass('opened') } - function showArea () { - area.slideDown(OC.menuSpeed * 4, function () { - area.trigger(new $.Event('show')); - }); - area.addClass('opened'); - $(button).addClass('opened'); - var input = $(areaSelector + ' [autofocus]'); + function showArea() { + area.slideDown(OC.menuSpeed * 4, function() { + area.trigger(new $.Event('show')) + }) + area.addClass('opened') + $(button).addClass('opened') + var input = $(areaSelector + ' [autofocus]') if (input.length === 1) { - input.focus(); + input.focus() } } @@ -94,23 +94,23 @@ export const registerAppsSlideToggle = () => { // button toggles the area if ($(button).is($(event.target).closest('[data-apps-slide-toggle]'))) { if (area.is(':visible')) { - hideArea(); + hideArea() } else { - showArea(); + showArea() } // all other areas that have not been clicked but are open // should be slid up } else { - var closest = $(event.target).closest(areaSelector); + var closest = $(event.target).closest(areaSelector) if (area.is(':visible') && closest[0] !== area[0]) { - hideArea(); + hideArea() } } } - }); + }) - }); -}; + }) +} -export default Apps; +export default Apps diff --git a/core/src/OC/appsettings.js b/core/src/OC/appsettings.js index b62af5c592a..7665d93fb7c 100644 --- a/core/src/OC/appsettings.js +++ b/core/src/OC/appsettings.js @@ -1,4 +1,5 @@ -/* +/* eslint-disable */ +/** * @copyright 2019 Christoph Wurst * * @author 2019 Christoph Wurst @@ -18,9 +19,8 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ - import $ from 'jquery' -import {filePath} from './routing' +import { filePath } from './routing' /** * Opens a popup with the setting for an app. @@ -42,7 +42,7 @@ export const appSettings = args => { message: 'The parameter appid is missing' } } - var props = {scriptName: 'settings.php', cache: true} + var props = { scriptName: 'settings.php', cache: true } $.extend(props, args) var settings = $('#appsettings') if (settings.length === 0) { @@ -61,10 +61,10 @@ export const appSettings = args => { popup.hide().remove() } else { const arrowclass = settings.hasClass('topright') ? 'up' : 'left' - $.get(filePath(props.appid, '', props.scriptName), function (data) { - popup.html(data).ready(function () { + $.get(filePath(props.appid, '', props.scriptName), function(data) { + popup.html(data).ready(function() { popup.prepend('

' + t('core', 'Settings') + '

').show() - popup.find('.close').bind('click', function () { + popup.find('.close').bind('click', function() { popup.remove() }) if (typeof props.loadJS !== 'undefined') { @@ -80,10 +80,10 @@ export const appSettings = args => { } } if (props.cache) { - $.ajaxSetup({cache: true}) + $.ajaxSetup({ cache: true }) } $.getScript(filePath(props.appid, 'js', scriptname)) - .fail(function (jqxhr, settings, e) { + .fail(function(jqxhr, settings, e) { throw e }) } diff --git a/core/src/OC/backbone-webdav.js b/core/src/OC/backbone-webdav.js index d007054630f..b27d117e568 100644 --- a/core/src/OC/backbone-webdav.js +++ b/core/src/OC/backbone-webdav.js @@ -1,3 +1,4 @@ +/* eslint-disable */ /* * Copyright (c) 2015 * @@ -53,8 +54,8 @@ * }); */ -import _ from 'underscore'; -import dav from 'davclient.js'; +import _ from 'underscore' +import dav from 'davclient.js' const methodMap = { create: 'POST', @@ -62,11 +63,11 @@ const methodMap = { patch: 'PROPPATCH', delete: 'DELETE', read: 'PROPFIND' -}; +} // Throw an error when a URL is needed, and none is supplied. -function urlError () { - throw new Error('A "url" property or function must be specified'); +function urlError() { + throw new Error('A "url" property or function must be specified') } /** @@ -75,184 +76,184 @@ function urlError () { * @param {Object} result * @param {Object} davProperties properties mapping */ -function parsePropFindResult (result, davProperties) { +function parsePropFindResult(result, davProperties) { if (_.isArray(result)) { - return _.map(result, function (subResult) { - return parsePropFindResult(subResult, davProperties); - }); + return _.map(result, function(subResult) { + return parsePropFindResult(subResult, davProperties) + }) } var props = { href: result.href - }; + } - _.each(result.propStat, function (propStat) { + _.each(result.propStat, function(propStat) { if (propStat.status !== 'HTTP/1.1 200 OK') { - return; + return } for (var key in propStat.properties) { - var propKey = key; + var propKey = key if (key in davProperties) { - propKey = davProperties[key]; + propKey = davProperties[key] } - props[propKey] = propStat.properties[key]; + props[propKey] = propStat.properties[key] } - }); + }) if (!props.id) { // parse id from href - props.id = parseIdFromLocation(props.href); + props.id = parseIdFromLocation(props.href) } - return props; + return props } /** * Parse ID from location * * @param {string} url url - * @return {string} id + * @returns {string} id */ -function parseIdFromLocation (url) { - var queryPos = url.indexOf('?'); +function parseIdFromLocation(url) { + var queryPos = url.indexOf('?') if (queryPos > 0) { - url = url.substr(0, queryPos); + url = url.substr(0, queryPos) } - var parts = url.split('/'); - var result; + var parts = url.split('/') + var result do { - result = parts[parts.length - 1]; - parts.pop(); + result = parts[parts.length - 1] + parts.pop() // note: first result can be empty when there is a trailing slash, // so we take the part before that - } while (!result && parts.length > 0); + } while (!result && parts.length > 0) - return result; + return result } -function isSuccessStatus (status) { - return status >= 200 && status <= 299; +function isSuccessStatus(status) { + return status >= 200 && status <= 299 } -function convertModelAttributesToDavProperties (attrs, davProperties) { - var props = {}; - var key; +function convertModelAttributesToDavProperties(attrs, davProperties) { + var props = {} + var key for (key in attrs) { - var changedProp = davProperties[key]; - var value = attrs[key]; + var changedProp = davProperties[key] + var value = attrs[key] if (!changedProp) { - console.warn('No matching DAV property for property "' + key); - changedProp = key; + console.warn('No matching DAV property for property "' + key) + changedProp = key } if (_.isBoolean(value) || _.isNumber(value)) { // convert to string - value = '' + value; + value = '' + value } - props[changedProp] = value; + props[changedProp] = value } - return props; + return props } -function callPropFind (client, options, model, headers) { +function callPropFind(client, options, model, headers) { return client.propFind( options.url, _.values(options.davProperties) || [], options.depth, headers - ).then(function (response) { + ).then(function(response) { if (isSuccessStatus(response.status)) { if (_.isFunction(options.success)) { - var propsMapping = _.invert(options.davProperties); - var results = parsePropFindResult(response.body, propsMapping); + var propsMapping = _.invert(options.davProperties) + var results = parsePropFindResult(response.body, propsMapping) if (options.depth > 0) { // discard root entry - results.shift(); + results.shift() } - options.success(results); - return; + options.success(results) + } } else if (_.isFunction(options.error)) { - options.error(response); + options.error(response) } - }); + }) } -function callPropPatch (client, options, model, headers) { +function callPropPatch(client, options, model, headers) { return client.propPatch( options.url, convertModelAttributesToDavProperties(model.changed, options.davProperties), headers - ).then(function (result) { + ).then(function(result) { if (isSuccessStatus(result.status)) { if (_.isFunction(options.success)) { // pass the object's own values because the server // does not return the updated model - options.success(model.toJSON()); + options.success(model.toJSON()) } } else if (_.isFunction(options.error)) { - options.error(result); + options.error(result) } - }); + }) } -function callMkCol (client, options, model, headers) { +function callMkCol(client, options, model, headers) { // call MKCOL without data, followed by PROPPATCH return client.request( options.type, options.url, headers, null - ).then(function (result) { + ).then(function(result) { if (!isSuccessStatus(result.status)) { if (_.isFunction(options.error)) { - options.error(result); + options.error(result) } - return; + return } - callPropPatch(client, options, model, headers); - }); + callPropPatch(client, options, model, headers) + }) } -function callMethod (client, options, model, headers) { - headers['Content-Type'] = 'application/json'; +function callMethod(client, options, model, headers) { + headers['Content-Type'] = 'application/json' return client.request( options.type, options.url, headers, options.data - ).then(function (result) { + ).then(function(result) { if (!isSuccessStatus(result.status)) { if (_.isFunction(options.error)) { - options.error(result); + options.error(result) } - return; + return } if (_.isFunction(options.success)) { if (options.type === 'PUT' || options.type === 'POST' || options.type === 'MKCOL') { // pass the object's own values because the server // does not return anything - var responseJson = result.body || model.toJSON(); - var locationHeader = result.xhr.getResponseHeader('Content-Location'); + var responseJson = result.body || model.toJSON() + var locationHeader = result.xhr.getResponseHeader('Content-Location') if (options.type === 'POST' && locationHeader) { - responseJson.id = parseIdFromLocation(locationHeader); + responseJson.id = parseIdFromLocation(locationHeader) } - options.success(responseJson); - return; + options.success(responseJson) + return } // if multi-status, parse if (result.status === 207) { - var propsMapping = _.invert(options.davProperties); - options.success(parsePropFindResult(result.body, propsMapping)); + var propsMapping = _.invert(options.davProperties) + options.success(parsePropFindResult(result.body, propsMapping)) } else { - options.success(result.body); + options.success(result.body) } } - }); + }) } export const davCall = (options, model) => { @@ -262,22 +263,22 @@ export const davCall = (options, model) => { 'DAV:': 'd', 'http://owncloud.org/ns': 'oc' }, options.xmlNamespaces || {}) - }); - client.resolveUrl = function () { - return options.url; - }; + }) + client.resolveUrl = function() { + return options.url + } var headers = _.extend({ 'X-Requested-With': 'XMLHttpRequest', 'requesttoken': OC.requestToken - }, options.headers); + }, options.headers) if (options.type === 'PROPFIND') { - return callPropFind(client, options, model, headers); + return callPropFind(client, options, model, headers) } else if (options.type === 'PROPPATCH') { - return callPropPatch(client, options, model, headers); + return callPropPatch(client, options, model, headers) } else if (options.type === 'MKCOL') { - return callMkCol(client, options, model, headers); + return callMkCol(client, options, model, headers) } else { - return callMethod(client, options, model, headers); + return callMethod(client, options, model, headers) } } @@ -285,73 +286,73 @@ export const davCall = (options, model) => { * DAV transport */ export const davSync = Backbone => (method, model, options) => { - var params = {type: methodMap[method] || method}; - var isCollection = (model instanceof Backbone.Collection); + var params = { type: methodMap[method] || method } + var isCollection = (model instanceof Backbone.Collection) if (method === 'update') { // if a model has an inner collection, it must define an // attribute "hasInnerCollection" that evaluates to true if (model.hasInnerCollection) { // if the model itself is a Webdav collection, use MKCOL - params.type = 'MKCOL'; + params.type = 'MKCOL' } else if (model.usePUT || (model.collection && model.collection.usePUT)) { // use PUT instead of PROPPATCH - params.type = 'PUT'; + params.type = 'PUT' } } // Ensure that we have a URL. if (!options.url) { - params.url = _.result(model, 'url') || urlError(); + params.url = _.result(model, 'url') || urlError() } // Ensure that we have the appropriate request data. if (options.data == null && model && (method === 'create' || method === 'update' || method === 'patch')) { - params.data = JSON.stringify(options.attrs || model.toJSON(options)); + params.data = JSON.stringify(options.attrs || model.toJSON(options)) } // Don't process data on a non-GET request. if (params.type !== 'PROPFIND') { - params.processData = false; + params.processData = false } if (params.type === 'PROPFIND' || params.type === 'PROPPATCH') { - var davProperties = model.davProperties; + var davProperties = model.davProperties if (!davProperties && model.model) { // use dav properties from model in case of collection - davProperties = model.model.prototype.davProperties; + davProperties = model.model.prototype.davProperties } if (davProperties) { if (_.isFunction(davProperties)) { - params.davProperties = davProperties.call(model); + params.davProperties = davProperties.call(model) } else { - params.davProperties = davProperties; + params.davProperties = davProperties } } - params.davProperties = _.extend(params.davProperties || {}, options.davProperties); + params.davProperties = _.extend(params.davProperties || {}, options.davProperties) if (_.isUndefined(options.depth)) { if (isCollection) { - options.depth = 1; + options.depth = 1 } else { - options.depth = 0; + options.depth = 0 } } } // Pass along `textStatus` and `errorThrown` from jQuery. - var error = options.error; - options.error = function (xhr, textStatus, errorThrown) { - options.textStatus = textStatus; - options.errorThrown = errorThrown; + var error = options.error + options.error = function(xhr, textStatus, errorThrown) { + options.textStatus = textStatus + options.errorThrown = errorThrown if (error) { - error.call(options.context, xhr, textStatus, errorThrown); + error.call(options.context, xhr, textStatus, errorThrown) } - }; + } // Make the request, allowing the user to override any Ajax options. - var xhr = options.xhr = Backbone.davCall(_.extend(params, options), model); - model.trigger('request', model, xhr, options); - return xhr; + var xhr = options.xhr = Backbone.davCall(_.extend(params, options), model) + model.trigger('request', model, xhr, options) + return xhr } diff --git a/core/src/OC/backbone.js b/core/src/OC/backbone.js index 07b5593eff9..38bfc046501 100644 --- a/core/src/OC/backbone.js +++ b/core/src/OC/backbone.js @@ -1,4 +1,4 @@ -/* +/** * @copyright 2019 Christoph Wurst * * @author 2019 Christoph Wurst @@ -19,15 +19,15 @@ * along with this program. If not, see . */ -import VendorBackbone from 'backbone'; -import {davCall, davSync} from './backbone-webdav'; +import VendorBackbone from 'backbone' +import { davCall, davSync } from './backbone-webdav' -const Backbone = VendorBackbone.noConflict(); +const Backbone = VendorBackbone.noConflict() // Patch Backbone for DAV Object.assign(Backbone, { davCall, - davSync: davSync(Backbone), -}); + davSync: davSync(Backbone) +}) -export default Backbone; +export default Backbone diff --git a/core/src/OC/capabilities.js b/core/src/OC/capabilities.js index 1adfe80d288..2e0a8da3995 100644 --- a/core/src/OC/capabilities.js +++ b/core/src/OC/capabilities.js @@ -24,7 +24,7 @@ const capabilities = window._oc_capabilities || {} /** * Returns the capabilities * - * @return {Array} capabilities + * @returns {Array} capabilities * * @since 14.0 */ diff --git a/core/src/OC/constants.js b/core/src/OC/constants.js index d77a2d28c70..972848997ae 100644 --- a/core/src/OC/constants.js +++ b/core/src/OC/constants.js @@ -1,4 +1,4 @@ -/* +/** * @copyright 2019 Christoph Wurst * * @author 2019 Christoph Wurst @@ -19,7 +19,7 @@ * along with this program. If not see . */ -export const coreApps = ['', 'admin','log','core/search','core','3rdparty'] +export const coreApps = ['', 'admin', 'log', 'core/search', 'core', '3rdparty'] export const menuSpeed = 50 export const PERMISSION_NONE = 0 export const PERMISSION_CREATE = 4 diff --git a/core/src/OC/contactsmenu.js b/core/src/OC/contactsmenu.js index 0af4bad412d..e986c46ec20 100644 --- a/core/src/OC/contactsmenu.js +++ b/core/src/OC/contactsmenu.js @@ -1,4 +1,4 @@ -/* global Backbone, Handlebars, Promise, _ */ +/* eslint-disable */ /** * @copyright 2017 Christoph Wurst @@ -22,10 +22,10 @@ * */ -import $ from 'jquery'; -import {Collection, Model, View} from 'backbone'; +import $ from 'jquery' +import { Collection, Model, View } from 'backbone' -import OC from './index'; +import OC from './index' /** * @class Contact @@ -43,18 +43,18 @@ const Contact = Model.extend({ /** * @returns {undefined} */ - initialize: function () { + initialize: function() { // Add needed property for easier template rendering if (this.get('actions').length === 0) { - this.set('hasOneAction', true); + this.set('hasOneAction', true) } else if (this.get('actions').length === 1) { - this.set('hasTwoActions', true); - this.set('secondAction', this.get('actions')[0]); + this.set('hasTwoActions', true) + this.set('secondAction', this.get('actions')[0]) } else { - this.set('hasManyActions', true); + this.set('hasManyActions', true) } } -}); +}) /** * @class ContactCollection @@ -62,7 +62,7 @@ const Contact = Model.extend({ */ const ContactCollection = Collection.extend({ model: Contact -}); +}) /** * @class ContactsListView @@ -80,29 +80,29 @@ const ContactsListView = View.extend({ * @param {object} options * @returns {undefined} */ - initialize: function (options) { - this._collection = options.collection; + initialize: function(options) { + this._collection = options.collection }, /** * @returns {self} */ - render: function () { - var self = this; - self.$el.html(''); - self._subViews = []; + render: function() { + var self = this + self.$el.html('') + self._subViews = [] - self._collection.forEach(function (contact) { + self._collection.forEach(function(contact) { var item = new ContactsListItemView({ model: contact - }); - item.render(); - self.$el.append(item.$el); - item.on('toggle:actionmenu', self._onChildActionMenuToggle, self); - self._subViews.push(item); - }); - - return self; + }) + item.render() + self.$el.append(item.$el) + item.on('toggle:actionmenu', self._onChildActionMenuToggle, self) + self._subViews.push(item) + }) + + return self }, /** @@ -111,12 +111,12 @@ const ContactsListView = View.extend({ * @param {type} $src * @returns {undefined} */ - _onChildActionMenuToggle: function ($src) { - this._subViews.forEach(function (view) { - view.trigger('parent:toggle:actionmenu', $src); - }); + _onChildActionMenuToggle: function($src) { + this._subViews.forEach(function(view) { + view.trigger('parent:toggle:actionmenu', $src) + }) } -}); +}) /** * @class ContactsListItemView @@ -146,37 +146,37 @@ const ContactsListItemView = View.extend({ * @param {object} data * @returns {undefined} */ - template: function (data) { - return this.contactTemplate(data); + template: function(data) { + return this.contactTemplate(data) }, /** * @param {object} options * @returns {undefined} */ - initialize: function (options) { - this._model = options.model; - this.on('parent:toggle:actionmenu', this._onOtherActionMenuOpened, this); + initialize: function(options) { + this._model = options.model + this.on('parent:toggle:actionmenu', this._onOtherActionMenuOpened, this) }, /** * @returns {self} */ - render: function () { + render: function() { this.$el.html(this.template({ contact: this._model.toJSON() - })); - this.delegateEvents(); + })) + this.delegateEvents() // Show placeholder if no avatar is available (avatar is rendered as img, not div) - this.$('div.avatar').imageplaceholder(this._model.get('fullName')); + this.$('div.avatar').imageplaceholder(this._model.get('fullName')) // Show tooltip for top action - this.$('.top-action').tooltip({placement: 'left'}); + this.$('.top-action').tooltip({ placement: 'left' }) // Show tooltip for second action - this.$('.second-action').tooltip({placement: 'left'}); + this.$('.second-action').tooltip({ placement: 'left' }) - return this; + return this }, /** @@ -185,14 +185,14 @@ const ContactsListItemView = View.extend({ * @private * @returns {undefined} */ - _onToggleActionsMenu: function () { - this._actionMenuShown = !this._actionMenuShown; + _onToggleActionsMenu: function() { + this._actionMenuShown = !this._actionMenuShown if (this._actionMenuShown) { - this.$('.menu').show(); + this.$('.menu').show() } else { - this.$('.menu').hide(); + this.$('.menu').hide() } - this.trigger('toggle:actionmenu', this.$el); + this.trigger('toggle:actionmenu', this.$el) }, /** @@ -200,15 +200,15 @@ const ContactsListItemView = View.extend({ * @argument {jQuery} $src * @returns {undefined} */ - _onOtherActionMenuOpened: function ($src) { + _onOtherActionMenuOpened: function($src) { if (this.$el.is($src)) { // Ignore - return; + return } - this._actionMenuShown = false; - this.$('.menu').hide(); + this._actionMenuShown = false + this.$('.menu').hide() } -}); +}) /** * @class ContactsMenuView @@ -248,15 +248,15 @@ const ContactsMenuView = View.extend({ /** * @returns {undefined} */ - _onSearch: _.debounce(function (e) { - var searchTerm = this.$('#contactsmenu-search').val(); + _onSearch: _.debounce(function(e) { + var searchTerm = this.$('#contactsmenu-search').val() // IE11 triggers an 'input' event after the view has been rendered // resulting in an endless loading loop. To prevent this, we remember // the last search term to savely ignore some events // See https://github.com/nextcloud/server/issues/5281 if (searchTerm !== this._searchTerm) { - this.trigger('search', this.$('#contactsmenu-search').val()); - this._searchTerm = searchTerm; + this.trigger('search', this.$('#contactsmenu-search').val()) + this._searchTerm = searchTerm } }, 700), @@ -264,75 +264,75 @@ const ContactsMenuView = View.extend({ * @param {object} data * @returns {string} */ - loadingTemplate: function (data) { - return this.templates.loading(data); + loadingTemplate: function(data) { + return this.templates.loading(data) }, /** * @param {object} data * @returns {string} */ - errorTemplate: function (data) { + errorTemplate: function(data) { return this.templates.error( _.extend({ couldNotLoadText: t('core', 'Could not load your contacts') }, data) - ); + ) }, /** * @param {object} data * @returns {string} */ - contentTemplate: function (data) { + contentTemplate: function(data) { return this.templates.menu( _.extend({ searchContactsText: t('core', 'Search contacts …') }, data) - ); + ) }, /** * @param {object} data * @returns {string} */ - contactsTemplate: function (data) { + contactsTemplate: function(data) { return this.templates.list( _.extend({ noContactsFoundText: t('core', 'No contacts found'), showAllContactsText: t('core', 'Show all contacts …'), contactsAppMgmtText: t('core', 'Install the Contacts app') }, data) - ); + ) }, /** * @param {object} options * @returns {undefined} */ - initialize: function (options) { - this.options = options; + initialize: function(options) { + this.options = options }, /** * @param {string} text * @returns {undefined} */ - showLoading: function (text) { - this.render(); - this._contacts = undefined; + showLoading: function(text) { + this.render() + this._contacts = undefined this.$('.content').html(this.loadingTemplate({ loadingText: text - })); + })) }, /** * @returns {undefined} */ - showError: function () { - this.render(); - this._contacts = undefined; - this.$('.content').html(this.errorTemplate()); + showError: function() { + this.render() + this._contacts = undefined + this.$('.content').html(this.errorTemplate()) }, /** @@ -340,16 +340,16 @@ const ContactsMenuView = View.extend({ * @param {string} searchTerm * @returns {undefined} */ - showContacts: function (viewData, searchTerm) { - this._contacts = viewData.contacts; + showContacts: function(viewData, searchTerm) { + this._contacts = viewData.contacts this.render({ contacts: viewData.contacts - }); + }) var list = new ContactsListView({ collection: viewData.contacts - }); - list.render(); + }) + list.render() this.$('.content').html(this.contactsTemplate({ contacts: viewData.contacts, searchTerm: searchTerm, @@ -357,25 +357,25 @@ const ContactsMenuView = View.extend({ contactsAppURL: OC.generateUrl('/apps/contacts'), canInstallApp: OC.isUserAdmin(), contactsAppMgmtURL: OC.generateUrl('/settings/apps/social/contacts') - })); - this.$('#contactsmenu-contacts').html(list.$el); + })) + this.$('#contactsmenu-contacts').html(list.$el) }, /** * @param {object} data * @returns {self} */ - render: function (data) { - var searchVal = this.$('#contactsmenu-search').val(); - this.$el.html(this.contentTemplate(data)); + render: function(data) { + var searchVal = this.$('#contactsmenu-search').val() + this.$el.html(this.contentTemplate(data)) // Focus search - this.$('#contactsmenu-search').val(searchVal); - this.$('#contactsmenu-search').focus(); - return this; + this.$('#contactsmenu-search').val(searchVal) + this.$('#contactsmenu-search').focus() + return this } -}); +}) /** * @param {Object} options @@ -384,9 +384,9 @@ const ContactsMenuView = View.extend({ * @class ContactsMenu * @memberOf OC */ -const ContactsMenu = function (options) { - this.initialize(options); -}; +const ContactsMenu = function(options) { + this.initialize(options) +} ContactsMenu.prototype = { /** @type {jQuery} */ @@ -407,23 +407,23 @@ ContactsMenu.prototype = { * @param {jQuery} options.trigger - the element to click on to open the menu * @returns {undefined} */ - initialize: function (options) { - this.$el = options.el; - this._$trigger = options.trigger; + initialize: function(options) { + this.$el = options.el + this._$trigger = options.trigger this._view = new ContactsMenuView({ el: this.$el - }); - this._view.on('search', function (searchTerm) { - this._loadContacts(searchTerm); - }, this); - - OC.registerMenu(this._$trigger, this.$el, function () { - this._toggleVisibility(true); - }.bind(this), true); - this.$el.on('beforeHide', function () { - this._toggleVisibility(false); - }.bind(this)); + }) + this._view.on('search', function(searchTerm) { + this._loadContacts(searchTerm) + }, this) + + OC.registerMenu(this._$trigger, this.$el, function() { + this._toggleVisibility(true) + }.bind(this), true) + this.$el.on('beforeHide', function() { + this._toggleVisibility(false) + }.bind(this)) }, /** @@ -431,12 +431,12 @@ ContactsMenu.prototype = { * @param {boolean} show * @returns {Promise} */ - _toggleVisibility: function (show) { + _toggleVisibility: function(show) { if (show) { - return this._loadContacts(); + return this._loadContacts() } else { - this.$el.html(''); - return Promise.resolve(); + this.$el.html('') + return Promise.resolve() } }, @@ -445,48 +445,48 @@ ContactsMenu.prototype = { * @param {string|undefined} searchTerm * @returns {Promise} */ - _getContacts: function (searchTerm) { - var url = OC.generateUrl('/contactsmenu/contacts'); + _getContacts: function(searchTerm) { + var url = OC.generateUrl('/contactsmenu/contacts') return Promise.resolve($.ajax(url, { method: 'POST', data: { filter: searchTerm } - })); + })) }, /** * @param {string|undefined} searchTerm * @returns {undefined} */ - _loadContacts: function (searchTerm) { - var self = this; + _loadContacts: function(searchTerm) { + var self = this if (!self._contactsPromise) { - self._contactsPromise = self._getContacts(searchTerm); + self._contactsPromise = self._getContacts(searchTerm) } if (_.isUndefined(searchTerm) || searchTerm === '') { - self._view.showLoading(t('core', 'Loading your contacts …')); + self._view.showLoading(t('core', 'Loading your contacts …')) } else { self._view.showLoading(t('core', 'Looking for {term} …', { term: searchTerm - })); + })) } - return self._contactsPromise.then(function (data) { + return self._contactsPromise.then(function(data) { // Convert contact entries to Backbone collection - data.contacts = new ContactCollection(data.contacts); + data.contacts = new ContactCollection(data.contacts) - self._view.showContacts(data, searchTerm); - }, function (e) { - self._view.showError(); - console.error('There was an error loading your contacts', e); - }).then(function () { + self._view.showContacts(data, searchTerm) + }, function(e) { + self._view.showError() + console.error('There was an error loading your contacts', e) + }).then(function() { // Delete promise, so that contacts are fetched again when the // menu is opened the next time. - delete self._contactsPromise; - }).catch(console.error.bind(this)); + delete self._contactsPromise + }).catch(console.error.bind(this)) } -}; +} -export default ContactsMenu; +export default ContactsMenu diff --git a/core/src/OC/currentuser.js b/core/src/OC/currentuser.js index 061abba89d6..c8f9d59c1eb 100644 --- a/core/src/OC/currentuser.js +++ b/core/src/OC/currentuser.js @@ -31,6 +31,6 @@ export const currentUser = rawUid !== undefined ? rawUid : false export const getCurrentUser = () => { return { uid: currentUser, - displayName, + displayName } } diff --git a/core/src/OC/dialogs.js b/core/src/OC/dialogs.js index b5a2c2c01b3..abc5b3e1c3a 100644 --- a/core/src/OC/dialogs.js +++ b/core/src/OC/dialogs.js @@ -1,5 +1,5 @@ /* global alert */ - +/* eslint-disable */ /* * @copyright 2019 Christoph Wurst * @@ -42,14 +42,15 @@ const Dialogs = { // used to name each dialog dialogsCounter: 0, + /** * displays alert dialog - * @param text content of dialog - * @param title dialog title - * @param callback which will be triggered when user presses OK - * @param modal make the dialog modal + * @param {string} text content of dialog + * @param {string} title dialog title + * @param {function} callback which will be triggered when user presses OK + * @param {boolean} [modal] make the dialog modal */ - alert: function (text, title, callback, modal) { + alert: function(text, title, callback, modal) { this.message( text, title, @@ -57,27 +58,28 @@ const Dialogs = { Dialogs.OK_BUTTON, callback, modal - ); + ) }, /** * displays info dialog - * @param text content of dialog - * @param title dialog title - * @param callback which will be triggered when user presses OK - * @param modal make the dialog modal + * @param {string} text content of dialog + * @param {string} title dialog title + * @param {function} callback which will be triggered when user presses OK + * @param {boolean} [modal] make the dialog modal */ - info: function (text, title, callback, modal) { - this.message(text, title, 'info', Dialogs.OK_BUTTON, callback, modal); + info: function(text, title, callback, modal) { + this.message(text, title, 'info', Dialogs.OK_BUTTON, callback, modal) }, + /** * displays confirmation dialog - * @param text content of dialog - * @param title dialog title - * @param callback which will be triggered when user presses YES or NO - * (true or false would be passed to callback respectively) - * @param modal make the dialog modal + * @param {string} text content of dialog + * @param {string} title dialog title + * @param {function} callback which will be triggered when user presses OK (true or false would be passed to callback respectively) + * @param {boolean} [modal] make the dialog modal + * @returns {Promise} */ - confirm: function (text, title, callback, modal) { + confirm: function(text, title, callback, modal) { return this.message( text, title, @@ -85,17 +87,17 @@ const Dialogs = { Dialogs.YES_NO_BUTTONS, callback, modal - ); + ) }, /** * displays confirmation dialog - * @param text content of dialog - * @param title dialog title - * @param callback which will be triggered when user presses YES or NO - * (true or false would be passed to callback respectively) - * @param modal make the dialog modal + * @param {string} text content of dialog + * @param {string} title dialog title + * @param {function} callback which will be triggered when user presses OK (true or false would be passed to callback respectively) + * @param {boolean} [modal] make the dialog modal + * @returns {Promise} */ - confirmHtml: function (text, title, callback, modal) { + confirmHtml: function(text, title, callback, modal) { return this.message( text, title, @@ -104,79 +106,81 @@ const Dialogs = { callback, modal, true - ); + ) }, /** * displays prompt dialog - * @param text content of dialog - * @param title dialog title - * @param callback which will be triggered when user presses YES or NO - * (true or false would be passed to callback respectively) - * @param modal make the dialog modal - * @param name name of the input field - * @param password whether the input should be a password input + * @param {string} text content of dialog + * @param {string} title dialog title + * @param {function} callback which will be triggered when user presses OK (true or false would be passed to callback respectively) + * @param {boolean} [modal] make the dialog modal + * @param {string} name name of the input field + * @param {boolean} password whether the input should be a password input + * @returns {Promise} */ - prompt: function (text, title, callback, modal, name, password) { - return $.when(this._getMessageTemplate()).then(function ($tmpl) { - var dialogName = 'oc-dialog-' + Dialogs.dialogsCounter + '-content'; - var dialogId = '#' + dialogName; + prompt: function(text, title, callback, modal, name, password) { + return $.when(this._getMessageTemplate()).then(function($tmpl) { + var dialogName = 'oc-dialog-' + Dialogs.dialogsCounter + '-content' + var dialogId = '#' + dialogName var $dlg = $tmpl.octemplate({ dialog_name: dialogName, title: title, message: text, type: 'notice' - }); - var input = $(''); - input.attr('type', password ? 'password' : 'text').attr('id', dialogName + '-input').attr('placeholder', name); - var label = $('