Browse Source

[MIG]Migrated web_widget_slick in v11.

pull/958/head
Meet 6 years ago
parent
commit
88115f6ea6
  1. 115
      web_widget_slick/README.rst
  2. 1
      web_widget_slick/__init__.py
  3. 9
      web_widget_slick/__manifest__.py
  4. 3
      web_widget_slick/readme/CONTRIBUTORS.rst
  5. 1
      web_widget_slick/readme/DESCRIPTION.rst
  6. 1
      web_widget_slick/readme/ROADMAP.rst
  7. 53
      web_widget_slick/readme/USAGE.rst
  8. 74
      web_widget_slick/static/src/js/web_widget_slick.js
  9. 2
      web_widget_slick/static/src/xml/web_widget_slick.xml

115
web_widget_slick/README.rst

@ -1,114 +1,3 @@
.. image:: https://img.shields.io/badge/license-LGPL--3-blue.svg
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
:alt: License: LGPL-3
**This file is going to be generated by oca-gen-addon-readme.**
=====================
Slick Carousel Widget
=====================
This module provides a Slick Carousel widget for use in the Odoo backend web interface.
Usage
=====
Default usage is on a One2many attachment field, as defined below::
class SlickExample(models.Model):
_name = 'slick.example'
_description = 'Slick Example Model'
image_ids = fields.One2many(
name='Images',
comodel_name='ir.attachment',
inverse_name='res_id',
)
Assuming the above model, you would add a Slick Carousel on the
``image_ids`` column by using the following field definition in the
model's form view::
<field name="image_ids" widget="one2many_slick_images" options="{}"/>
Options
-------
The widget passes options directly through to Slick, so any `setting
available to Slick`_ is available to the widget. Additional options
specific to Odoo are:
+-----------------+--------------+---------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Name | Type | Default | Description |
+=================+==============+=====================+=============================================================================================================================================================================+
| ``fieldName`` | ``String`` | ``datas`` | Field to lookup on relation table. Defaults to ``datas``, which is the data field used in ``ir.attachment`` table. This would be used to define a custom attachment model |
+-----------------+--------------+---------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| ``modelName`` | ``String`` | ``ir.attachment`` | Model of attachment relation. This would be used to define a custom attachment model instead of default ``ir.attachment`` |
+-----------------+--------------+---------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
.. _setting available to Slick: http://kenwheeler.github.io/slick/#settings
Example Module
--------------
An example implementation, for instructional purposes as well as convenient
functional testing, is provided in the `web_widget_slick_example` module.
* Install `web_widget_slick_example`.
* Activate Developer Mode.
* Go to Settings / Technical / Slick, and open the record to view the widget.
To try out different Slick settings:
* Go to Settings/User Interface/Views and search for 'slick.example.view.form'.
* Open the form view record.
* Click the Edit button.
* In the Architecture editor, find `options="{'slidesToShow': 2}`, and add
any desired settings (separated by commas) inside the curly braces.
* Save the changes and browse to the widget, as described above, to see the
widget with the new settings in effect.
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/162/10.0
Known issues / Roadmap
======================
* Adding / Deleting images from a carousel is not currently supported.
Bug Tracker
===========
Bugs are tracked on `GitHub Issues
<https://github.com/OCA/web/issues>`_. In case of trouble, please
check there if your issue has already been reported. If you spotted it first,
help us smash it by providing detailed and welcomed feedback.
Credits
=======
Images
------
* Odoo Community Association: `Icon <https://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.svg>`_.
Contributors
------------
* Dave Lasley <dave@laslabs.com>
* Brent Hughes <brent.hughes@laslabs.com>
Do not contact contributors directly about support or help with technical issues.
Maintainer
----------
.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org
This module is maintained by the OCA.
OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.
To contribute to this module, please visit https://odoo-community.org.
This module provides a Slick Carousel widget for use in the Odoo backend web interface.

1
web_widget_slick/__init__.py

@ -1,3 +1,2 @@
# -*- coding: utf-8 -*-
# Copyright 2016-2017 LasLabs Inc.
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).

9
web_widget_slick/__manifest__.py

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2016-2017 LasLabs Inc.
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).
@ -6,13 +5,11 @@
"name": "Slick Carousel Widget",
"summary": "Adds SlickJS slider widget for use as a carousel on Many2one"
" attachment fields in backend form views.",
"version": "10.0.1.0.0",
"version": "11.0.1.0.0",
"category": "Web",
"website": "https://laslabs.com/",
"author": "LasLabs, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/web",
"author": "LasLabs, Meet Dholakia, Odoo Community Association (OCA)",
"license": "LGPL-3",
"application": False,
"installable": True,
"depends": [
"web",
],

3
web_widget_slick/readme/CONTRIBUTORS.rst

@ -0,0 +1,3 @@
* Dave Lasley <dave@laslabs.com>
* Brent Hughes <brent.hughes@laslabs.com>
* Meet Dholakia <meetcomputer009@gmail.com>

1
web_widget_slick/readme/DESCRIPTION.rst

@ -0,0 +1 @@
This module provides a Slick Carousel widget for use in the Odoo backend web interface.

1
web_widget_slick/readme/ROADMAP.rst

@ -0,0 +1 @@
* Adding / Deleting images from a carousel is not currently supported.

53
web_widget_slick/readme/USAGE.rst

@ -0,0 +1,53 @@
Default usage is on a One2many attachment field, as defined below::
class SlickExample(models.Model):
_name = 'slick.example'
_description = 'Slick Example Model'
image_ids = fields.One2many(
name='Images',
comodel_name='ir.attachment',
inverse_name='res_id',
)
Assuming the above model, you would add a Slick Carousel on the
``image_ids`` column by using the following field definition in the
model's form view::
<field name="image_ids" widget="one2many_slick_images" options="{}"/>
Options
-------
The widget passes options directly through to Slick, so any `setting
available to Slick`_ is available to the widget. Additional options
specific to Odoo are:
+-----------------+--------------+---------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Name | Type | Default | Description |
+=================+==============+=====================+=============================================================================================================================================================================+
| ``fieldName`` | ``String`` | ``datas`` | Field to lookup on relation table. Defaults to ``datas``, which is the data field used in ``ir.attachment`` table. This would be used to define a custom attachment model |
+-----------------+--------------+---------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| ``modelName`` | ``String`` | ``ir.attachment`` | Model of attachment relation. This would be used to define a custom attachment model instead of default ``ir.attachment`` |
+-----------------+--------------+---------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
.. _setting available to Slick: http://kenwheeler.github.io/slick/#settings
Example Module
--------------
An example implementation, for instructional purposes as well as convenient
functional testing, is provided in the `web_widget_slick_example` module.
* Install `web_widget_slick_example`.
* Activate Developer Mode.
* Go to Settings / Technical / Slick, and open the record to view the widget.
To try out different Slick settings:
* Go to Settings/User Interface/Views and search for 'slick.example.view.form'.
* Open the form view record.
* Click the Edit button.
* In the Architecture editor, find `options="{'slidesToShow': 2}`, and add
any desired settings (separated by commas) inside the curly braces.
* Save the changes and browse to the widget, as described above, to see the
widget with the new settings in effect.

74
web_widget_slick/static/src/js/web_widget_slick.js

@ -2,14 +2,16 @@
* License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). */
odoo.define('web_widget_slick', function(require) {
"use strict";
"use strict";
var core = require('web.core');
var relational_fields = require('web.relational_fields');
var registry = require('web.field_registry');
var core = require('web.core');
var AbstractManyField = require('web.form_relational').AbstractManyField;
var FieldOne2Many = relational_fields.FieldOne2Many;
var FieldSlickImages = AbstractManyField.extend({
var FieldSlickImages = FieldOne2Many.extend({
widget_class: 'o_slick',
className: 'o_slick',
template: 'FieldSlickImages',
$slick: null,
no_rerender: true,
@ -62,39 +64,36 @@ odoo.define('web_widget_slick', function(require) {
]
},
init: function(field_manager, node) {
this._super(field_manager, node);
this.options = _.defaults(this.options, this.defaults);
init: function (parent, name, record, options) {
this._super.apply(this, arguments);
this.nodeOptions = _.defaults(this.nodeOptions, this.defaults);
},
destroy_content: function() {
if (this.$slick) {
var $imgs = this.$el.find('img');
// Unslicking removes the carousel but re-appends any images,
// so removal of images is also required
$imgs.each($.proxy(this._slickRemove, this));
this.$slick.slick('unslick');
}
destroy: function () {
if (this.$slick) {
var $imgs = this.$el.find('img');
// Unslicking removes the carousel but re-appends any images,
// so removal of images is also required
$imgs.each($.proxy(this._slickRemove, this));
this.$slick.slick('unslick');
}
this._super.apply(this, arguments);
},
render_value: function() {
this._super();
this.destroy_content();
this.$el.parent('td').addClass('o_slick_cell');
this.$slick = $('<div class="slick-container"></div>');
if (this.options.arrows) {
this.$slick.addClass('slick-arrowed');
}
this.$el.append(this.$slick);
var baseUrl = '/web/image/' + this.options.modelName + '/';
var value = this.get('value');
this.loading.push.apply(value);
_.each(value, $.proxy(this._slickRender, this, [baseUrl]));
this.$slick.slick(this.options);
core.bus.on('resize', this, this._resizeCarousel);
_render: function () {
this._super();
this.$el.empty()
this.$slick = $('<div class="slick-container"></div>');
if (this.nodeOptions.arrows) {
this.$slick.addClass('slick-arrowed');
}
this.$el.append(this.$slick);
var baseUrl = '/web/image/' + this.nodeOptions.modelName + '/';
var value = this.value.res_ids;
this.loading.push.apply(value);
_.each(value, $.proxy(this._slickRender, this, [baseUrl]));
this.$slick.slick(this.nodeOptions);
core.bus.on('resize', this, this._resizeCarousel);
},
_resizeCarousel: function () {
@ -158,15 +157,16 @@ odoo.define('web_widget_slick', function(require) {
_slickRender: function (baseUrl, id) {
var $img = $('<img class="img img-responsive"></img>');
var $div = $('<div></div>');
$img.attr('data-lazy', baseUrl + id + '/' + this.options.fieldName);
$img.attr('data-lazy', baseUrl + id + '/' + this.nodeOptions.fieldName);
$div.append($img);
this.$slick.append($div);
}
});
core.form_widget_registry.add("one2many_slick_images", FieldSlickImages);
registry
.add('one2many_slick_images', FieldSlickImages);
return {FieldSlickImages: FieldSlickImages};
return {FieldSlickImages: FieldSlickImages};
});

2
web_widget_slick/static/src/xml/web_widget_slick.xml

@ -4,6 +4,6 @@
<template>
<t t-name="FieldSlickImages">
<div t-attf-class="o_form_field {{ widget.widget_class }}"></div>
<div t-attf-class="o_form_field {{ widget.className}}"></div>
</t>
</template>
Loading…
Cancel
Save