diff options
| author | Parth Gajjar (Open ERP) <pga@tinyerp.com> | 2014-02-26 17:01:21 +0530 |
|---|---|---|
| committer | Parth Gajjar (Open ERP) <pga@tinyerp.com> | 2014-02-26 17:01:21 +0530 |
| commit | d4e7b18a553e1920548c4cd6de4faa9815c5cb02 (patch) | |
| tree | 658f9f8a973fd8274f7ceb116e280bcc9668f78c | |
| parent | 2ab61cf001fab1d30050598931bfa39956cf4883 (diff) | |
[ADD] added snippet for country event, script for finding coordinates from brwoser, And display events from users country
bzr revid: pga@tinyerp.com-20140226113121-vni0182v0cc2u3d4
| -rw-r--r-- | addons/website/static/src/css/website.css | 6 | ||||
| -rw-r--r-- | addons/website/static/src/css/website.sass | 6 | ||||
| -rw-r--r-- | addons/website/static/src/img/blocks/block-country_events.png | bin | 0 -> 790 bytes | |||
| -rw-r--r-- | addons/website_event/controllers/main.py | 22 | ||||
| -rw-r--r-- | addons/website_event/static/src/js/website_geolocation.js | 40 | ||||
| -rw-r--r-- | addons/website_event/views/website_event.xml | 58 |
6 files changed, 132 insertions, 0 deletions
diff --git a/addons/website/static/src/css/website.css b/addons/website/static/src/css/website.css index e47b7a41baa..b386c3f4769 100644 --- a/addons/website/static/src/css/website.css +++ b/addons/website/static/src/css/website.css @@ -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; +} diff --git a/addons/website/static/src/css/website.sass b/addons/website/static/src/css/website.sass index 3cdfe37a896..9e69f85065d 100644 --- a/addons/website/static/src/css/website.sass +++ b/addons/website/static/src/css/website.sass @@ -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 Binary files differnew file mode 100644 index 00000000000..52254ba4c3e --- /dev/null +++ b/addons/website/static/src/img/blocks/block-country_events.png diff --git a/addons/website_event/controllers/main.py b/addons/website_event/controllers/main.py index 2a6e1d134e3..132fc14ed09 100644 --- a/addons/website_event/controllers/main.py +++ b/addons/website_event/controllers/main.py @@ -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 index 00000000000..3d48b042433 --- /dev/null +++ b/addons/website_event/static/src/js/website_geolocation.js @@ -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 diff --git a/addons/website_event/views/website_event.xml b/addons/website_event/views/website_event.xml index d002521b021..c2d2129ecdd 100644 --- a/addons/website_event/views/website_event.xml +++ b/addons/website_event/views/website_event.xml @@ -336,5 +336,63 @@ </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&field=image&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> |
