[IMP]Improved code for publish and subscribe.
bzr revid: bth@tinyerp.com-20130905102511-338aevjlwe3jktcc
This commit is contained in:
parent
82dbf1f5b0
commit
5093f52887
|
@ -16,7 +16,7 @@ import werkzeug
|
|||
|
||||
class website_event(http.Controller):
|
||||
|
||||
@website.route(['/event/', '/event/page/<int:page>/'], type='http', auth="public")
|
||||
@website.route(['/event', '/event/page/<int:page>/'], type='http', auth="public")
|
||||
def events(self, page=1, **searches):
|
||||
website = request.registry['website']
|
||||
event_obj = request.registry['event.event']
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
from openerp.addons.web import http
|
||||
from openerp import SUPERUSER_ID
|
||||
from openerp.addons.web.http import request
|
||||
from openerp.addons.website import website
|
||||
import base64
|
||||
import simplejson
|
||||
|
||||
|
@ -9,7 +10,7 @@ from urllib import quote_plus
|
|||
|
||||
class website_hr_recruitment(http.Controller):
|
||||
|
||||
@http.route(['/jobs'], type='http', auth="public")
|
||||
@website.route(['/jobs'], type='http', auth="public")
|
||||
def jobs(self, **post):
|
||||
website = request.registry['website']
|
||||
hr_job_obj = request.registry['hr.job']
|
||||
|
@ -27,24 +28,24 @@ class website_hr_recruitment(http.Controller):
|
|||
vals = {}
|
||||
for rec in hr_job_obj.browse(request.cr, request.uid, jobpost_ids):
|
||||
vals[rec.id] = {'count': int(rec.no_of_recruitment), 'date_recruitment': rec.write_date.split(' ')[0]}
|
||||
values = website.get_rendering_context({
|
||||
values = {
|
||||
'companies': companies,
|
||||
'res_job': hr_job_obj.browse(request.cr, request.uid, jobpost_ids),
|
||||
'vals': vals,
|
||||
'no_of_jobs': len(hr_job_obj.browse(request.cr, request.uid, jobpost_ids)),
|
||||
})
|
||||
return website.render("website_hr_recruitment.index", values)
|
||||
}
|
||||
return request.webcontext.render("website_hr_recruitment.index", values)
|
||||
|
||||
@http.route(['/job/detail/<id>'], type='http', auth="public")
|
||||
@website.route(['/job/detail/<id>'], type='http', auth="public")
|
||||
def detail(self, id=0):
|
||||
id = id and int(id) or 0
|
||||
website = request.registry['website']
|
||||
values = website.get_rendering_context({
|
||||
values = {
|
||||
'job': request.registry['hr.job'].browse(request.cr, request.uid, id)
|
||||
})
|
||||
return website.render("website_hr_recruitment.detail", values)
|
||||
}
|
||||
return request.webcontext.render("website_hr_recruitment.detail", values)
|
||||
|
||||
@http.route(['/job/success'], type='http', auth="admin")
|
||||
@website.route(['/job/success'], type='http', auth="admin")
|
||||
def success(self, **post):
|
||||
id = request.registry['hr.applicant'].create(request.cr, request.uid, post)
|
||||
if post['ufile']:
|
||||
|
@ -58,12 +59,12 @@ class website_hr_recruitment(http.Controller):
|
|||
}
|
||||
request.registry['ir.attachment'].create(request.cr, request.uid, attachment_values)
|
||||
website = request.registry['website']
|
||||
values = website.get_rendering_context({
|
||||
values = {
|
||||
'jobid': post['job_id']
|
||||
})
|
||||
return website.render("website_hr_recruitment.thankyou", values)
|
||||
}
|
||||
return request.webcontext.render("website_hr_recruitment.thankyou", values)
|
||||
|
||||
@http.route('/recruitment/message_get_subscribed', type='json', auth="admin")
|
||||
@website.route('/recruitment/message_get_subscribed', type='json', auth="admin")
|
||||
def message_get_subscribed(self, email, id, mail_group_id):
|
||||
id = int(id)
|
||||
mail_group_id = int(mail_group_id)
|
||||
|
@ -76,7 +77,7 @@ class website_hr_recruitment(http.Controller):
|
|||
group_obj.message_subscribe(request.cr, SUPERUSER_ID, [mail_group_id], partner_ids)
|
||||
return 1
|
||||
|
||||
@http.route('/recruitment/message_get_unsubscribed', type='json', auth="admin")
|
||||
@website.route('/recruitment/message_get_unsubscribed', type='json', auth="admin")
|
||||
def message_get_unsubscribed(self, email, id, mail_group_id):
|
||||
mail_group_id = int(mail_group_id)
|
||||
id = int(id)
|
||||
|
@ -87,4 +88,22 @@ class website_hr_recruitment(http.Controller):
|
|||
group_obj.message_unsubscribe(request.cr, SUPERUSER_ID, [mail_group_id], partner_ids)
|
||||
return 1
|
||||
|
||||
# vim:expandtab:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
@website.route('/recruitment/published', type='json', auth="admin")
|
||||
def published (self, **post):
|
||||
hr_job = request.registry['hr.job']
|
||||
id = int(post['id'])
|
||||
rec = hr_job.browse(request.cr, request.uid, id)
|
||||
vals = {}
|
||||
|
||||
if rec.website_published:
|
||||
vals['state'] = 'recruit'
|
||||
if rec.no_of_recruitment == 0.0:
|
||||
vals ['no_of_recruitment'] = 1.0
|
||||
else:
|
||||
vals['state'] = 'open'
|
||||
vals ['no_of_recruitment'] = 0.0
|
||||
|
||||
res = hr_job.write(request.cr, request.uid, [rec.id], vals)
|
||||
obj = hr_job.browse(request.cr, request.uid, id)
|
||||
return { 'count': obj.no_of_recruitment, 'state': obj.state, 'published': obj.website_published }
|
||||
# vim:expandtab:tabstop=4:softtabstop=4:shiftwidth=4:
|
|
@ -1,29 +1,60 @@
|
|||
$(function () {
|
||||
$(document).on('click', 'button[name=subscribe]', function (e) {
|
||||
div = $(this).parent();
|
||||
parent = $(this).parent().parent();
|
||||
groupid = $(this).siblings('input[name=group_id]').val();
|
||||
id = $(this).parent().parent().attr('id');
|
||||
email = $(this).siblings('div').find('input[name=email]').val();
|
||||
var div = $(this).parent();
|
||||
var parent = $(this).parent().parent();
|
||||
var groupid = $(this).siblings('input[name=group_id]').val();
|
||||
var id = $(this).parent().parent().attr('id');
|
||||
var email = $(this).siblings('div').find('input[name=email]').val();
|
||||
|
||||
openerp.jsonRpc('/recruitment/message_get_subscribed', 'call', {'email': email, 'id': id, 'mail_group_id': groupid}).then(function (result) {
|
||||
if (result == 1) {
|
||||
div.hide();
|
||||
console.log(parent.find('.hidden'))
|
||||
parent.find('.hidden').find('input[type=hidden][name=email]').val(email);
|
||||
parent.find('.hidden').removeClass('hidden');
|
||||
div.removeClass('show').addClass('hidden');
|
||||
parent.find('div:gt(0)').find('input[type=hidden][name=email]').val(email);
|
||||
parent.find('div:gt(0)').removeClass('hidden');
|
||||
}
|
||||
});
|
||||
});
|
||||
$(document).on('click', 'button[name=unsubscribe]', function (e) {
|
||||
div = $(this).parent();
|
||||
parent = $(this).parent().parent();
|
||||
id = $(this).parent().parent().attr('id');
|
||||
groupid = $(this).siblings('input[name=group_id]').val();
|
||||
var div = $(this).parent();
|
||||
var parent = $(this).parent().parent();
|
||||
var id = $(this).parent().parent().attr('id');
|
||||
var groupid = $(this).siblings('input[name=group_id]').val();
|
||||
|
||||
openerp.jsonRpc('/recruitment/message_get_unsubscribed', 'call', {'email': $(this).siblings('input[name=email]').val(), 'id': id, 'mail_group_id': groupid}).then(function (result) {
|
||||
if (result == 1) {
|
||||
parent.find('.subscribedetails').show();
|
||||
parent.find('div:first').removeClass('hidden').addClass('show');
|
||||
div.addClass('hidden');
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
$(document).on('click', '.js_publish', function (e) {
|
||||
var id = $(this).data('id');
|
||||
var row = $(this).parents().find('tr#'+id);
|
||||
var counting = row.find('td:first').find('span#counting');
|
||||
var msg = row.find('td:first').find('span#norecruit');
|
||||
var div = row.find('td:first').find('div#'+id+' div:first');
|
||||
|
||||
var loadpublish = function () {
|
||||
return openerp.jsonRpc('/recruitment/published', 'call', {'id': id}).then(function (result) {
|
||||
if (result['published']) {
|
||||
msg.addClass('hidden');
|
||||
counting.removeClass('hidden');
|
||||
counting.find('span#counting_num').html(result['count']);
|
||||
div.addClass('hidden');
|
||||
} else {
|
||||
msg.removeClass('hidden');
|
||||
counting.addClass('hidden');
|
||||
div.removeClass('hidden');
|
||||
}
|
||||
});
|
||||
}
|
||||
var i = 0;
|
||||
$(this).ajaxComplete(function(el, xhr, settings) {
|
||||
if (settings.url == "/website/publish") {
|
||||
i++;
|
||||
if (i == 1)
|
||||
settings.jsonpCallback = loadpublish()
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
|
@ -39,18 +39,14 @@
|
|||
<span t-field="job.department_id.name"></span>
|
||||
</t><br/>
|
||||
<i class="icon-time"></i> <t t-esc="vals[job.id]['date_recruitment']"/><br/>
|
||||
<span id='counting'>
|
||||
<t t-if="job.no_of_recruitment > 0">
|
||||
<i class="icon-group"></i> No.of Post:
|
||||
<span id='counting_num'>
|
||||
<t t-esc="vals[job.id]['count']"></t>
|
||||
</span>
|
||||
</t>
|
||||
<span id='counting' t-att-class="job.no_of_recruitment > 0 and 'show' or 'hidden'" style="position:absolute;">
|
||||
<i class="icon-group"></i> No.of Post:
|
||||
<span id='counting_num'>
|
||||
<t t-esc="vals[job.id]['count']"></t>
|
||||
</span>
|
||||
</span>
|
||||
<span id="norecruit">
|
||||
<t t-if="job.no_of_recruitment < 1">
|
||||
Right now no recruitment is going on.
|
||||
</t>
|
||||
<span id="norecruit" t-att-class="job.no_of_recruitment < 1 and 'show' or 'hidden'" style="position:absolute;">
|
||||
Right now no recruitment is going on.
|
||||
</span>
|
||||
<br/>
|
||||
<span><i class="icon-map-marker"></i> <t t-field="res_company.city"/>
|
||||
|
@ -62,29 +58,28 @@
|
|||
</t><br/>
|
||||
<t t-if="res_company.phone">&#x2706; <t t-field="res_company.phone"/></t></span>
|
||||
<div t-att-id="job.id">
|
||||
<t t-if="job.no_of_recruitment < 1">
|
||||
<div class="subscribedetails">
|
||||
<strong>You may also be interested in our others job positions, for which we don't have availabilities right now.<br/>
|
||||
Follow the positions that interests you and we will send you an email when the position is available.</strong><br/><br/>
|
||||
<div class="col-md-4 col-sm-8">
|
||||
<input placeholder="Email Address" type="email" name="email" class="form-control"/>
|
||||
</div>
|
||||
<button class="btn btn-primary" name="subscribe">Subscribe</button>
|
||||
<input type="hidden" name="recid" t-att-value="job.id"/>
|
||||
<input type="hidden" name="group_id" t-att-value="%(website_hr_recruitment.website_mail_jobs)d"/>
|
||||
<div class="subscribedetails" t-att-class="job.no_of_recruitment < 1 and 'show' or 'hidden'">
|
||||
<strong>You may also be interested in our others job positions, for which we don't have availabilities right now.<br/>
|
||||
Follow the positions that interests you and we will send you an email when the position is available.</strong><br/><br/>
|
||||
<div class="col-md-4 col-sm-8">
|
||||
<input placeholder="Email Address" type="email" name="email" class="form-control"/>
|
||||
</div>
|
||||
<div class="hidden">
|
||||
<div class="alert alert-dismissable alert-success">
|
||||
<button type="button" class="close" data-dismiss="alert">x</button>
|
||||
<strong>Oh great!</strong> You are successfully subscribed email notifications for a <a t-att-href="'/job/detail/%%s' %% job.id" class="alert-link"><t t-esc="job.name"/></a> job.
|
||||
</div>
|
||||
<input type="hidden" name="email"/>
|
||||
<input type="hidden" name="group_id" t-att-value="%(website_hr_recruitment.website_mail_jobs)d"/>
|
||||
<button type="submit" class="btn" name="unsubscribe">Unsubscribe</button>
|
||||
<button class="btn btn-primary" name="subscribe">Subscribe</button>
|
||||
<input type="hidden" name="recid" t-att-value="job.id"/>
|
||||
<input type="hidden" name="group_id" t-att-value="%(website_hr_recruitment.website_mail_jobs)d"/>
|
||||
</div>
|
||||
<div class="hidden">
|
||||
<div class="alert alert-dismissable alert-success">
|
||||
<button type="button" class="close" data-dismiss="alert">x</button>
|
||||
<strong>Oh great!</strong> You are successfully subscribed email notifications for a <a t-att-href="'/job/detail/%%s' %% job.id" class="alert-link"><t t-esc="job.name"/></a> job.
|
||||
</div>
|
||||
</t>
|
||||
<input type="hidden" name="email"/>
|
||||
<input type="hidden" name="group_id" t-att-value="%(website_hr_recruitment.website_mail_jobs)d"/>
|
||||
<button type="submit" class="btn" name="unsubscribe">Unsubscribe</button>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
<td><t t-call="website.publish"><t t-set="object" t-value="job"/></t></td>
|
||||
</tr>
|
||||
</t>
|
||||
</tbody>
|
||||
|
|
Loading…
Reference in New Issue