## $Id: resources.py 7713 2012-02-28 10:14:55Z uli $
##
## Copyright (C) 2011 Uli Fouquet & Henrik Bettermann
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program; if not, write to the Free Software
## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
##
"""Special JavaScript and CSS resources provided by waeup.sirp.
"""
#from hurry import yui
from hurry.resource import Library, ResourceInclusion
from hurry.jqueryui import jqueryui, base, blitzer, ui_lightness, humanity
from hurry.jquery import jquery


#: All local resources are registered under the name ``waeup_sirp``.
waeup_sirp = Library('waeup_sirp', 'static')

#: A resource that binds a jQueryUI datepicker widget to each
#: <div> or <input> tag with class ``datepicker``.
#: If you want to let a JavaScript datepicker appear when
#: clicking into some input field, then you have to perform
#: two steps:
#:
#: * In the `update()` method of the responsible view/page/form
#:   require the JavaScript code to be rendered into the page::
#:
#:     from waeup.sirp.browser.resources import datepicker
#:     # ...
#:     class MyPage(...):
#:       # ...
#:       def update(self):
#:         datepicker.need()
#:
#:   This way all required JavaScripts will be rendered correctly
#:   into the HTML page generated.
#:
#: * In your HTML code add some ``<input>`` or ``<div>`` tag with
#:   ``class`` set to ``datepicker``, like this:
#:
#:   .. code-block:: html
#:
#:     <input type="text" name="entrydate" class="datepicker" />
#:
#: When the HTML is rendered, clicking into the field will open
#: a datepicker widget. The datepicker functionality will be
#: delivered by jQueryUI for every ``<div>/<input>`` field with class
#: ``datepicker`` set.
#:
#: That means, you can also have several date input fields on a
#: single page as long as each one has class ``datepicker``.
#:
#: Furthermore :func:`datepicker` supports different kinds of date
#: representation from which you can choose simply by setting a
#: different CSS class. The ``datepicker`` CSS mentioned above is
#: only one of the following possibilities:
#:
#: ``"datepicker"``
#:    renders date in format ``YYYY-MM-DD`` (ISO standard)
#:
#: ``"datepicker-year"``
#:    same but also adds a select field for year
#:
#: ``"datepicker-le"``
#:    renders date in format ``DD/MM/YYYY`` (little endian)
#:
#: ``"datepicker-le-year"``
#:    same but also adds a select field for year
#:
#: ``"datepicker-de"``
#:    renders date in format ``DD.MM.YYYY`` (german format)
#:
#: ``"datepicker-de-year"``
#:    same but also adds a select field for year
#:
#: ``"datepicker-us"``
#:    renders date in format ``MM/DD/YYYY`` (U.S. format)
#:
#: ``"datepicker-us-year"``
#:    same but also adds a select field for year
datepicker = ResourceInclusion(waeup_sirp, 'datepicker.js',
                               depends=[jqueryui])


#: If you want generate alert or confirm messages then you have to perform
#: two steps:
#:
#: * In the `update()` method of the responsible view/page/form
#:   require the JavaScript code to be rendered into the page::
#:
#:     from waeup.sirp.browser.resources import warning
#:     # ...
#:     class MyPage(...):
#:       # ...
#:       def update(self):
#:         warning.need()
#:
#:   This way all required JavaScripts will be rendered correctly
#:   into the HTML page generated.
#:
#:   In your HTML code add some <input> or <a> tag with onClick event:
#:
#:   .. code-block:: html
#:
#:        <input type="submit" name="xyz" value="abc">
#:               onclick="return confirmPost('Are you sure?')"/>
warning = ResourceInclusion(waeup_sirp, 'warning.js')

#: If you have many select boxes in a from which have to be selected at the same
#: time you have to perform two steps:
#:
#: * In the `update()` method of the responsible view/page/form
#:   require the JavaScript code to be rendered into the page::
#:
#:     from waeup.sirp.browser.resources import toggleall
#:     # ...
#:     class MyPage(...):
#:       # ...
#:       def update(self):
#:         toggleall.need()
#:
#:   This way all required JavaScripts will be rendered correctly
#:   into the HTML page generated.
#:
#:   In your HTML code add some <input> tag with onClick event:
#:
#:   .. code-block:: html
#:
#:    <input type="checkbox" onClick="toggle(this, 'entries')" />
toggleall = ResourceInclusion(waeup_sirp, 'toggleall.js')

#: A resource that binds Bootstrap tabs to <div> tags with class
#: ``tabs``.
#:
#: If you want Bootstrap tabs in your page then you
#: have to perform two steps:
#:
#: * In the `update()` method of the responsible view/page/form
#:   require the JavaScript code to be rendered into the page and set
#:   tab for redirection::
#:
#:     from waeup.sirp.browser.resources import tabs
#:
#:     class MyPage(...):
#:
#:       def update(self):
#:         tabs.need()
#:         self.tab1 = self.tab2 = self.tab3 = ''
#:         qs = self.request.get('QUERY_STRING', '')
#:         if not qs:
#:           qs = 'tab1'
#:         setattr(self, qs, 'active')
#:
#:   This way all required JavaScripts will be rendered correctly
#:   into the HTML page generated.
#:
#: * In your HTML code add some tags with like this:
#:
#:    .. code-block:: html
#:
#:     <ul class="tabs" data-tabs="tabs" >
#:       <li tal:attributes="class view/tab1"><a href="#tab-1">Tab 1 Heading</a></li>
#:       <li tal:attributes="class view/tab2"><a href="#tab-2">Tab 2 Heading</a></li>
#:       <li tal:attributes="class view/tab3"><a href="#tab-3">Tab 3 Heading</a></li>
#:     </ul>

#:     <div class="tab-content">
#:       <div id="tab-1" tal:attributes="class view/tab1">...</div>
#:       <div id="tab-2" tal:attributes="class view/tab2">...</div>
#:       <div id="tab-3" tal:attributes="class view/tab3">...</div>
#:     </div>
#:
#: When the HTML is rendered, clicking into one of the tabs will make
#: other <div>s disappear. See
#:
#:   http://twitter.github.com/bootstrap/javascript.html#tabs
#:
#: for details.
#:
tabs = ResourceInclusion(waeup_sirp, 'bootstrap-tabs-1.4.0.js',
                          depends=[jquery])


#: Resource that makes datatables for jQuery UI available.
#:
#: We register a normal version and a minified version. To make real
#: use of datatables you might want to add some specialized CSS like
#: `datatable_css` below.
from js.jquery_datatables import jquery_datatables as datatables
from fanstatic import Library, Resource
waeup_kofa = Library('waeup_kofa', 'static')
#datatables = ResourceInclusion(waeup_sirp, 'jquery.dataTables.js',
#                               minified='jquery.dataTables.min.js',
#                               depends=[jquery])

#: A stylesheet for datatables
#datatables_css = ResourceInclusion(waeup_sirp, 'datatables.css')
datatables_css = Resource(waeup_kofa, 'datatables.css')

#: A resource that turns HTML tables into sortable, searchable and :
#: multi-page widgets using jQuery and the dataTables plugin available
#: from http://www.datatables.net.
#:
#: If you want jQuery datatables for some <table> in your page then you
#: have to perform two steps:
#:
#: * In the `update()` method of the responsible view/page/form
#:   require the JavaScript code to be rendered into the page::
#:
#:     from waeup.sirp.browser.resources import datatable
#:     # ...
#:     class MyPage(...):
#:       # ...
#:       def update(self):
#:         datatable.need()
#:
#:   This way all required JavaScripts will be rendered correctly
#:   into the HTML page generated.
#:
#: * Assign a ``display dataTable`` class to the HTML table you want to tune:
#:
#:   .. code-block:: html
#:
#:      <table class="display dataTable">
#:        <thead>
#:          <tr>
#:            <th>Name</th><th>Title</th>
#:          </tr>
#:        </thead>
#:        <tbody>
#:          <tr class="gradeA">
#: 	      <td>Manfred</td><td>Mammoth of the year</td>
#:          </tr>
#:          <tr class="gradeA">
#: 	      <td>Wolfgang</td><td>Junior</td>
#:          </tr>
#:        </tbody>
#:      </table>
#:
#: When the HTML is rendered, clicking into one of the tabs will make
#: other <div>s disappear. See
#:
#:   http://www.datatables.net/
#:
#: for details.
#:
#datatable = ResourceInclusion(waeup_sirp, 'datatable.js',
#                              depends=[datatables, datatables_css])
datatable = Resource(waeup_kofa, 'datatable.js',
                     depends=[datatables, datatables_css])

#: Register Twitter's Bootsrap css including dropdown js as a resource.
bootstrap_min = ResourceInclusion(
    waeup_sirp, 'bootstrap-1.4.0.css')

dropdown = ResourceInclusion(
    waeup_sirp, 'bootstrap-dropdown-1.4.0.js',
    depends=[jquery])

#: Register basic SIRP CSS (which is based on ``bootstrap.min-1.4.0.css`` 
#: and ``base`` as a resource.
waeup_base_css = ResourceInclusion(
    waeup_sirp, 'waeup-base.css',
    depends=[dropdown,bootstrap_min, base])

#: A basic theme based on jQuery only (crappy yet).
waeuptheme_empty = ResourceInclusion(
    waeup_sirp, 'empty.css',
    depends=[humanity])
