Merge pull request #13878 from nextcloud/refactor/oc-appconfig-eventsource-l10n
Move OC.AppConfig, OC.EventSource and OC.L10N to the server bundle
This commit is contained in:
commit
2682d672d8
|
@ -9,7 +9,6 @@
|
||||||
"jquery.ocdialog.js",
|
"jquery.ocdialog.js",
|
||||||
"oc-dialogs.js",
|
"oc-dialogs.js",
|
||||||
"js.js",
|
"js.js",
|
||||||
"l10n.js",
|
|
||||||
"share.js",
|
"share.js",
|
||||||
"sharetemplates.js",
|
"sharetemplates.js",
|
||||||
"sharesocialmanager.js",
|
"sharesocialmanager.js",
|
||||||
|
@ -21,8 +20,6 @@
|
||||||
"sharedialogshareelistview.js",
|
"sharedialogshareelistview.js",
|
||||||
"octemplate.js",
|
"octemplate.js",
|
||||||
"contactsmenu_templates.js",
|
"contactsmenu_templates.js",
|
||||||
"eventsource.js",
|
|
||||||
"config.js",
|
|
||||||
"public/appconfig.js",
|
"public/appconfig.js",
|
||||||
"public/comments.js",
|
"public/comments.js",
|
||||||
"public/publicpage.js",
|
"public/publicpage.js",
|
||||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -2,13 +2,10 @@
|
||||||
"jquery.ocdialog.js",
|
"jquery.ocdialog.js",
|
||||||
"oc-dialogs.js",
|
"oc-dialogs.js",
|
||||||
"js.js",
|
"js.js",
|
||||||
"l10n.js",
|
|
||||||
"octemplate.js",
|
"octemplate.js",
|
||||||
"eventsource.js",
|
|
||||||
"public/appconfig.js",
|
"public/appconfig.js",
|
||||||
"public/comments.js",
|
"public/comments.js",
|
||||||
"public/whatsnew.js",
|
"public/whatsnew.js",
|
||||||
"config.js",
|
|
||||||
"oc-requesttoken.js",
|
"oc-requesttoken.js",
|
||||||
"mimetype.js",
|
"mimetype.js",
|
||||||
"mimetypelist.js",
|
"mimetypelist.js",
|
||||||
|
|
|
@ -18,11 +18,13 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import OCP from '../OCP/index';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @namespace
|
* @namespace
|
||||||
* @deprecated Use OCP.AppConfig instead
|
* @deprecated 16.0.0 Use OCP.AppConfig instead
|
||||||
*/
|
*/
|
||||||
OC.AppConfig={
|
const AppConfig = {
|
||||||
/**
|
/**
|
||||||
* @deprecated Use OCP.AppConfig.getValue() instead
|
* @deprecated Use OCP.AppConfig.getValue() instead
|
||||||
*/
|
*/
|
||||||
|
@ -63,4 +65,7 @@ OC.AppConfig={
|
||||||
deleteKey:function(app,key){
|
deleteKey:function(app,key){
|
||||||
OCP.AppConfig.deleteKey(app, key);
|
OCP.AppConfig.deleteKey(app, key);
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export default AppConfig;
|
|
@ -30,70 +30,72 @@
|
||||||
|
|
||||||
/* global EventSource */
|
/* global EventSource */
|
||||||
|
|
||||||
|
import $ from 'jquery'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new event source
|
* Create a new event source
|
||||||
* @param {string} src
|
* @param {string} src
|
||||||
* @param {object} [data] to be send as GET
|
* @param {object} [data] to be send as GET
|
||||||
*
|
*
|
||||||
* @constructs OC.EventSource
|
* @constructs OCEventSource
|
||||||
*/
|
*/
|
||||||
OC.EventSource=function(src,data){
|
const OCEventSource = function (src, data) {
|
||||||
var dataStr='';
|
var dataStr = '';
|
||||||
var name;
|
var name;
|
||||||
var joinChar;
|
var joinChar;
|
||||||
this.typelessListeners=[];
|
this.typelessListeners = [];
|
||||||
this.closed = false;
|
this.closed = false;
|
||||||
this.listeners={};
|
this.listeners = {};
|
||||||
if(data){
|
if (data) {
|
||||||
for(name in data){
|
for (name in data) {
|
||||||
dataStr+=name+'='+encodeURIComponent(data[name])+'&';
|
dataStr += name + '=' + encodeURIComponent(data[name]) + '&';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dataStr+='requesttoken='+encodeURIComponent(oc_requesttoken);
|
dataStr += 'requesttoken=' + encodeURIComponent(oc_requesttoken);
|
||||||
if(!this.useFallBack && typeof EventSource !== 'undefined'){
|
if (!this.useFallBack && typeof EventSource !== 'undefined') {
|
||||||
joinChar = '&';
|
joinChar = '&';
|
||||||
if(src.indexOf('?') === -1) {
|
if (src.indexOf('?') === -1) {
|
||||||
joinChar = '?';
|
joinChar = '?';
|
||||||
}
|
}
|
||||||
this.source= new EventSource(src+joinChar+dataStr);
|
this.source = new EventSource(src + joinChar + dataStr);
|
||||||
this.source.onmessage=function(e){
|
this.source.onmessage = function (e) {
|
||||||
for(var i=0;i<this.typelessListeners.length;i++){
|
for (var i = 0; i < this.typelessListeners.length; i++) {
|
||||||
this.typelessListeners[i](JSON.parse(e.data));
|
this.typelessListeners[i](JSON.parse(e.data));
|
||||||
}
|
}
|
||||||
}.bind(this);
|
}.bind(this);
|
||||||
}else{
|
} else {
|
||||||
var iframeId='oc_eventsource_iframe_'+OC.EventSource.iframeCount;
|
var iframeId = 'oc_eventsource_iframe_' + OCEventSource.iframeCount;
|
||||||
OC.EventSource.fallBackSources[OC.EventSource.iframeCount]=this;
|
OCEventSource.fallBackSources[OCEventSource.iframeCount] = this;
|
||||||
this.iframe=$('<iframe/>');
|
this.iframe = $('<iframe/>');
|
||||||
this.iframe.attr('id',iframeId);
|
this.iframe.attr('id', iframeId);
|
||||||
this.iframe.hide();
|
this.iframe.hide();
|
||||||
|
|
||||||
joinChar = '&';
|
joinChar = '&';
|
||||||
if(src.indexOf('?') === -1) {
|
if (src.indexOf('?') === -1) {
|
||||||
joinChar = '?';
|
joinChar = '?';
|
||||||
}
|
}
|
||||||
this.iframe.attr('src',src+joinChar+'fallback=true&fallback_id='+OC.EventSource.iframeCount+'&'+dataStr);
|
this.iframe.attr('src', src + joinChar + 'fallback=true&fallback_id=' + OCEventSource.iframeCount + '&' + dataStr);
|
||||||
$('body').append(this.iframe);
|
$('body').append(this.iframe);
|
||||||
this.useFallBack=true;
|
this.useFallBack = true;
|
||||||
OC.EventSource.iframeCount++;
|
OCEventSource.iframeCount++;
|
||||||
}
|
}
|
||||||
//add close listener
|
//add close listener
|
||||||
this.listen('__internal__',function(data){
|
this.listen('__internal__', function (data) {
|
||||||
if(data === 'close'){
|
if (data === 'close') {
|
||||||
this.close();
|
this.close();
|
||||||
}
|
}
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
};
|
};
|
||||||
OC.EventSource.fallBackSources=[];
|
OCEventSource.fallBackSources = [];
|
||||||
OC.EventSource.iframeCount=0;//number of fallback iframes
|
OCEventSource.iframeCount = 0;//number of fallback iframes
|
||||||
OC.EventSource.fallBackCallBack=function(id,type,data){
|
OCEventSource.fallBackCallBack = function (id, type, data) {
|
||||||
OC.EventSource.fallBackSources[id].fallBackCallBack(type,data);
|
OCEventSource.fallBackSources[id].fallBackCallBack(type, data);
|
||||||
};
|
};
|
||||||
OC.EventSource.prototype={
|
OCEventSource.prototype = {
|
||||||
typelessListeners:[],
|
typelessListeners: [],
|
||||||
iframe:null,
|
iframe: null,
|
||||||
listeners:{},//only for fallback
|
listeners: {},//only for fallback
|
||||||
useFallBack:false,
|
useFallBack: false,
|
||||||
/**
|
/**
|
||||||
* Fallback callback for browsers that don't have the
|
* Fallback callback for browsers that don't have the
|
||||||
* native EventSource object.
|
* native EventSource object.
|
||||||
|
@ -104,50 +106,50 @@ OC.EventSource.prototype={
|
||||||
* @param {String} type event type
|
* @param {String} type event type
|
||||||
* @param {Object} data received data
|
* @param {Object} data received data
|
||||||
*/
|
*/
|
||||||
fallBackCallBack:function(type,data){
|
fallBackCallBack: function (type, data) {
|
||||||
var i;
|
var i;
|
||||||
// ignore messages that might appear after closing
|
// ignore messages that might appear after closing
|
||||||
if (this.closed) {
|
if (this.closed) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(type){
|
if (type) {
|
||||||
if (typeof this.listeners.done !== 'undefined') {
|
if (typeof this.listeners.done !== 'undefined') {
|
||||||
for(i=0;i<this.listeners[type].length;i++){
|
for (i = 0; i < this.listeners[type].length; i++) {
|
||||||
this.listeners[type][i](data);
|
this.listeners[type][i](data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}else{
|
} else {
|
||||||
for(i=0;i<this.typelessListeners.length;i++){
|
for (i = 0; i < this.typelessListeners.length; i++) {
|
||||||
this.typelessListeners[i](data);
|
this.typelessListeners[i](data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
lastLength:0,//for fallback
|
lastLength: 0,//for fallback
|
||||||
/**
|
/**
|
||||||
* Listen to a given type of events.
|
* Listen to a given type of events.
|
||||||
*
|
*
|
||||||
* @param {String} type event type
|
* @param {String} type event type
|
||||||
* @param {Function} callback event callback
|
* @param {Function} callback event callback
|
||||||
*/
|
*/
|
||||||
listen:function(type,callback){
|
listen: function (type, callback) {
|
||||||
if(callback && callback.call){
|
if (callback && callback.call) {
|
||||||
|
|
||||||
if(type){
|
if (type) {
|
||||||
if(this.useFallBack){
|
if (this.useFallBack) {
|
||||||
if(!this.listeners[type]){
|
if (!this.listeners[type]) {
|
||||||
this.listeners[type]=[];
|
this.listeners[type] = [];
|
||||||
}
|
}
|
||||||
this.listeners[type].push(callback);
|
this.listeners[type].push(callback);
|
||||||
}else{
|
} else {
|
||||||
this.source.addEventListener(type,function(e){
|
this.source.addEventListener(type, function (e) {
|
||||||
if (typeof e.data !== 'undefined') {
|
if (typeof e.data !== 'undefined') {
|
||||||
callback(JSON.parse(e.data));
|
callback(JSON.parse(e.data));
|
||||||
} else {
|
} else {
|
||||||
callback('');
|
callback('');
|
||||||
}
|
}
|
||||||
},false);
|
}, false);
|
||||||
}
|
}
|
||||||
}else{
|
} else {
|
||||||
this.typelessListeners.push(callback);
|
this.typelessListeners.push(callback);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -155,10 +157,12 @@ OC.EventSource.prototype={
|
||||||
/**
|
/**
|
||||||
* Closes this event source.
|
* Closes this event source.
|
||||||
*/
|
*/
|
||||||
close:function(){
|
close: function () {
|
||||||
this.closed = true;
|
this.closed = true;
|
||||||
if (typeof this.source !== 'undefined') {
|
if (typeof this.source !== 'undefined') {
|
||||||
this.source.close();
|
this.source.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export default OCEventSource;
|
|
@ -22,7 +22,10 @@
|
||||||
import Backbone from 'backbone';
|
import Backbone from 'backbone';
|
||||||
|
|
||||||
import Apps from './apps'
|
import Apps from './apps'
|
||||||
|
import AppConfig from './appconfig'
|
||||||
import ContactsMenu from './contactsmenu';
|
import ContactsMenu from './contactsmenu';
|
||||||
|
import EventSource from './eventsource'
|
||||||
|
import L10N from './l10n'
|
||||||
import {davCall, davSync} from './backbone-webdav';
|
import {davCall, davSync} from './backbone-webdav';
|
||||||
|
|
||||||
// Patch Backbone for DAV
|
// Patch Backbone for DAV
|
||||||
|
@ -34,6 +37,9 @@ Object.assign(Backbone, {
|
||||||
/** @namespace OC */
|
/** @namespace OC */
|
||||||
export default {
|
export default {
|
||||||
Apps,
|
Apps,
|
||||||
|
AppConfig,
|
||||||
Backbone,
|
Backbone,
|
||||||
ContactsMenu,
|
ContactsMenu,
|
||||||
|
EventSource,
|
||||||
|
L10N,
|
||||||
};
|
};
|
||||||
|
|
|
@ -8,12 +8,18 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import _ from 'underscore'
|
||||||
|
import $ from 'jquery'
|
||||||
|
import Handlebars from 'handlebars'
|
||||||
|
|
||||||
|
import OC from './index'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* L10N namespace with localization functions.
|
* L10N namespace with localization functions.
|
||||||
*
|
*
|
||||||
* @namespace
|
* @namespace OC.L10n
|
||||||
*/
|
*/
|
||||||
OC.L10N = {
|
const L10n = {
|
||||||
/**
|
/**
|
||||||
* String bundles with app name as key.
|
* String bundles with app name as key.
|
||||||
* @type {Object.<String,String>}
|
* @type {Object.<String,String>}
|
||||||
|
@ -321,28 +327,9 @@ OC.L10N = {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
export default L10n;
|
||||||
* translate a string
|
|
||||||
* @param {string} app the id of the app for which to translate the string
|
|
||||||
* @param {string} text the string to translate
|
|
||||||
* @param [vars] map of placeholder key to value
|
|
||||||
* @param {number} [count] number to replace %n with
|
|
||||||
* @return {string}
|
|
||||||
*/
|
|
||||||
window.t = _.bind(OC.L10N.translate, OC.L10N);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* translate a string
|
|
||||||
* @param {string} app the id of the app for which to translate the string
|
|
||||||
* @param {string} text_singular the string to translate for exactly one object
|
|
||||||
* @param {string} text_plural the string to translate for n objects
|
|
||||||
* @param {number} count number to determine whether to use singular or plural
|
|
||||||
* @param [vars] map of placeholder key to value
|
|
||||||
* @return {string} Translated string
|
|
||||||
*/
|
|
||||||
window.n = _.bind(OC.L10N.translatePlural, OC.L10N);
|
|
||||||
|
|
||||||
Handlebars.registerHelper('t', function(app, text) {
|
Handlebars.registerHelper('t', function(app, text) {
|
||||||
return OC.L10N.translate(app, text);
|
return L10n.translate(app, text);
|
||||||
});
|
});
|
||||||
|
|
|
@ -72,3 +72,24 @@ window['moment'] = moment
|
||||||
window['OC'] = OC
|
window['OC'] = OC
|
||||||
window['OCP'] = OCP
|
window['OCP'] = OCP
|
||||||
window['OCA'] = OCA
|
window['OCA'] = OCA
|
||||||
|
|
||||||
|
/**
|
||||||
|
* translate a string
|
||||||
|
* @param {string} app the id of the app for which to translate the string
|
||||||
|
* @param {string} text the string to translate
|
||||||
|
* @param [vars] map of placeholder key to value
|
||||||
|
* @param {number} [count] number to replace %n with
|
||||||
|
* @return {string}
|
||||||
|
*/
|
||||||
|
window.t = _.bind(OC.L10N.translate, OC.L10N);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* translate a string
|
||||||
|
* @param {string} app the id of the app for which to translate the string
|
||||||
|
* @param {string} text_singular the string to translate for exactly one object
|
||||||
|
* @param {string} text_plural the string to translate for n objects
|
||||||
|
* @param {number} count number to determine whether to use singular or plural
|
||||||
|
* @param [vars] map of placeholder key to value
|
||||||
|
* @return {string} Translated string
|
||||||
|
*/
|
||||||
|
window.n = _.bind(OC.L10N.translatePlural, OC.L10N);
|
||||||
|
|
Loading…
Reference in New Issue