[ADD] added snippet for country event, script for finding coordinates from brwoser...
authorParth Gajjar (Open ERP) <pga@tinyerp.com>
Wed, 26 Feb 2014 11:31:21 +0000 (17:01 +0530)
committerParth Gajjar (Open ERP) <pga@tinyerp.com>
Wed, 26 Feb 2014 11:31:21 +0000 (17:01 +0530)
bzr revid: pga@tinyerp.com-20140226113121-vni0182v0cc2u3d4

addons/website/static/src/css/website.css
addons/website/static/src/css/website.sass
addons/website/static/src/img/blocks/block-country_events.png [new file with mode: 0644]
addons/website_event/controllers/main.py
addons/website_event/static/src/js/website_geolocation.js [new file with mode: 0644]
addons/website_event/views/website_event.xml

index e47b7a4..b386c3f 100644 (file)
@@ -529,3 +529,9 @@ span[data-oe-type="monetary"] {
   width: 400px;
   margin: 40px auto;
 }
+
+.oe_website_overflow_ellipsis{
+  white-space:nowrap;
+  overflow:hidden;
+  text-overflow:ellipsis;
+}
index 3cdfe37..9e69f85 100644 (file)
@@ -428,3 +428,9 @@ span[data-oe-type="monetary"]
 .oe_website_login_container
     width: 400px
     margin: 40px auto
+
+.oe_website_overflow_ellipsis
+    white-space:nowrap
+    overflow:hidden
+    text-overflow:ellipsis
+
diff --git a/addons/website/static/src/img/blocks/block-country_events.png b/addons/website/static/src/img/blocks/block-country_events.png
new file mode 100644 (file)
index 0000000..52254ba
Binary files /dev/null and b/addons/website/static/src/img/blocks/block-country_events.png differ
index 2a6e1d1..132fc14 100644 (file)
@@ -28,6 +28,7 @@ controllers = controllers()
 
 
 from datetime import datetime, timedelta
+import time
 from dateutil.relativedelta import relativedelta
 from openerp import tools
 import werkzeug.urls
@@ -215,3 +216,24 @@ class website_event(http.Controller):
         }
         event_id = Event.create(request.cr, request.uid, vals, context=context)
         return request.redirect("/event/%s/?enable_editor=1" % event_id)
+
+    @http.route('/event/get_country_event_list/<path:country_code>', type='http', auth='public', website=True)
+    def get_country_events(self,country_code ,**post):
+        cr, uid, context = request.cr, request.uid, request.context
+        event_obj = request.registry['event.event']
+        event_ids = event_obj.search(request.cr, request.uid, [('country_id.code', '=', country_code),('state', '=', 'confirm'),('date_begin','>=', time.strftime('%Y-%m-%d 00:00:00'))], order="date_begin", context=request.context)
+        events = event_obj.browse(request.cr, request.uid, event_ids, context=request.context)
+        country_obj = request.registry['res.country']
+        country_ids = country_obj.search(request.cr, request.uid, [('code', '=', country_code)], context=request.context)
+        country = country_obj.browse(request.cr, request.uid, country_ids[0], context=request.context)
+        result = {'events':[], 'country': country}
+        for event in events:
+            start_date = datetime.strptime(event.date_begin.split(' ')[0], "%Y-%m-%d")
+            end_date = datetime.strptime(event.date_end.split(' ')[0], "%Y-%m-%d")
+            if end_date == start_date:
+                result['events'].append({"date": start_date.strftime("%b")+" "+start_date.strftime("%e"), 
+                                         "event": event, 'url': event.website_url})
+            else:
+                result['events'].append({"date":start_date.strftime("%b")+" "+start_date.strftime("%e")+"-"+end_date.strftime("%e"),
+                                         "event": event, 'url': event.website_url})
+        return request.website.render("website_event.country_events_list",result)
diff --git a/addons/website_event/static/src/js/website_geolocation.js b/addons/website_event/static/src/js/website_geolocation.js
new file mode 100644 (file)
index 0000000..3d48b04
--- /dev/null
@@ -0,0 +1,40 @@
+(function() {
+    "use strict";
+    function getLocation()
+    {
+        if (navigator.geolocation)
+        {
+            navigator.geolocation.getCurrentPosition(showPosition);
+        }
+        else{alert("Geolocation is not supported by this browser.");}
+    }
+    
+    function showPosition(position)
+    {
+        var latitude = position.coords.latitude;
+        var longitude = position.coords.longitude;
+        $.ajax({
+            url:  "https://maps.googleapis.com/maps/api/geocode/json?latlng="+latitude+","+longitude+"&sensor=false",
+            type: 'GET',
+            dataType: 'json',
+            success: function(response, status, xhr, wfe){ 
+                if(response.status == 'OK'){
+                    var last_element = response.results[response.results.length - 1]
+                    if( last_element.types.indexOf( "country" ) != -1){
+                        var country_obj = last_element.address_components[0];
+                        $('img.event_country_flag').attr('src','base/static/img/country_flags/'+country_obj.short_name.toLowerCase()+'.png');
+                        $.post( "/event/get_country_event_list/"+country_obj.short_name, function( data ) {
+                            $( ".country_events_list" ).replaceWith( data );
+                        });
+                    }
+                }
+            }
+        });
+    }
+
+    $(document).ready(function () {
+        if($('.country_events').length){
+            getLocation();
+        }
+    });
+})();
\ No newline at end of file
index d002521..c2d2129 100644 (file)
         </div>
     </t>
 </template>
+
+<template id="event_script" name="Country Events Snippet Script" inherit_id="website.layout">
+    <xpath expr="//head" position="inside">
+        <script type="text/javascript" src="/website_event/static/src/js/website_geolocation.js"></script>
+    </xpath>
+</template>
+
+<template id="country_events" name="Country Events" inherit_id="website.snippets">
+    <xpath expr="//div[@id='snippet_feature']" position="inside">
+        <div data-snippet-id="country_events" data-selector-children=".oe_structure, [data-oe-type=html]" class="country_events"> 
+            <div class="oe_snippet_thumbnail">
+                <img class="oe_snippet_thumbnail_img" src="/website/static/src/img/blocks/block-country_events.png" />
+                <span class="oe_snippet_thumbnail_title">Country Events</span>
+            </div>
+            <section class="oe_snippet_body country_events">
+                <div class="container">
+                    <div class="row">
+                        <div class="col-md-3">
+                            <div class="country_events_list">
+                            <div class="text-muted text-center">
+                                <h1><i class="fa fa-map-marker fa-5x"></i></h1>
+                                <h3>Allow browser to use your Location.</h3>
+                            </div>
+                            </div>
+                        </div>
+                        <div class="col-md-5">
+                        </div>
+                        <div class="col-md-4">
+                        </div>
+                    </div>
+                </div>
+            </section>
+        </div>
+    </xpath>
+</template>
+
+<template id="country_events_list" name="Country">
+    <t t-ignore="true">
+        <div class="mb16 country_events_list">
+            <img class="img-rounded img-responsive" t-att-src="'/website/image?model=res.country&amp;field=image&amp;id='+str(country.id)"></img>
+            <t t-if="events">
+                <h4><b>Events In <span t-esc="country.name"></span></b></h4>
+                <div t-foreach="events[:5]" t-as="country_event" class="oe_website_overflow_ellipsis mb8">
+                    <t t-if="not country_event['event'].website_published">
+                        <span class="label label-danger"><i class="fa fa-ban"></i></span>
+                    </t>
+                    <i class="fa fa-calendar"></i> <b><span t-esc="country_event['date']"/>: <span><a t-att-href="country_event['url']"><t t-esc="country_event['event'].name"/></a></span></b>
+                </div>
+            </t>
+            <t t-if="len(events) > 5">
+                <b class="text-center"><a t-att-href="'/event/?country='+str(country.id)">All events for <span t-esc="country.name"></span></a></b>
+            </t>
+            <t t-if="events == []">
+                <h4 ><b>No events available for <span t-esc="country.name"></span></b></h4>
+            </t>
+        </div>
+    </t>
+</template>
 </data>
 </openerp>