diff options
author | Thomas Müller <thomas.mueller@tmit.eu> | 2013-07-12 09:43:04 +0200 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2013-07-12 09:43:04 +0200 |
commit | 24b4806af4a9b485b4b9a772809d118e91c6d97f (patch) | |
tree | df5664782eefd384bd6ed3dc363a25575da89202 /core/js | |
parent | 8793acfb4e751cfdb464d259de45249cec5d6398 (diff) | |
parent | 3abe68176ff09ca579ff9e5f15872fb5cab8ff4d (diff) | |
download | nextcloud-server-24b4806af4a9b485b4b9a772809d118e91c6d97f.tar.gz nextcloud-server-24b4806af4a9b485b4b9a772809d118e91c6d97f.zip |
Merge branch 'master' into googledrive
Diffstat (limited to 'core/js')
-rw-r--r-- | core/js/config.php | 2 | ||||
-rw-r--r-- | core/js/eventsource.js | 6 | ||||
-rw-r--r-- | core/js/jquery.multiselect.js | 153 | ||||
-rw-r--r-- | core/js/jquery.ocdialog.js | 217 | ||||
-rw-r--r-- | core/js/js.js | 17 | ||||
-rw-r--r-- | core/js/multiselect.js | 4 | ||||
-rw-r--r-- | core/js/oc-dialogs.js | 29 | ||||
-rw-r--r-- | core/js/octemplate.js | 8 | ||||
-rw-r--r-- | core/js/share.js | 51 | ||||
-rw-r--r-- | core/js/update.js | 5 |
10 files changed, 408 insertions, 84 deletions
diff --git a/core/js/config.php b/core/js/config.php index 53a8fb96388..dd46f7889d1 100644 --- a/core/js/config.php +++ b/core/js/config.php @@ -26,8 +26,6 @@ $array = array( "oc_debug" => (defined('DEBUG') && DEBUG) ? 'true' : 'false', "oc_webroot" => "\"".OC::$WEBROOT."\"", "oc_appswebroots" => str_replace('\\/', '/', json_encode($apps_paths)), // Ugly unescape slashes waiting for better solution - "oc_current_user" => "document.getElementsByTagName('head')[0].getAttribute('data-user')", - "oc_requesttoken" => "document.getElementsByTagName('head')[0].getAttribute('data-requesttoken')", "datepickerFormatDate" => json_encode($l->l('jsdate', 'jsdate')), "dayNames" => json_encode( array( diff --git a/core/js/eventsource.js b/core/js/eventsource.js index ce8c8387c8e..536b180bc8f 100644 --- a/core/js/eventsource.js +++ b/core/js/eventsource.js @@ -110,7 +110,11 @@ OC.EventSource.prototype={ this.listeners[type].push(callback); }else{ this.source.addEventListener(type,function(e){ - callback(JSON.parse(e.data)); + if (typeof e.data != 'undefined') { + callback(JSON.parse(e.data)); + } else { + callback(''); + } },false); } }else{ diff --git a/core/js/jquery.multiselect.js b/core/js/jquery.multiselect.js index 46aab7ebf01..16ae4264177 100644 --- a/core/js/jquery.multiselect.js +++ b/core/js/jquery.multiselect.js @@ -1,6 +1,7 @@ +/* jshint forin:true, noarg:true, noempty:true, eqeqeq:true, boss:true, undef:true, curly:true, browser:true, jquery:true */ /* - * jQuery MultiSelect UI Widget 1.11 - * Copyright (c) 2011 Eric Hynds + * jQuery MultiSelect UI Widget 1.13 + * Copyright (c) 2012 Eric Hynds * * http://www.erichynds.com/jquery/jquery-ui-multiselect-widget/ * @@ -34,8 +35,8 @@ $.widget("ech.multiselect", { noneSelectedText: 'Select options', selectedText: '# selected', selectedList: 0, - show: '', - hide: '', + show: null, + hide: null, autoOpen: false, multiple: true, position: {} @@ -62,7 +63,7 @@ $.widget("ech.multiselect", { menu = (this.menu = $('<div />')) .addClass('ui-multiselect-menu ui-widget ui-widget-content ui-corner-all') .addClass( o.classes ) - .insertAfter( button ), + .appendTo( document.body ), header = (this.header = $('<div />')) .addClass('ui-widget-header ui-corner-all ui-multiselect-header ui-helper-clearfix') @@ -119,70 +120,72 @@ $.widget("ech.multiselect", { menu = this.menu, checkboxContainer = this.checkboxContainer, optgroups = [], - html = [], + html = "", id = el.attr('id') || multiselectID++; // unique ID for the label & option tags // build items - this.element.find('option').each(function( i ){ + el.find('option').each(function( i ){ var $this = $(this), parent = this.parentNode, title = this.innerHTML, description = this.title, value = this.value, - inputID = this.id || 'ui-multiselect-'+id+'-option-'+i, + inputID = 'ui-multiselect-' + (this.id || id + '-option-' + i), isDisabled = this.disabled, isSelected = this.selected, - labelClasses = ['ui-corner-all'], + labelClasses = [ 'ui-corner-all' ], + liClasses = (isDisabled ? 'ui-multiselect-disabled ' : ' ') + this.className, optLabel; // is this an optgroup? - if( parent.tagName.toLowerCase() === 'optgroup' ){ - optLabel = parent.getAttribute('label'); + if( parent.tagName === 'OPTGROUP' ){ + optLabel = parent.getAttribute( 'label' ); // has this optgroup been added already? if( $.inArray(optLabel, optgroups) === -1 ){ - html.push('<li class="ui-multiselect-optgroup-label"><a href="#">' + optLabel + '</a></li>'); + html += '<li class="ui-multiselect-optgroup-label ' + parent.className + '"><a href="#">' + optLabel + '</a></li>'; optgroups.push( optLabel ); } } if( isDisabled ){ - labelClasses.push('ui-state-disabled'); + labelClasses.push( 'ui-state-disabled' ); } // browsers automatically select the first option // by default with single selects if( isSelected && !o.multiple ){ - labelClasses.push('ui-state-active'); + labelClasses.push( 'ui-state-active' ); } - html.push('<li class="' + (isDisabled ? 'ui-multiselect-disabled' : '') + '">'); + html += '<li class="' + liClasses + '">'; // create the label - html.push('<label for="'+inputID+'" title="'+description+'" class="'+labelClasses.join(' ')+ '">'); - html.push('<input id="'+inputID+'" name="multiselect_'+id+'" type="'+(o.multiple ? "checkbox" : "radio")+'" value="'+value+'" title="'+title+'"'); + html += '<label for="' + inputID + '" title="' + description + '" class="' + labelClasses.join(' ') + '">'; + html += '<input id="' + inputID + '" name="multiselect_' + id + '" type="' + (o.multiple ? "checkbox" : "radio") + '" value="' + value + '" title="' + title + '"'; // pre-selected? if( isSelected ){ - html.push(' checked="checked"'); - html.push(' aria-selected="true"'); + html += ' checked="checked"'; + html += ' aria-selected="true"'; } // disabled? if( isDisabled ){ - html.push(' disabled="disabled"'); - html.push(' aria-disabled="true"'); + html += ' disabled="disabled"'; + html += ' aria-disabled="true"'; } // add the title and close everything off - html.push(' /><span>' + title + '</span></label></li>'); + html += ' /><span>' + title + '</span></label></li>'; }); // insert into the DOM - checkboxContainer.html( html.join('') ); + checkboxContainer.html( html ); // cache some moar useful elements this.labels = menu.find('label'); + this.inputs = this.labels.children('input'); // set widths this._setButtonWidth(); @@ -197,10 +200,10 @@ $.widget("ech.multiselect", { } }, - // updates the button text. call refresh() to rebuild + // updates the button text. call refresh() to rebuild update: function(){ var o = this.options, - $inputs = this.labels.find('input'), + $inputs = this.inputs, $checked = $inputs.filter(':checked'), numChecked = $checked.length, value; @@ -211,7 +214,7 @@ $.widget("ech.multiselect", { if($.isFunction( o.selectedText )){ value = o.selectedText.call(this, numChecked, $inputs.length, $checked.get()); } else if( /\d/.test(o.selectedList) && o.selectedList > 0 && numChecked <= o.selectedList){ - value = $checked.map(function(){ return this.title; }).get().join(', '); + value = $checked.map(function(){ return $(this).next().html(); }).get().join(', '); } else { value = o.selectedText.replace('#', numChecked).replace('#', $inputs.length); } @@ -291,8 +294,8 @@ $.widget("ech.multiselect", { var $this = $(this), $inputs = $this.parent().nextUntil('li.ui-multiselect-optgroup-label').find('input:visible:not(:disabled)'), - nodes = $inputs.get(), - label = $this.parent().text(); + nodes = $inputs.get(), + label = $this.parent().text(); // trigger event and bail if the return is false if( self._trigger('beforeoptgrouptoggle', e, { inputs:nodes, label:label }) === false ){ @@ -343,11 +346,15 @@ $.widget("ech.multiselect", { tags = self.element.find('option'); // bail if this input is disabled or the event is cancelled - if( this.disabled || self._trigger('click', e, { value:val, text:this.title, checked:checked }) === false ){ + if( this.disabled || self._trigger('click', e, { value: val, text: this.title, checked: checked }) === false ){ e.preventDefault(); return; } + // make sure the input has focus. otherwise, the esc key + // won't close the menu after clicking an item. + $this.focus(); + // toggle aria state $this.attr('aria-selected', checked); @@ -389,7 +396,7 @@ $.widget("ech.multiselect", { // handler fires before the form is actually reset. delaying it a bit // gives the form inputs time to clear. $(this.element[0].form).bind('reset.multiselect', function(){ - setTimeout(function(){ self.update(); }, 10); + setTimeout($.proxy(self.refresh, self), 10); }); }, @@ -428,7 +435,7 @@ $.widget("ech.multiselect", { // if at the first/last element if( !$next.length ){ - var $container = this.menu.find('ul:last'); + var $container = this.menu.find('ul').last(); // move to the first/last this.menu.find('label')[ moveToLast ? 'last' : 'first' ]().trigger('mouseover'); @@ -445,27 +452,29 @@ $.widget("ech.multiselect", { // other related attributes of a checkbox. // // The context of this function should be a checkbox; do not proxy it. - _toggleCheckbox: function( prop, flag ){ + _toggleState: function( prop, flag ){ return function(){ - !this.disabled && (this[ prop ] = flag); + if( !this.disabled ) { + this[ prop ] = flag; + } if( flag ){ this.setAttribute('aria-selected', true); } else { this.removeAttribute('aria-selected'); } - } + }; }, _toggleChecked: function( flag, group ){ - var $inputs = (group && group.length) ? - group : - this.labels.find('input'), - + var $inputs = (group && group.length) ? group : this.inputs, self = this; // toggle state on inputs - $inputs.each(this._toggleCheckbox('checked', flag)); + $inputs.each(this._toggleState('checked', flag)); + + // give the first input focus + $inputs.eq(0).focus(); // update button text this.update(); @@ -480,7 +489,7 @@ $.widget("ech.multiselect", { .find('option') .each(function(){ if( !this.disabled && $.inArray(this.value, values) > -1 ){ - self._toggleCheckbox('selected', flag).call( this ); + self._toggleState('selected', flag).call( this ); } }); @@ -494,9 +503,22 @@ $.widget("ech.multiselect", { this.button .attr({ 'disabled':flag, 'aria-disabled':flag })[ flag ? 'addClass' : 'removeClass' ]('ui-state-disabled'); - this.menu - .find('input') - .attr({ 'disabled':flag, 'aria-disabled':flag }) + var inputs = this.menu.find('input'); + var key = "ech-multiselect-disabled"; + + if(flag) { + // remember which elements this widget disabled (not pre-disabled) + // elements, so that they can be restored if the widget is re-enabled. + inputs = inputs.filter(':enabled') + .data(key, true) + } else { + inputs = inputs.filter(function() { + return $.data(this, key) === true; + }).removeData(key); + } + + inputs + .attr({ 'disabled':flag, 'arial-disabled':flag }) .parent()[ flag ? 'addClass' : 'removeClass' ]('ui-state-disabled'); this.element @@ -509,16 +531,17 @@ $.widget("ech.multiselect", { button = this.button, menu = this.menu, speed = this.speed, - o = this.options; + o = this.options, + args = []; // bail if the multiselectopen event returns false, this widget is disabled, or is already open if( this._trigger('beforeopen') === false || button.hasClass('ui-state-disabled') || this._isOpen ){ return; } - var $container = menu.find('ul:last'), + var $container = menu.find('ul').last(), effect = o.show, - pos = button.position(); + pos = button.offset(); // figure out opening effects/speeds if( $.isArray(o.show) ){ @@ -526,6 +549,12 @@ $.widget("ech.multiselect", { speed = o.show[1] || self.speed; } + // if there's an effect, assume jQuery UI is in use + // build the arguments to pass to show() + if( effect ) { + args = [ effect, speed ]; + } + // set the scroll of the checkbox container $container.scrollTop(0).height(o.height); @@ -536,17 +565,19 @@ $.widget("ech.multiselect", { menu .show() .position( o.position ) - .hide() - .show( effect, speed ); + .hide(); // if position utility is not available... } else { menu.css({ - top: pos.top+button.outerHeight(), + top: pos.top + button.outerHeight(), left: pos.left - }).show( effect, speed ); + }); } + // show the menu, maybe with a speed/effect combo + $.fn.show.apply(menu, args); + // select the first option // triggering both mouseover and mouseover because 1.4.2+ has a bug where triggering mouseover // will actually trigger mouseenter. the mouseenter trigger is there for when it's eventually fixed @@ -563,7 +594,10 @@ $.widget("ech.multiselect", { return; } - var o = this.options, effect = o.hide, speed = this.speed; + var o = this.options, + effect = o.hide, + speed = this.speed, + args = []; // figure out opening effects/speeds if( $.isArray(o.hide) ){ @@ -571,7 +605,11 @@ $.widget("ech.multiselect", { speed = o.hide[1] || this.speed; } - this.menu.hide(effect, speed); + if( effect ) { + args = [ effect, speed ]; + } + + $.fn.hide.apply(this.menu, args); this.button.removeClass('ui-state-active').trigger('blur').trigger('mouseleave'); this._isOpen = false; this._trigger('close'); @@ -618,6 +656,10 @@ $.widget("ech.multiselect", { return this.menu; }, + getButton: function(){ + return this.button; + }, + // react to option changes after initialization _setOption: function( key, value ){ var menu = this.menu; @@ -633,7 +675,7 @@ $.widget("ech.multiselect", { menu.find('a.ui-multiselect-none span').eq(-1).text(value); break; case 'height': - menu.find('ul:last').height( parseInt(value,10) ); + menu.find('ul').last().height( parseInt(value,10) ); break; case 'minWidth': this.options[ key ] = parseInt(value,10); @@ -649,6 +691,11 @@ $.widget("ech.multiselect", { case 'classes': menu.add(this.button).removeClass(this.options.classes).addClass(value); break; + case 'multiple': + menu.toggleClass('ui-multiselect-single', !value); + this.options.multiple = value; + this.element[0].multiple = value; + this.refresh(); } $.Widget.prototype._setOption.apply( this, arguments ); diff --git a/core/js/jquery.ocdialog.js b/core/js/jquery.ocdialog.js new file mode 100644 index 00000000000..7413927e3b2 --- /dev/null +++ b/core/js/jquery.ocdialog.js @@ -0,0 +1,217 @@ +(function($) { + $.widget('oc.ocdialog', { + options: { + width: 'auto', + height: 'auto', + closeButton: true, + closeOnEscape: true, + modal: false + }, + _create: function() { + var self = this; + + this.originalCss = { + display: this.element[0].style.display, + width: this.element[0].style.width, + height: this.element[0].style.height, + }; + + this.originalTitle = this.element.attr('title'); + this.options.title = this.options.title || this.originalTitle; + + this.$dialog = $('<div class="oc-dialog" />') + .attr({ + // Setting tabIndex makes the div focusable + tabIndex: -1, + role: 'dialog' + }) + .insertBefore(this.element); + this.$dialog.append(this.element.detach()); + this.element.removeAttr('title').addClass('oc-dialog-content').appendTo(this.$dialog); + + this.$dialog.css({ + display: 'inline-block', + position: 'fixed' + }); + + $(document).on('keydown keyup', function(event) { + if(event.target !== self.$dialog.get(0) && self.$dialog.find($(event.target)).length === 0) { + return; + } + // Escape + if(event.keyCode === 27 && self.options.closeOnEscape) { + self.close(); + return false; + } + // Enter + if(event.keyCode === 13) { + event.stopImmediatePropagation(); + if(event.type === 'keyup') { + event.preventDefault(); + return false; + } + // If no button is selected we trigger the primary + if(self.$buttonrow && self.$buttonrow.find($(event.target)).length === 0) { + var $button = self.$buttonrow.find('button.primary'); + if($button) { + $button.trigger('click'); + } + } else if(self.$buttonrow) { + $(event.target).trigger('click'); + } + return false; + } + }); + $(window).resize(function() { + self.parent = self.$dialog.parent().length > 0 ? self.$dialog.parent() : $('body'); + var pos = self.parent.position(); + self.$dialog.css({ + left: pos.left + (self.parent.width() - self.$dialog.outerWidth())/2, + top: pos.top + (self.parent.height() - self.$dialog.outerHeight())/2 + }); + }); + + this._setOptions(this.options); + $(window).trigger('resize'); + this._createOverlay(); + }, + _init: function() { + this.$dialog.focus(); + this._trigger('open'); + }, + _setOption: function(key, value) { + var self = this; + switch(key) { + case 'title': + var $title = $('<h3 class="oc-dialog-title">' + this.options.title + + '</h3>'); //<hr class="oc-dialog-separator" />'); + if(this.$title) { + this.$title.replaceWith($title); + } else { + this.$title = $title.prependTo(this.$dialog); + } + this._setSizes(); + break; + case 'buttons': + var $buttonrow = $('<div class="oc-dialog-buttonrow" />'); + if(this.$buttonrow) { + this.$buttonrow.replaceWith($buttonrow); + } else { + this.$buttonrow = $buttonrow.appendTo(this.$dialog); + } + $.each(value, function(idx, val) { + var $button = $('<button>').text(val.text); + if(val.defaultButton) { + $button.addClass('primary'); + self.$defaultButton = $button; + } + self.$buttonrow.append($button); + $button.click(function() { + val.click.apply(self.element[0], arguments); + }); + }); + this.$buttonrow.find('button') + .on('focus', function(event) { + self.$buttonrow.find('button').removeClass('primary'); + $(this).addClass('primary'); + }); + this._setSizes(); + break; + case 'closeButton': + if(value) { + var $closeButton = $('<a class="oc-dialog-close svg"></a>'); + this.$dialog.prepend($closeButton); + $closeButton.on('click', function() { + self.close(); + }); + } + break; + case 'width': + this.$dialog.css('width', value); + break; + case 'height': + this.$dialog.css('height', value); + break; + case 'close': + this.closeCB = value; + break; + } + //this._super(key, value); + $.Widget.prototype._setOption.apply(this, arguments ); + }, + _setOptions: function(options) { + //this._super(options); + $.Widget.prototype._setOptions.apply(this, arguments); + }, + _setSizes: function() { + var content_height = this.$dialog.height(); + if(this.$title) { + content_height -= this.$title.outerHeight(true); + } + if(this.$buttonrow) { + content_height -= this.$buttonrow.outerHeight(true); + } + this.parent = this.$dialog.parent().length > 0 ? this.$dialog.parent() : $('body'); + content_height = Math.min(content_height, this.parent.height()-20) + this.element.css({ + height: content_height + 'px', + width: this.$dialog.innerWidth()-20 + 'px' + }); + }, + _createOverlay: function() { + if(!this.options.modal) { + return; + } + + var self = this; + this.overlay = $('<div>') + .addClass('oc-dialog-dim') + .appendTo($('#content')); + this.overlay.on('click keydown keyup', function(event) { + if(event.target !== self.$dialog.get(0) && self.$dialog.find($(event.target)).length === 0) { + event.preventDefault(); + event.stopPropagation(); + return; + } + }); + }, + _destroyOverlay: function() { + if (!this.options.modal) { + return; + } + + if (this.overlay) { + this.overlay.off('click keydown keyup'); + this.overlay.remove(); + this.overlay = null; + } + }, + widget: function() { + return this.$dialog + }, + close: function() { + this._destroyOverlay(); + var self = this; + // Ugly hack to catch remaining keyup events. + setTimeout(function() { + self._trigger('close', self); + self.$dialog.hide(); + }, 200); + }, + destroy: function() { + if(this.$title) { + this.$title.remove() + } + if(this.$buttonrow) { + this.$buttonrow.remove() + } + + if(this.originalTitle) { + this.element.attr('title', this.originalTitle); + } + this.element.removeClass('oc-dialog-content') + .css(this.originalCss).detach().insertBefore(this.$dialog); + this.$dialog.remove(); + } + }); +}(jQuery)); diff --git a/core/js/js.js b/core/js/js.js index 3cb4d3dd151..5158b66d73a 100644 --- a/core/js/js.js +++ b/core/js/js.js @@ -7,7 +7,10 @@ */ var oc_debug; var oc_webroot; -var oc_requesttoken; + +var oc_current_user = document.getElementsByTagName('head')[0].getAttribute('data-user'); +var oc_requesttoken = document.getElementsByTagName('head')[0].getAttribute('data-requesttoken'); + if (typeof oc_webroot === "undefined") { oc_webroot = location.pathname.substr(0, location.pathname.lastIndexOf('/')); } @@ -223,8 +226,12 @@ var OC={ var path=OC.filePath(app,'css',style+'.css'); if(OC.addStyle.loaded.indexOf(path)===-1){ OC.addStyle.loaded.push(path); - style=$('<link rel="stylesheet" type="text/css" href="'+path+'"/>'); - $('head').append(style); + if (document.createStyleSheet) { + document.createStyleSheet(path); + } else { + style=$('<link rel="stylesheet" type="text/css" href="'+path+'"/>'); + $('head').append(style); + } } }, basename: function(path) { @@ -349,10 +356,10 @@ OC.Notification={ }, show: function(text) { if(($('#notification').filter('span.undo').length == 1) || OC.Notification.isHidden()){ - $('#notification').html(text); + $('#notification').text(text); $('#notification').fadeIn().css("display","inline"); }else{ - OC.Notification.queuedNotifications.push($(text).html()); + OC.Notification.queuedNotifications.push($('<div/>').text(text).html()); } }, isHidden: function() { diff --git a/core/js/multiselect.js b/core/js/multiselect.js index 463c397d8cd..48d521e1856 100644 --- a/core/js/multiselect.js +++ b/core/js/multiselect.js @@ -176,10 +176,10 @@ }); button.parent().data('preventHide',false); if(settings.createText){ - var li=$('<li class="creator">+ <em>'+settings.createText+'<em></li>'); + var li=$('<li class="creator">+ '+settings.createText+'</li>'); li.click(function(event){ li.empty(); - var input=$('<input class="new">'); + var input=$('<input type="text" class="new">'); li.append(input); input.focus(); input.css('width',button.innerWidth()); diff --git a/core/js/oc-dialogs.js b/core/js/oc-dialogs.js index e1d3657724e..f4bc174b5eb 100644 --- a/core/js/oc-dialogs.js +++ b/core/js/oc-dialogs.js @@ -72,7 +72,7 @@ var OCdialogs = { var dialog_name = 'oc-dialog-filepicker-content'; var dialog_id = '#' + dialog_name; if(self.$filePicker) { - self.$filePicker.dialog('close'); + self.$filePicker.ocdialog('close'); } self.$filePicker = $tmpl.octemplate({ dialog_name: dialog_name, @@ -110,26 +110,29 @@ var OCdialogs = { datapath += '/' + self.$filelist.find('.filepicker_element_selected .filename').text(); } callback(datapath); - self.$filePicker.dialog('close'); + self.$filePicker.ocdialog('close'); } }; var buttonlist = [{ text: t('core', 'Choose'), - click: functionToCall + click: functionToCall, + defaultButton: true }, { text: t('core', 'Cancel'), - click: function(){self.$filePicker.dialog('close'); } + click: function(){self.$filePicker.ocdialog('close'); } }]; - self.$filePicker.dialog({ + self.$filePicker.ocdialog({ closeOnEscape: true, width: (4/9)*$(document).width(), height: 420, modal: modal, buttons: buttonlist, close: function(event, ui) { - self.$filePicker.dialog('destroy').remove(); + try { + $(this).ocdialog('destroy').remove(); + } catch(e) {} self.$filePicker = null; } }); @@ -161,30 +164,32 @@ var OCdialogs = { text: t('core', 'Yes'), click: function(){ if (callback !== undefined) { callback(true) }; - $(dialog_id).dialog('close'); - } + $(dialog_id).ocdialog('close'); + }, + defaultButton: true }, { text: t('core', 'No'), click: function(){ if (callback !== undefined) { callback(false) }; - $(dialog_id).dialog('close'); + $(dialog_id).ocdialog('close'); } }]; break; case OCdialogs.OK_BUTTON: var functionToCall = function() { - $(dialog_id).dialog('close'); + $(dialog_id).ocdialog('close'); if(callback !== undefined) { callback() }; }; buttonlist[0] = { text: t('core', 'Ok'), - click: functionToCall + click: functionToCall, + defaultButton: true }; break; }; - $(dialog_id).dialog({ + $(dialog_id).ocdialog({ closeOnEscape: true, modal: modal, buttons: buttonlist diff --git a/core/js/octemplate.js b/core/js/octemplate.js index e032506c0b1..e69c6cc56e0 100644 --- a/core/js/octemplate.js +++ b/core/js/octemplate.js @@ -60,11 +60,11 @@ var self = this; if(typeof this.options.escapeFunction === 'function') { - $.each(this.vars, function(key, val) { - if(typeof val === 'string') { - self.vars[key] = self.options.escapeFunction(val); + for (var key = 0; key < this.vars.length; key++) { + if(typeof this.vars[key] === 'string') { + this.vars[key] = self.options.escapeFunction(this.vars[key]); } - }); + } } var _html = this._build(this.vars); diff --git a/core/js/share.js b/core/js/share.js index 36e4babedf9..21e352ee1c6 100644 --- a/core/js/share.js +++ b/core/js/share.js @@ -149,13 +149,26 @@ OC.Share={ var html = '<div id="dropdown" class="drop" data-item-type="'+itemType+'" data-item-source="'+itemSource+'">'; if (data !== false && data.reshare !== false && data.reshare.uid_owner !== undefined) { if (data.reshare.share_type == OC.Share.SHARE_TYPE_GROUP) { - html += '<span class="reshare">'+t('core', 'Shared with you and the group {group} by {owner}', {group: data.reshare.share_with, owner: data.reshare.displayname_owner})+'</span>'; + html += '<span class="reshare">'+t('core', 'Shared with you and the group {group} by {owner}', {group: escapeHTML(data.reshare.share_with), owner: escapeHTML(data.reshare.displayname_owner)})+'</span>'; } else { - html += '<span class="reshare">'+t('core', 'Shared with you by {owner}', {owner: data.reshare.displayname_owner})+'</span>'; + html += '<span class="reshare">'+t('core', 'Shared with you by {owner}', {owner: escapeHTML(data.reshare.displayname_owner)})+'</span>'; } html += '<br />'; } if (possiblePermissions & OC.PERMISSION_SHARE) { + // Determine the Allow Public Upload status. + // Used later on to determine if the + // respective checkbox should be checked or + // not. + + var allowPublicUploadStatus = false; + $.each(data.shares, function(key, value) { + if (allowPublicUploadStatus) { + return true; + } + allowPublicUploadStatus = (value.permissions & OC.PERMISSION_CREATE) ? true : false; + }); + html += '<input id="shareWith" type="text" placeholder="'+t('core', 'Share with')+'" />'; html += '<ul id="shareWithList">'; html += '</ul>'; @@ -168,12 +181,18 @@ OC.Share={ html += '<div id="linkPass">'; html += '<input id="linkPassText" type="password" placeholder="'+t('core', 'Password')+'" />'; html += '</div>'; - html += '</div>'; - html += '<form id="emailPrivateLink" >'; + if (itemType === 'folder' && (possiblePermissions & OC.PERMISSION_CREATE)) { + html += '<div id="allowPublicUploadWrapper" style="display:none;">'; + html += '<input type="checkbox" value="1" name="allowPublicUpload" id="sharingDialogAllowPublicUpload"' + ((allowPublicUploadStatus) ? 'checked="checked"' : '') + ' />'; + html += '<label for="sharingDialogAllowPublicUpload">' + t('core', 'Allow Public Upload') + '</label>'; + html += '</div>'; + } + html += '</div><form id="emailPrivateLink" >'; html += '<input id="email" style="display:none; width:62%;" value="" placeholder="'+t('core', 'Email link to person')+'" type="text" />'; html += '<input id="emailButton" style="display:none;" type="submit" value="'+t('core', 'Send')+'" />'; html += '</form>'; } + html += '<div id="expiration">'; html += '<input type="checkbox" name="expirationCheckbox" id="expirationCheckbox" value="1" /><label for="expirationCheckbox">'+t('core', 'Set expiration date')+'</label>'; html += '<input id="expirationDate" type="text" placeholder="'+t('core', 'Expiration date')+'" style="display:none; width:90%;" />'; @@ -370,6 +389,7 @@ OC.Share={ $('#expiration').show(); $('#emailPrivateLink #email').show(); $('#emailPrivateLink #emailButton').show(); + $('#allowPublicUploadWrapper').show(); }, hideLink:function() { $('#linkText').hide('blind'); @@ -378,6 +398,7 @@ OC.Share={ $('#linkPass').hide(); $('#emailPrivateLink #email').hide(); $('#emailPrivateLink #emailButton').hide(); + $('#allowPublicUploadWrapper').hide(); }, dirname:function(path) { return path.replace(/\\/g,'/').replace(/\/[^\/]*$/, ''); @@ -543,6 +564,28 @@ $(document).ready(function() { $(this).select(); }); + // Handle the Allow Public Upload Checkbox + $(document).on('click', '#sharingDialogAllowPublicUpload', function() { + + // Gather data + var allowPublicUpload = $(this).is(':checked'); + var itemType = $('#dropdown').data('item-type'); + var itemSource = $('#dropdown').data('item-source'); + var permissions = 0; + + // Calculate permissions + if (allowPublicUpload) { + permissions = OC.PERMISSION_UPDATE + OC.PERMISSION_CREATE + OC.PERMISSION_READ; + } else { + permissions = OC.PERMISSION_READ; + } + + // Update the share information + OC.Share.share(itemType, itemSource, OC.Share.SHARE_TYPE_LINK, '', permissions, function(data) { + return; + }); + }); + $(document).on('click', '#dropdown #showPassword', function() { $('#linkPass').toggle('blind'); if (!$('#showPassword').is(':checked') ) { diff --git a/core/js/update.js b/core/js/update.js index 8ab02bbf935..2c28e72f7cd 100644 --- a/core/js/update.js +++ b/core/js/update.js @@ -5,6 +5,9 @@ $(document).ready(function () { }); updateEventSource.listen('error', function(message) { $('<span>').addClass('error').append(message).append('<br />').appendTo($('.update')); + message = 'Please reload the page.'; + $('<span>').addClass('error').append(message).append('<br />').appendTo($('.update')); + updateEventSource.close(); }); updateEventSource.listen('failure', function(message) { $('<span>').addClass('error').append(message).append('<br />').appendTo($('.update')); @@ -20,4 +23,4 @@ $(document).ready(function () { window.location.href = OC.webroot; }, 3000); }); -});
\ No newline at end of file +}); |