Button Widget fixes + minor JS fixes.

This commit is contained in:
buddh4 2017-07-02 23:01:04 +02:00
parent dedef3a9f9
commit 472e453e46
7 changed files with 85 additions and 17 deletions

View File

@ -6,6 +6,7 @@ HumHub Change Log
- Fix #2644 overlapping popup preview image after increasing preview image size (hagalaz)
- Fix: Button widget child class static instantiation not working
- Fix: ModalButton instatiation and added ModalButton::close()
- Fix: Respect `max_file_uploads` setting in UploadInput widget
1.2.1 (June 17, 2017)
- Fix: Invite error in french language

View File

@ -52,7 +52,7 @@ class Button extends Widget
public static function instance($text = null)
{
return new static(['text' => $text]);
return new static(['type' => self::TYPE_NONE, 'text' => $text]);
}
public static function back($url, $text = null)
@ -70,11 +70,25 @@ class Button extends Widget
return new static(['type' => self::TYPE_NONE, 'text' => $text]);
}
public static function asLink($text = null, $href = '#')
{
return self::none($text)->link($href);
}
public static function primary($text = null)
{
return new static(['type' => self::TYPE_PRIMARY, 'text' => $text]);
}
public static function save($text = null)
{
if(!$text) {
$text = Yii::t('base', 'Save');
}
return self::primary($text);
}
public static function defaultType($text = null)
{
return new static(['type' => self::TYPE_DEFAULT, 'text' => $text]);
@ -113,6 +127,11 @@ class Button extends Widget
return $this;
}
public function setText($text)
{
$this->text = $text;
}
public function right($right = true)
{
if($right) {
@ -181,6 +200,10 @@ class Button extends Widget
public function options($options)
{
if(isset($options['class'])) {
Html::addCssClass($this->htmlOptions, $options['class']);
unset($options['class']);
}
$this->htmlOptions = ArrayHelper::merge($this->htmlOptions, $options);
return $this;
}

View File

@ -29,7 +29,8 @@ use yii\helpers\Url;
class Link extends Button
{
public $link = true;
public $_link = true;
public function to($url)
{

View File

@ -18,6 +18,7 @@ namespace humhub\widgets;
use humhub\components\Widget;
use humhub\libs\Html;
use Yii;
use yii\helpers\ArrayHelper;
use yii\helpers\Url;
@ -32,7 +33,6 @@ class ModalButton extends Button
{
public function init()
{
$this->action('ui.modal.load');
parent::init(); // TODO: Change the autogenerated stub
}
@ -42,9 +42,23 @@ class ModalButton extends Button
return $this;
}
public function close()
public static function close($text = null)
{
$this->options(['data-modal-close' => '']);
return static::cancel($text);
}
public static function cancel($text = null)
{
if(!$text) {
$text = Yii::t('base', 'Cancel');
}
return static::defaultType($text)->options(['data-modal-close' => '']);
}
public static function submitModal($url = null, $text = null)
{
return parent::save($text)->submit()->action('ui.modal.submit', $url);
}
public function post($url)

View File

@ -99,7 +99,15 @@ humhub.module('client', function (module, require, $) {
cfg.type = $form.attr('method') || 'post';
cfg.data = $form.serialize();
var url = cfg.url || originalEvent.url || $form.attr('action');
var url = cfg.url;
if(!url && (originalEvent && originalEvent.url)) {
url = originalEvent.url;
} else if(!url && $form) {
url = $form.attr('action');
}
return ajax(url, cfg, originalEvent);
};

View File

@ -114,17 +114,15 @@ humhub.module('ui.loader', function (module, require, $) {
}
}
$skBounce = $result.find('.sk-bounce1, .sk-bounce2, .sk-bounce3');
if (cfg['itemCss']) {
$result.find('.sk-bounce1').css(cfg['itemCss']);
$result.find('.sk-bounce2').css(cfg['itemCss']);
$result.find('.sk-bounce3').css(cfg['itemCss']);
$skBounce.css(cfg['itemCss']);
}
if (cfg['size']) {
var size = cfg['size'];
$result.find('.sk-bounce1').css({'width': size, 'height': size});
$result.find('.sk-bounce2').css({'width': size, 'height': size});
$result.find('.sk-bounce3').css({'width': size, 'height': size});
$skBounce.css({'width': size, 'height': size});
}
if (cfg['wrapper']) {

View File

@ -600,16 +600,27 @@ humhub.module('ui.modal', function (module, require, $) {
evt.$form = evt.$target;
}
var id = evt.$trigger.data('modal-id');
if (!id) {
// try to autodetect modal id if we're currently in a modal
var $parent = evt.$trigger.closest('.modal');
if ($parent.length) {
id = $parent.attr('id');
}
}
var modal = (id) ? module.get(id) : module.global;
return client.submit(evt, _defaultRequestOptions(evt, options)).then(function (response) {
module.global.setDialog(response);
if (!module.global.$.is(':visible')) {
module.global.show();
modal.setDialog(response);
if (!modal.$.is(':visible')) {
modal.show();
}
module.global.$.trigger('submitted');
modal.$.trigger('submitted');
return response;
}).catch(function (error) {
module.log.error(error, true);
modal.close();
});
};
@ -626,12 +637,24 @@ humhub.module('ui.modal', function (module, require, $) {
var modal = (id) ? module.get(id) : module.global;
return modal.load(evt, _defaultRequestOptions(evt, options)).catch(function (err) {
module.log.error(err, true);
modal.close();
});
};
var post = function (evt, options) {
return module.global.post(evt, _defaultRequestOptions(evt, options)).catch(function (err) {
var id = evt.$trigger.data('modal-id');
if (!id) {
// try to autodetect modal id if we're currently in a modal
var $parent = evt.$trigger.closest('.modal');
if ($parent.length) {
id = $parent.attr('id');
}
}
var modal = (id) ? module.get(id) : module.global;
return modal.post(evt, _defaultRequestOptions(evt, options)).catch(function (err) {
module.log.error(err, true);
modal.close();
});
};