diff options
Diffstat (limited to 'core/js')
-rw-r--r-- | core/js/core.json | 3 | ||||
-rw-r--r-- | core/js/js.js | 30 | ||||
-rw-r--r-- | core/js/lostpassword.js | 4 | ||||
-rw-r--r-- | core/js/multiselect.js | 6 | ||||
-rw-r--r-- | core/js/placeholder.js | 8 | ||||
-rw-r--r-- | core/js/sharedialoglinkshareview.js | 69 | ||||
-rw-r--r-- | core/js/sharedialogmailview.js | 176 | ||||
-rw-r--r-- | core/js/sharedialogshareelistview.js | 4 | ||||
-rw-r--r-- | core/js/sharedialogview.js | 10 | ||||
-rw-r--r-- | core/js/tests/specs/coreSpec.js | 25 |
10 files changed, 240 insertions, 95 deletions
diff --git a/core/js/core.json b/core/js/core.json index d894d59ca54..03c72e9b3ff 100644 --- a/core/js/core.json +++ b/core/js/core.json @@ -1,6 +1,6 @@ { "vendor": [ - "jquery/jquery.min.js", + "jquery/dist/jquery.min.js", "jquery-migrate/jquery-migrate.min.js", "jquery-ui/ui/jquery-ui.custom.js", "underscore/underscore.js", @@ -32,6 +32,7 @@ "sharedialogview.js", "sharedialogexpirationview.js", "sharedialoglinkshareview.js", + "sharedialogmailview.js", "sharedialogresharerinfoview.js", "sharedialogshareelistview.js", "octemplate.js", diff --git a/core/js/js.js b/core/js/js.js index 188c15c5db5..69ebabdb419 100644 --- a/core/js/js.js +++ b/core/js/js.js @@ -752,7 +752,8 @@ var OC={ // sometimes "beforeunload" happens later, so need to defer the reload a bit setTimeout(function() { if (!self._userIsNavigatingAway && !self._reloadCalled) { - OC.reload(); + OC.Notification.show(t('core', 'Problem loading page, reloading in 5 seconds')); + setTimeout(OC.reload, 5000); // only call reload once self._reloadCalled = true; } @@ -1337,9 +1338,6 @@ if(typeof localStorage !=='undefined' && localStorage !== null){ var item = localStorage.getItem(OC.localStorage.namespace+name); if(item === null) { return null; - } else if (typeof JSON === 'undefined') { - //fallback to jquery for IE6/7/8 - return $.parseJSON(item); } else { return JSON.parse(item); } @@ -1439,11 +1437,15 @@ function initCore() { */ moment.locale(OC.getLocale()); - if ($.browser.msie || !!navigator.userAgent.match(/Trident\/7\./)) { - // for IE10+ that don't have conditional comments - // and IE11 doesn't identify as MSIE any more... + var userAgent = window.navigator.userAgent; + var msie = userAgent.indexOf('MSIE '); + var trident = userAgent.indexOf('Trident/'); + var edge = userAgent.indexOf('Edge/'); + + if (msie > 0 || trident > 0) { + // (IE 10 or older) || IE 11 $('html').addClass('ie'); - } else if (!!navigator.userAgent.match(/Edge\/12/)) { + } else if (edge > 0) { // for edge $('html').addClass('edge'); } @@ -1498,9 +1500,15 @@ function initCore() { interval = maxInterval; } var url = OC.generateUrl('/heartbeat'); - setInterval(function(){ - $.post(url); - }, interval * 1000); + var heartBeatTimeout = null; + var heartBeat = function() { + clearTimeout(heartBeatTimeout); + heartBeatTimeout = setInterval(function() { + $.post(url); + }, interval * 1000); + }; + $(document).ajaxComplete(heartBeat); + heartBeat(); } // session heartbeat (defaults to enabled) diff --git a/core/js/lostpassword.js b/core/js/lostpassword.js index df28c2308cb..30d7b98f4e8 100644 --- a/core/js/lostpassword.js +++ b/core/js/lostpassword.js @@ -81,12 +81,12 @@ OC.Lostpassword = { $('#password').parents('form').attr('action'), { password : $('#password').val(), - proceed: $('#encrypted-continue').attr('checked') ? 'true' : 'false' + proceed: $('#encrypted-continue').is(':checked') ? 'true' : 'false' }, OC.Lostpassword.resetDone ); } - if($('#encrypted-continue').attr('checked')) { + if($('#encrypted-continue').is(':checked')) { $('#reset-password #submit').hide(); $('#reset-password #float-spinner').removeClass('hidden'); } diff --git a/core/js/multiselect.js b/core/js/multiselect.js index 6d5c54ac0f5..71cf3e10a69 100644 --- a/core/js/multiselect.js +++ b/core/js/multiselect.js @@ -120,7 +120,7 @@ label.text(element.text() || item); label.attr('title', element.text() || item); if(settings.checked.indexOf(item) !== -1 || checked) { - input.attr('checked', true); + input.prop('checked', true); } if(checked){ if(settings.singleSelect) { @@ -145,7 +145,7 @@ element.attr('selected','selected'); if(typeof settings.oncheck === 'function') { if(settings.oncheck(value)===false) { - $(this).attr('checked', false); + $(this).prop('checked', false); return; } } @@ -157,7 +157,7 @@ element.attr('selected',null); if(typeof settings.onuncheck === 'function') { if(settings.onuncheck(value)===false) { - $(this).attr('checked',true); + $(this).prop('checked',true); return; } } diff --git a/core/js/placeholder.js b/core/js/placeholder.js index da721ac5bcb..1b03a28ecca 100644 --- a/core/js/placeholder.js +++ b/core/js/placeholder.js @@ -92,7 +92,7 @@ // Init vars var result = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; var rgb = [0, 0, 0]; - var sat = 80; + var sat = 70; var lum = 68; var modulo = 16; @@ -106,6 +106,12 @@ for(var count=1;count<modulo;count++) { rgb[count%3] += parseInt(result[count]); } + + // Reduce values bigger than rgb requirements + rgb[0] = rgb[0]%255; + rgb[1] = rgb[1]%255; + rgb[2] = rgb[2]%255; + var hsl = rgbToHsl(rgb[0], rgb[1], rgb[2]); // Classic formulla to check the brigtness for our eye diff --git a/core/js/sharedialoglinkshareview.js b/core/js/sharedialoglinkshareview.js index 1d158ccec16..2fc6f657b02 100644 --- a/core/js/sharedialoglinkshareview.js +++ b/core/js/sharedialoglinkshareview.js @@ -40,12 +40,6 @@ '<label for="sharingDialogAllowPublicUpload-{{cid}}">{{publicUploadLabel}}</label>' + '</div>' + ' {{/if}}' + - ' {{#if mailPublicNotificationEnabled}}' + - '<form id="emailPrivateLink" class="emailPrivateLinkForm">' + - ' <input id="email" class="emailField" value="" placeholder="{{mailPrivatePlaceholder}}" type="text" />' + - ' <input id="emailButton" class="emailButton" type="submit" value="{{mailButtonText}}" />' + - '</form>' + - ' {{/if}}' + '{{else}}' + // FIXME: this doesn't belong in this view '{{#if noSharingPlaceholder}}<input id="shareWith-{{cid}}" class="shareWithField" type="text" placeholder="{{noSharingPlaceholder}}" disabled="disabled"/>{{/if}}' + @@ -76,7 +70,6 @@ showLink: true, events: { - 'submit .emailPrivateLinkForm': '_onEmailPrivateLink', 'focusout input.linkPassText': 'onPasswordEntered', 'keyup input.linkPassText': 'onPasswordKeyUp', 'click .linkCheckbox': 'onLinkCheckBoxChange', @@ -112,7 +105,6 @@ _.bindAll( this, - '_onEmailPrivateLink', 'onLinkCheckBoxChange', 'onPasswordEntered', 'onPasswordKeyUp', @@ -218,34 +210,6 @@ }); }, - _onEmailPrivateLink: function(event) { - event.preventDefault(); - - var $emailField = this.$el.find('.emailField'); - var $emailButton = this.$el.find('.emailButton'); - var email = $emailField.val(); - if (email !== '') { - $emailField.prop('disabled', true); - $emailButton.prop('disabled', true); - $emailField.val(t('core', 'Sending ...')); - this.model.sendEmailPrivateLink(email).done(function() { - $emailField.css('font-weight', 'bold').val(t('core','Email sent')); - setTimeout(function() { - $emailField.val(''); - $emailField.css('font-weight', 'normal'); - $emailField.prop('disabled', false); - $emailButton.prop('disabled', false); - }, 2000); - }).fail(function() { - $emailField.val(email); - $emailField.css('font-weight', 'normal'); - $emailField.prop('disabled', false); - $emailButton.prop('disabled', false); - }); - } - return false; - }, - render: function() { var linkShareTemplate = this.template(); var resharingAllowed = this.model.sharePermissionPossible(); @@ -299,39 +263,6 @@ mailButtonText: t('core', 'Send') })); - var $emailField = this.$el.find('.emailField'); - if (isLinkShare && $emailField.length !== 0) { - $emailField.autocomplete({ - minLength: 1, - source: function (search, response) { - $.get( - OC.generateUrl('core/ajax/share.php'), { - fetch: 'getShareWithEmail', - search: search.term - }, function(result) { - if (result.status == 'success' && result.data.length > 0) { - response(result.data); - } - }); - }, - select: function( event, item ) { - $emailField.val(item.item.email); - return false; - } - }) - .data("ui-autocomplete")._renderItem = function( ul, item ) { - return $('<li>') - .append('<a>' + escapeHTML(item.displayname) + "<br>" + escapeHTML(item.email) + '</a>' ) - .appendTo( ul ); - }; - } - - // TODO drop with IE8 drop - if($('html').hasClass('ie8')) { - this.$el.find('#linkPassText').removeAttr('placeholder'); - this.$el.find('#linkPassText').val(''); - } - this.delegateEvents(); return this; diff --git a/core/js/sharedialogmailview.js b/core/js/sharedialogmailview.js new file mode 100644 index 00000000000..84e3f3242ad --- /dev/null +++ b/core/js/sharedialogmailview.js @@ -0,0 +1,176 @@ +/* + * Copyright (c) 2016 + * + * This file is licensed under the Affero General Public License version 3 + * or later. + * + * See the COPYING-README file. + * + */ + +(function() { + if (!OC.Share) { + OC.Share = {}; + } + + var TEMPLATE = + '{{#if shareAllowed}}' + + ' {{#if mailPublicNotificationEnabled}}' + + '<form id="emailPrivateLink" class="emailPrivateLinkForm">' + + ' <input id="email" class="emailField" value="{{email}}" placeholder="{{mailPrivatePlaceholder}}" type="text" />' + + ' <input id="emailButton" class="emailButton" type="submit" value="{{mailButtonText}}" />' + + '</form>' + + ' {{/if}}' + + '{{/if}}' + ; + + /** + * @class OCA.Share.ShareDialogMailView + * @member {OC.Share.ShareItemModel} model + * @member {jQuery} $el + * @memberof OCA.Sharing + * @classdesc + * + * Represents the GUI of the share dialogue + * + */ + var ShareDialogMailView = OC.Backbone.View.extend({ + /** @type {string} **/ + id: 'shareDialogMailView', + + /** @type {OC.Share.ShareConfigModel} **/ + configModel: undefined, + + /** @type {Function} **/ + _template: undefined, + + /** @type {boolean} **/ + showLink: true, + + events: { + 'submit .emailPrivateLinkForm': '_onEmailPrivateLink' + }, + + initialize: function(options) { + var view = this; + + this.model.on('change:linkShare', function() { + view.render(); + }); + + if(!_.isUndefined(options.configModel)) { + this.configModel = options.configModel; + } else { + throw 'missing OC.Share.ShareConfigModel'; + } + + _.bindAll( + this, + '_onEmailPrivateLink' + ); + }, + + _onEmailPrivateLink: function(event) { + event.preventDefault(); + + var $emailField = this.$el.find('.emailField'); + var $emailButton = this.$el.find('.emailButton'); + var email = $emailField.val(); + if (email !== '') { + $emailField.prop('disabled', true); + $emailButton.prop('disabled', true); + $emailField.val(t('core', 'Sending ...')); + this.model.sendEmailPrivateLink(email).done(function() { + $emailField.css('font-weight', 'bold').val(t('core','Email sent')); + setTimeout(function() { + $emailField.val(''); + $emailField.css('font-weight', 'normal'); + $emailField.prop('disabled', false); + $emailButton.prop('disabled', false); + }, 2000); + }).fail(function() { + $emailField.val(email); + $emailField.css('font-weight', 'normal'); + $emailField.prop('disabled', false); + $emailButton.prop('disabled', false); + }); + } + return false; + }, + + render: function() { + var linkShareTemplate = this.template(); + var resharingAllowed = this.model.sharePermissionPossible(); + var email = this.$el.find('.emailField').val(); + + if(!resharingAllowed + || !this.showLink + || !this.configModel.isShareWithLinkAllowed()) + { + var templateData = {shareAllowed: false}; + if (!resharingAllowed) { + // add message + templateData.noSharingPlaceholder = t('core', 'Resharing is not allowed'); + } + this.$el.html(linkShareTemplate(templateData)); + return this; + } + + var isLinkShare = this.model.get('linkShare').isLinkShare; + + this.$el.html(linkShareTemplate({ + cid: this.cid, + shareAllowed: true, + mailPublicNotificationEnabled: isLinkShare && this.configModel.isMailPublicNotificationEnabled(), + mailPrivatePlaceholder: t('core', 'Email link to person'), + mailButtonText: t('core', 'Send link via email'), + email: email + })); + + var $emailField = this.$el.find('.emailField'); + if (isLinkShare && $emailField.length !== 0) { + $emailField.autocomplete({ + minLength: 1, + source: function (search, response) { + $.get( + OC.generateUrl('core/ajax/share.php'), { + fetch: 'getShareWithEmail', + search: search.term + }, function(result) { + if (result.status == 'success' && result.data.length > 0) { + response(result.data); + } + }); + }, + select: function( event, item ) { + $emailField.val(item.item.email); + return false; + } + }) + .data("ui-autocomplete")._renderItem = function( ul, item ) { + return $('<li>') + .append('<a>' + escapeHTML(item.displayname) + "<br>" + escapeHTML(item.email) + '</a>' ) + .appendTo( ul ); + }; + } + this.delegateEvents(); + + return this; + }, + + /** + * @returns {Function} from Handlebars + * @private + */ + template: function () { + if (!this._template) { + this._template = Handlebars.compile(TEMPLATE); + } + return this._template; + } + + }); + + OC.Share.ShareDialogMailView = ShareDialogMailView; + +})();
\ No newline at end of file diff --git a/core/js/sharedialogshareelistview.js b/core/js/sharedialogshareelistview.js index 33f30d08fec..83fde154615 100644 --- a/core/js/sharedialogshareelistview.js +++ b/core/js/sharedialogshareelistview.js @@ -260,11 +260,11 @@ if ($element.attr('name') === 'edit') { checked = $element.is(':checked'); // Check/uncheck Create, Update, and Delete checkboxes if Edit is checked/unck - $($checkboxes).attr('checked', checked); + $($checkboxes).prop('checked', checked); } else { var numberChecked = $checkboxes.filter(':checked').length; checked = numberChecked > 0; - $('input[name="edit"]', $li).attr('checked', checked); + $('input[name="edit"]', $li).prop('checked', checked); } var permissions = OC.PERMISSION_READ; diff --git a/core/js/sharedialogview.js b/core/js/sharedialogview.js index 56f53caddae..a4bfde1777b 100644 --- a/core/js/sharedialogview.js +++ b/core/js/sharedialogview.js @@ -26,6 +26,7 @@ '<div class="shareeListView subView"></div>' + '<div class="linkShareView subView"></div>' + '<div class="expirationView subView"></div>' + + '<div class="mailView subView"></div>' + '<div class="loading hidden" style="height: 50px"></div>'; var TEMPLATE_REMOTE_SHARE_INFO = @@ -67,6 +68,9 @@ /** @type {object} **/ shareeListView: undefined, + /** @type {object} **/ + mailView: undefined, + events: { 'input .shareWithField': 'onShareWithFieldChanged' }, @@ -103,7 +107,8 @@ resharerInfoView: 'ShareDialogResharerInfoView', linkShareView: 'ShareDialogLinkShareView', expirationView: 'ShareDialogExpirationView', - shareeListView: 'ShareDialogShareeListView' + shareeListView: 'ShareDialogShareeListView', + mailView: 'ShareDialogMailView' }; for(var name in subViews) { @@ -360,6 +365,9 @@ this.shareeListView.$el = this.$el.find('.shareeListView'); this.shareeListView.render(); + this.mailView.$el = this.$el.find('.mailView'); + this.mailView.render(); + this.$el.find('.hasTooltip').tooltip(); return this; diff --git a/core/js/tests/specs/coreSpec.js b/core/js/tests/specs/coreSpec.js index f18ecbc1a44..3d19a38c416 100644 --- a/core/js/tests/specs/coreSpec.js +++ b/core/js/tests/specs/coreSpec.js @@ -305,6 +305,7 @@ describe('Core base tests', function() { counter++; xhr.respond(200, {'Content-Type': 'application/json'}, '{}'); }); + $(document).off('ajaxComplete'); // ignore previously registered heartbeats }); afterEach(function() { clock.restore(); @@ -312,6 +313,7 @@ describe('Core base tests', function() { window.oc_config = oldConfig; routeStub.restore(); $(document).off('ajaxError'); + $(document).off('ajaxComplete'); }); it('sends heartbeat half the session lifetime when heartbeat enabled', function() { /* jshint camelcase: false */ @@ -340,7 +342,7 @@ describe('Core base tests', function() { clock.tick(20 * 1000); expect(counter).toEqual(2); }); - it('does no send heartbeat when heartbeat disabled', function() { + it('does not send heartbeat when heartbeat disabled', function() { /* jshint camelcase: false */ window.oc_config = { session_keepalive: false, @@ -470,6 +472,7 @@ describe('Core base tests', function() { var $navigation; beforeEach(function() { + jQuery.fx.off = true; clock = sinon.useFakeTimers(); $('#testArea').append('<div id="header">' + '<a class="menutoggle header-appname-container" href="#">' + @@ -482,6 +485,7 @@ describe('Core base tests', function() { $navigation = $('#navigation'); }); afterEach(function() { + jQuery.fx.off = false; clock.restore(); $(document).off('ajaxError'); }); @@ -491,7 +495,6 @@ describe('Core base tests', function() { }); it('Clicking menu toggle toggles navigation in', function() { window.initCore(); - $navigation.hide(); // normally done through media query triggered CSS expect($navigation.is(':visible')).toEqual(false); $toggle.click(); clock.tick(1 * 1000); @@ -935,10 +938,13 @@ describe('Core base tests', function() { }); describe('global ajax errors', function() { var reloadStub, ajaxErrorStub, clock; + var notificationStub; + var waitTimeMs = 6000; beforeEach(function() { clock = sinon.useFakeTimers(); reloadStub = sinon.stub(OC, 'reload'); + notificationStub = sinon.stub(OC.Notification, 'show'); // unstub the error processing method ajaxErrorStub = OC._processAjaxError; ajaxErrorStub.restore(); @@ -946,6 +952,7 @@ describe('Core base tests', function() { }); afterEach(function() { reloadStub.restore(); + notificationStub.restore(); clock.restore(); }); @@ -970,7 +977,7 @@ describe('Core base tests', function() { $(document).trigger(new $.Event('ajaxError'), xhr); // trigger timers - clock.tick(1000); + clock.tick(waitTimeMs); if (expectedCall) { expect(reloadStub.calledOnce).toEqual(true); @@ -986,7 +993,7 @@ describe('Core base tests', function() { $(document).trigger(new $.Event('ajaxError'), xhr); // trigger timers - clock.tick(1000); + clock.tick(waitTimeMs); expect(reloadStub.calledOnce).toEqual(true); }); @@ -997,9 +1004,17 @@ describe('Core base tests', function() { $(document).trigger(new $.Event('ajaxError'), xhr); - clock.tick(1000); + clock.tick(waitTimeMs); expect(reloadStub.notCalled).toEqual(true); }); + it('displays notification', function() { + var xhr = { status: 401 }; + + $(document).trigger(new $.Event('ajaxError'), xhr); + + clock.tick(waitTimeMs); + expect(notificationStub.calledOnce).toEqual(true); + }); }); }); |