generic-cards-container-controllet.html 6.61 KB
<!--
@license
    The MIT License (MIT)

    Copyright (c) 2015 Dipartimento di Informatica - Università di Salerno - Italy

    Permission is hereby granted, free of charge, to any person obtaining a copy
    of this software and associated documentation files (the "Software"), to deal
    in the Software without restriction, including without limitation the rights
    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    copies of the Software, and to permit persons to whom the Software is
    furnished to do so, subject to the following conditions:

    The above copyright notice and this permission notice shall be included in
    all copies or substantial portions of the Software.

    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    THE SOFTWARE.
-->

<!--
* Developed by :
* ROUTE-TO-PA Project - grant No 645860. - www.routetopa.eu
*
-->

<link rel="import" href="../../bower_components/polymer/polymer.html">
<link rel="import" href="../../bower_components/paper-styles/color.html">

<link rel="import" href="../../bower_components/paper-material">
<link rel="import" href="../../bower_components/paper-icon-button/paper-icon-button.html">
<link rel="import" href="../../bower_components/iron-icons/iron-icons.html">
<link rel="import" href="../../bower_components/iron-flex-layout/iron-flex-layout.html">

<!--
 `items-slider-controllet` is a carousel of cards with a title and an image. Pass to it an array of objects with name and image fields and
 a responsive slider will be created. Every time the user click on a card an event will be generate in order to get the card clicked information to
 the component that use the slider.

Example:

    <items-slider-controllet items='[{name : "myObject1", image : "pathToMyImage1"},...,{name : "myObjectN", image : "pathToMyImageN"}]' \>
    </items-slider-controllet>


@element items-slider-controllet
@status beta
@homepage index.html
@group controllets
-->

<dom-module id="generic-cards-container-controllet">
    <template>

        <style is="custom-style">

            .legend span{
                position: relative;
                top: 8px;
            }

            .card_grid
            {
                width: 100%;
                z-index: 0;
                margin: auto;
                padding: 5%;
            }

            .card_grid:after {
                content: '';
                display: block;
                clear: both;
            }

            ::content .card{
                margin: 10px;
                float: left;
            }

            ::content .card_grid .fullscreen{
                display: none;
            }

            ::content .card_grid .delete{
                display: none;
            }

            ::content .card_grid .modify{
                display: none;
            }

            ::content .card_grid .open
            {
                display: none;
            }

            ::content .empty{
                position: absolute;
                right: 0;
                left: 27%;
                top: 40%;
                margin-right: auto;
                margin-left: auto;
                font-family: 'Roboto', sans-serif;
                font-weight: 500;
                font-size: large;
            }

        </style>

        <div id="container" class="layout vertical">
            <div class="card_grid" id="card_grid">
                <content></content>
            </div>
        </div>
    </template>

    <script>

        Polymer({

            is : 'generic-cards-container-controllet',

            /**
             * Fired when the user selects a card from slider by clicking on it.
             *
             * @event generic-cards-container-controllet_card-selected
             */
            properties : {
                prevSelectedCard : {
                    type: Object,
                    value : null
                },
                /**
                 * Presected card. You can pass the card title to preselect it.
                 */
                selectedCard:{
                    type: String,
                    value: undefined
                }
            },

            ready : function(){
                var _this = this;
                var cards = document.querySelectorAll('paper-card-controllet');

//                if(cards.length == 0){
//
//                   this.$.card_grid.innerHTML += "<div class='empty'>There is nothing to show.</div>";
//                }

                for(var i = 0; i < cards.length; i++){
                    cards[i].addEventListener('click', function(e){
                       _this._cardClick(e)
                    });
                }
            },

            _cardClick : function(e){

                if(this.prevSelectedCard != null){
                    this.prevSelectedCard.elevation = "1";

                }
                e.currentTarget.elevation = "5";
                this.prevSelectedCard = e.currentTarget;

                this.fire('generic-cards-container-controllet_card-selected', {selectedElement: e.currentTarget});
                this.fire('animated-button-container-controllet_close', {});

            },

            _handleSearch: function(e){
                if(e.detail.id == "search_from_animated_button_container") {
                    var cards = document.querySelectorAll('.card');
                    for (var i = 0; i < cards.length; i++) {
                        var title = cards[i].cardTitle;
                        var comment = cards[i].comment;
                        var type = cards[i].cardType;

                        var searchFlag = title.indexOf(e.detail.searchKey) == -1 && comment.indexOf(e.detail.searchKey) == -1 && type.indexOf(e.detail.searchKey) == -1;

                        if (!searchFlag || e.detail.searchKey == "") {
                            cards[i].style.display = "inline-block";
                        } else {
                            cards[i].style.display = "none";
                        }
                    }
                }
            }
        });

    </script>

</dom-module>