[IMP]Improved code for subscribe and unsubscribe and removed unneccesary code.
bzr revid: bth@tinyerp.com-20130822073718-32ibwy5li2b510ot
This commit is contained in:
@@ -10,16 +10,14 @@ from urllib import quote_plus
|
||||
class website_hr_recruitment(http.Controller):
|
||||
|
||||
@http.route(['/jobs'], type='http', auth="public")
|
||||
def jobs(self, mail_group_id=None, job_id=None, **post):
|
||||
def jobs(self, **post):
|
||||
website = request.registry['website']
|
||||
hr_job_obj = request.registry['hr.job']
|
||||
group_obj = request.registry['mail.group']
|
||||
user_obj = request.registry['res.users']
|
||||
|
||||
domain = [(1, '=', 1)] or [('website_published', '=', True)]
|
||||
search = [("state", 'in', ['recruit', 'open'])]
|
||||
domain += search
|
||||
|
||||
|
||||
jobpost_ids = hr_job_obj.search(request.cr, request.uid, domain)
|
||||
request.cr.execute("select distinct(com.id) from hr_job job, res_company com where com.id=job.company_id")
|
||||
ids = []
|
||||
@@ -33,55 +31,10 @@ class website_hr_recruitment(http.Controller):
|
||||
'companies': companies,
|
||||
'res_job': hr_job_obj.browse(request.cr, request.uid, jobpost_ids),
|
||||
'vals': vals,
|
||||
'subscribe': post.get('subscribe'),
|
||||
'job_id': None,
|
||||
'no_of_jobs': len(hr_job_obj.browse(request.cr, request.uid, jobpost_ids)),
|
||||
})
|
||||
if request.uid != website.get_public_user().id and mail_group_id:
|
||||
message_follower_ids = group_obj.read(request.cr, request.uid, [mail_group_id], ['message_follower_ids'])[0]['message_follower_ids']
|
||||
parent_id = user_obj.browse(request.cr, SUPERUSER_ID, request.uid).partner_id.id
|
||||
values['subscribe'] = parent_id in message_follower_ids
|
||||
|
||||
if job_id:
|
||||
values['job_id'] = hr_job_obj.browse(request.cr, request.uid, job_id)
|
||||
return website.render("website_hr_recruitment.index", values)
|
||||
|
||||
@http.route(['/jobs/subscribe'], type='http', auth="public")
|
||||
def subscribe(self, mail_group_id=None, job_id=None, **post):
|
||||
website = request.registry['website']
|
||||
partner_obj = request.registry['res.partner']
|
||||
group_obj = request.registry['mail.group']
|
||||
user_obj = request.registry['res.users']
|
||||
|
||||
if mail_group_id and 'subscribe' in post and (post.get('email') or request.uid != website.get_public_user().id):
|
||||
if request.uid == website.get_public_user().id:
|
||||
partner_ids = partner_obj.search(request.cr, SUPERUSER_ID, [("email", "=", post.get('email'))])
|
||||
if not partner_ids:
|
||||
partner_ids = [partner_obj.create(request.cr, SUPERUSER_ID, {"email": post.get('email'), "name": "Subscribe: %s" % post.get('email')})]
|
||||
else:
|
||||
partner_ids = [user_obj.browse(request.cr, request.uid, request.uid).partner_id.id]
|
||||
group_obj.check_access_rule(request.cr, request.uid, [mail_group_id], 'read')
|
||||
group_obj.message_subscribe(request.cr, SUPERUSER_ID, [mail_group_id], partner_ids)
|
||||
|
||||
return self.jobs(mail_group_id=mail_group_id, job_id=job_id, subscribe=post.get('email'))
|
||||
|
||||
@http.route(['/jobs/unsubscribe'], type='http', auth="public")
|
||||
def unsubscribe(self, mail_group_id=None, job_id=None, **post):
|
||||
website = request.registry['website']
|
||||
partner_obj = request.registry['res.partner']
|
||||
group_obj = request.registry['mail.group']
|
||||
user_obj = request.registry['res.users']
|
||||
|
||||
if mail_group_id and 'unsubscribe' in post and (post.get('email') or request.uid != website.get_public_user().id):
|
||||
if request.uid == website.get_public_user().id:
|
||||
partner_ids = partner_obj.search(request.cr, SUPERUSER_ID, [("email", "=", post.get('email'))])
|
||||
else:
|
||||
partner_ids = [user_obj.browse(request.cr, request.uid, request.uid).partner_id.id]
|
||||
group_obj.check_access_rule(request.cr, request.uid, [mail_group_id], 'read')
|
||||
group_obj.message_unsubscribe(request.cr, SUPERUSER_ID, [mail_group_id], partner_ids)
|
||||
|
||||
return self.jobs(mail_group_id=mail_group_id, job_id=job_id, subscribe=None)
|
||||
|
||||
@http.route(['/job/detail/<id>'], type='http', auth="public")
|
||||
def detail(self, id=0):
|
||||
id = id and int(id) or 0
|
||||
@@ -132,6 +85,7 @@ class website_hr_recruitment(http.Controller):
|
||||
|
||||
@http.route('/recruitment/message_get_subscribed', type='json', auth="admin")
|
||||
def message_get_subscribed(self, email, id):
|
||||
id = int(id)
|
||||
hr_job = request.registry['hr.job']
|
||||
partner_obj = request.registry['res.partner']
|
||||
partner_ids = partner_obj.search(request.cr, SUPERUSER_ID, [("email", "=", email)])
|
||||
@@ -143,9 +97,10 @@ class website_hr_recruitment(http.Controller):
|
||||
@http.route('/recruitment/message_get_unsubscribed', type='json', auth="admin")
|
||||
def message_get_unsubscribed(self, email, id):
|
||||
hr_job = request.registry['hr.job']
|
||||
id = int(id)
|
||||
partner_obj = request.registry['res.partner']
|
||||
partner_ids = partner_obj.search(request.cr, SUPERUSER_ID, [("email", "=", email)])
|
||||
hr_job.write(request.cr, request.uid, [id], {'message_follower_ids': []})
|
||||
hr_job.write(request.cr, request.uid, [id], {'message_follower_ids': [(3, pid) for pid in partner_ids]})
|
||||
return 1
|
||||
|
||||
# vim:expandtab:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
||||
@@ -3,9 +3,11 @@ $(function () {
|
||||
div = $(this).parent();
|
||||
parent = $(this).parent().parent();
|
||||
id = $(this).parent().parent().attr('id');
|
||||
openerp.jsonRpc('/recruitment/message_get_subscribed', 'call', {'email': $(this).siblings('input[name=email]').val(), 'id': id}).then(function (result) {
|
||||
email = $(this).siblings('input[name=email]').val();
|
||||
openerp.jsonRpc('/recruitment/message_get_subscribed', 'call', {'email': email, 'id': id}).then(function (result) {
|
||||
if (result == 1) {
|
||||
div.hide();
|
||||
parent.find('.hidden').find('input[type=hidden]').val(email);
|
||||
parent.find('.hidden').removeClass('hidden');
|
||||
}
|
||||
});
|
||||
@@ -39,6 +41,7 @@ $(function () {
|
||||
} else {
|
||||
$('tr[id='+$link.data('id')+']').find('span#counting').find('span#counting_num').html(result['count']);
|
||||
}
|
||||
$('tr[id='+$link.data('id')+']').find('div[id='+$link.data('id')+']').addClass('hidden');
|
||||
} else {
|
||||
$p.removeClass("hidden");
|
||||
$unp.addClass("hidden");
|
||||
@@ -47,6 +50,18 @@ $(function () {
|
||||
if ($.trim($('tr[id='+$link.data('id')+']').find('span#norecruit').html()).length == 0) {
|
||||
$('tr[id='+$link.data('id')+']').find('span#norecruit').html("Right now no recruitment is going on.")
|
||||
}
|
||||
$('tr[id='+$link.data('id')+']').find('div[id='+$link.data('id')+']').removeClass('hidden');
|
||||
if ($.trim($('tr[id='+$link.data('id')+']').find('div[id='+$link.data('id')+']').html()).length == 0) {
|
||||
htmlcon = "<div class='subscribedetails'><strong>You may also be interested in our others job positions, for which we don't have availabilities right now.<br/>"
|
||||
htmlcon += "Follow the positions that interests you and we will send you an email when the position is available.</strong><br/><br/>"
|
||||
htmlcon += "<input placeholder='Email Address' type='email' name='email' class='input-medium'/>"
|
||||
htmlcon += "<button class='btn btn-primary' name='subscribe'>Subscribe</button>"
|
||||
htmlcon += "<input type='hidden' name='recid' t-att-value='job.id'/> </div>"
|
||||
$('tr[id='+$link.data('id')+']').find('div[id='+$link.data('id')+']').html(htmlcon);
|
||||
}else{
|
||||
$('tr[id='+$link.data('id')+']').find('div[id='+$link.data('id')+']').removeClass('hidden');
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -60,22 +60,24 @@
|
||||
<span t-field="res_company.country_id.name"></span>
|
||||
</t><br/>
|
||||
<t t-if="res_company.phone">&#x2706; <t t-field="res_company.phone"/></t></span>
|
||||
<div t-if="job.no_of_recruitment < 1" t-att-id="job.id">
|
||||
<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/>
|
||||
<input placeholder="Email Address" type="email" name="email" class="input-medium"/>
|
||||
<button class="btn btn-primary" name="subscribe">Subscribe</button>
|
||||
<input type="hidden" name="recid" t-att-value="job.id"/>
|
||||
</div>
|
||||
<div class="hidden">
|
||||
<div class="alert alert-success">
|
||||
<button type="button" class="close" data-dismiss="alert">×</button>
|
||||
<strong>Oh great!</strong> You are successfully subscribed email notifications for a <b><t t-esc="job.name"/></b> job.
|
||||
<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/>
|
||||
<input placeholder="Email Address" type="email" name="email" class="input-medium"/>
|
||||
<button class="btn btn-primary" name="subscribe">Subscribe</button>
|
||||
<input type="hidden" name="recid" t-att-value="job.id"/>
|
||||
</div>
|
||||
<input type="hidden" name="email" t-att-value="subscribe"/>
|
||||
<button type="submit" class="btn" name="unsubscribe">Unsubscribe</button>
|
||||
</div>
|
||||
<div class="hidden">
|
||||
<div class="alert alert-success">
|
||||
<button type="button" class="close" data-dismiss="alert">×</button>
|
||||
<strong>Oh great!</strong> You are successfully subscribed email notifications for a <b><t t-esc="job.name"/></b> job.
|
||||
</div>
|
||||
<input type="hidden" name="email"/>
|
||||
<button type="submit" class="btn" name="unsubscribe">Unsubscribe</button>
|
||||
</div>
|
||||
</t>
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
|
||||
Reference in New Issue
Block a user