[non_profit][fix] Chapter listing and join and leave chapter issue (#12463)
* [fix] Chapter listing and Join and leave chapter issue
* [minor] Changes in chapter html, chapter title to chapter name
diff --git a/erpnext/non_profit/doctype/chapter/chapter.py b/erpnext/non_profit/doctype/chapter/chapter.py
index d484882..3320690 100644
--- a/erpnext/non_profit/doctype/chapter/chapter.py
+++ b/erpnext/non_profit/doctype/chapter/chapter.py
@@ -35,4 +35,16 @@
context.title = 'All Chapters'
context.no_breadcrumbs = True
context.order_by = 'creation desc'
- context.introduction = '<p>All Chapters</p>'
\ No newline at end of file
+ context.introduction = '<p>All Chapters</p>'
+
+
+@frappe.whitelist()
+def leave(title, user_id, leave_reason):
+ chapter = frappe.get_doc("Chapter", title)
+ for member in chapter.members:
+ if member.user == user_id:
+ member.enabled = 0
+ member.leave_reason = leave_reason
+ chapter.save(ignore_permissions=1)
+ frappe.db.commit()
+ return "Thank you for Feedback"
\ No newline at end of file
diff --git a/erpnext/non_profit/doctype/chapter/templates/chapter.html b/erpnext/non_profit/doctype/chapter/templates/chapter.html
index 8953481..671a13a 100644
--- a/erpnext/non_profit/doctype/chapter/templates/chapter.html
+++ b/erpnext/non_profit/doctype/chapter/templates/chapter.html
@@ -5,34 +5,39 @@
<h3>Details</h3>
<p>{{ introduction }}</p>
{% if meetup_embed_html %}
-{{ meetup_embed_html }}
+ {{ meetup_embed_html }}
{% endif %}
<h3>List of Members</h3>
-{% if members %}
+
+{% if members %}
<table class="table table-bordered small" style="max-width: 500px;">
<tr>
<th width="15%" ></th>
<th>Member Details</th>
</tr>
+ {% set index = [1] %}
{% for user in members %}
- <tr>
- <td>{{ loop.index }}</td>
- <td>
- <div class="row">
- <div class="col-lg-6 col-md-6 col-sm-6">{{ frappe.db.get_value('User', user.user, 'full_name') }}</div>
- <div class="col-lg-6 col-md-6 col-sm-6 text-right">
- {% if user.website_url %}
- <a href="{{ user.website_url }}">{{ user.website_url or '' }}</a>
+ {% if user.enabled == 1 %}
+ <tr>
+ <td>{{ index|length }}</td>
+ <td>
+ <div class="row">
+ <div class="col-lg-6 col-md-6 col-sm-6">{{ frappe.db.get_value('User', user.user, 'full_name') }}</div>
+ <div class="col-lg-6 col-md-6 col-sm-6 text-right">
+ {% if user.website_url %}
+ <a href="{{ user.website_url }}">{{ user.website_url or '' }}</a>
+ {% endif %}
+ </div>
+ <div class="col-lg-12">
+ {% if user.introduction %}
+ {{ user.introduction }}
{% endif %}
+ </div>
</div>
- <div class="col-lg-12">
- {% if user.introduction %}
- {{ user.introduction }}
- {% endif %}
- </div>
- </div>
- </td>
- </tr>
+ </td>
+ </tr>
+ {% set __ = index.append(1) %}
+ {% endif %}
{% endfor %}
</table>
{% else %}
diff --git a/erpnext/non_profit/doctype/chapter/templates/chapter_row.html b/erpnext/non_profit/doctype/chapter/templates/chapter_row.html
index 67fb0c5..12176ca 100644
--- a/erpnext/non_profit/doctype/chapter/templates/chapter_row.html
+++ b/erpnext/non_profit/doctype/chapter/templates/chapter_row.html
@@ -1,21 +1,30 @@
{% if doc.published %}
<div style="margin-bottom: 30px; max-width: 600px" class="with-border clickable">
- <a href="/{{ doc.route }}">
+ <a href={{ route }}>
<h3>{{ doc.name }}</h3>
<p>
- <span class="label">{{ frappe.db.get_value('User', chapter_head, 'full_name') }}</span>
+ <span class="label"> Chapter Head : {{ frappe.db.get_value('User', chapter_head, 'full_name') }} </span>
<span class="label">
{% if members %}
- Members: {{ members|length }}
+ {% set index = [] %}
+ {% for user in members %}
+ {% if user.enabled == 1 %}
+ {% set __ = index.append(1) %}
+ {% endif %}
+ {% endfor %}
+ Members: {{ index|length }}
{% else %}
Members: 0
{% endif %}
- </span>
+ </span>
+ <!-- Assignment of value to global variable not working in jinja -->
</p>
<p>{{ html2text(doc.introduction[:200]) }}{% if introduction|len > 200 %}...{% endif %}</p>
</a>
</div>
{% endif %}
+
+<!-- this is a sample default list template -->
<style type="text/css">
.label {
diff --git a/erpnext/non_profit/doctype/chapter_member/chapter_member.json b/erpnext/non_profit/doctype/chapter_member/chapter_member.json
index ba78a67..0b8f5a7 100644
--- a/erpnext/non_profit/doctype/chapter_member/chapter_member.json
+++ b/erpnext/non_profit/doctype/chapter_member/chapter_member.json
@@ -132,6 +132,36 @@
"search_index": 0,
"set_only_once": 0,
"unique": 0
+ },
+ {
+ "allow_bulk_edit": 0,
+ "allow_on_submit": 0,
+ "bold": 0,
+ "collapsible": 0,
+ "columns": 0,
+ "fieldname": "leave_reason",
+ "fieldtype": "Data",
+ "hidden": 0,
+ "ignore_user_permissions": 0,
+ "ignore_xss_filter": 0,
+ "in_filter": 0,
+ "in_global_search": 0,
+ "in_list_view": 0,
+ "in_standard_filter": 0,
+ "label": "Leave Reason",
+ "length": 0,
+ "no_copy": 0,
+ "permlevel": 0,
+ "precision": "",
+ "print_hide": 0,
+ "print_hide_if_no_value": 0,
+ "read_only": 0,
+ "remember_last_selected_value": 0,
+ "report_hide": 0,
+ "reqd": 0,
+ "search_index": 0,
+ "set_only_once": 0,
+ "unique": 0
}
],
"has_web_view": 0,
@@ -144,7 +174,7 @@
"issingle": 0,
"istable": 1,
"max_attachments": 0,
- "modified": "2017-12-06 11:33:34.300252",
+ "modified": "2018-01-12 12:16:10.591039",
"modified_by": "Administrator",
"module": "Non Profit",
"name": "Chapter Member",
diff --git a/erpnext/templates/pages/non_profit/join-chapter.html b/erpnext/templates/pages/non_profit/join-chapter.html
index 284e9c4..029cd77 100644
--- a/erpnext/templates/pages/non_profit/join-chapter.html
+++ b/erpnext/templates/pages/non_profit/join-chapter.html
@@ -11,18 +11,18 @@
<p><a href="/login?redirect-to=/{{ chapter.route }}" class='btn btn-primary'>Login</a></p>
{% else %}
{% if already_member %}
- <p>You are already a member of {{ chapter.title }}!</p>
+ <p>You are already a member of {{ chapter.name }}!</p>
{{ chapter_button() }}
<p><a href="">Leave Chapter</a></p>
{% else %}
{% if frappe.local.request.method=='POST' %}
- <p>Welcome to chapter {{ chapter.title }}!</p>
+ <p>Welcome to chapter {{ chapter.name }}!</p>
{{ chapter_button() }}
{% else %}
<div style="padding: 20px 0;">
<div class="row">
<div class="col-lg-8 col-md-8">
- <form name="user-intro" action="/join-chapter" method='POST'>
+ <form name="user-intro" action="/non_profit/join-chapter" method='POST'>
<div class="form-group">
<input name="name" class="hidden form-control" type="text"
value="{{chapter.name}}">
diff --git a/erpnext/templates/pages/non_profit/join_chapter.py b/erpnext/templates/pages/non_profit/join_chapter.py
index 78ef053..121f444 100644
--- a/erpnext/templates/pages/non_profit/join_chapter.py
+++ b/erpnext/templates/pages/non_profit/join_chapter.py
@@ -4,7 +4,7 @@
context.no_cache = True
chapter = frappe.get_doc('Chapter', frappe.form_dict.name)
if frappe.session.user!='Guest':
- if frappe.session.user in [d.user for d in chapter.members]:
+ if frappe.session.user in [d.user for d in chapter.members if d.enabled == 1]:
context.already_member = True
else:
if frappe.request.method=='GET':
diff --git a/erpnext/templates/pages/non_profit/leave-chapter.html b/erpnext/templates/pages/non_profit/leave-chapter.html
index 2f8452d..009c7af 100644
--- a/erpnext/templates/pages/non_profit/leave-chapter.html
+++ b/erpnext/templates/pages/non_profit/leave-chapter.html
@@ -1,16 +1,42 @@
{% extends "templates/web.html" %}
-<!--
-{% macro chapter_button() %}
- <p><a href="/{{ chapter.route }}" class='btn btn-primary'>
- Go to Chapter Page</a></p>
-{% endmacro %}
- -->
{% block page_content %}
{% if member_deleted %}
- <p>You are not a member of {{ chapter.title }}!</p>
+ <p>You are not a member of {{ chapter.name }}!</p>
+ <div>
+ <form>
+ <div class="form-group">
+ <label for="leave">Why do you want to leave this chapter</label>
+ <input type="text" name="leave" class="form-control" id="leave">
+ </div>
+ <button type="button" class="btn btn-default btn-leave" data-title= "{{ chapter.name }}" id="btn-leave">Submit
+ </button>
+ </form>
+ </div>
<p>Please signup and login to join this chapter</p>
<p><a href="/join-chapter?name={{ chapter.name }}" class='btn btn-primary'>Become Member agian</a></p>
{% endif %}
+ <script>
+ frappe.ready(function() {
+ $(".btn-leave").on("click", function() {
+ var leave = $("#leave").val();
+ var user_id = frappe.session.user;
+ var title = $(this).attr("data-title");
+ frappe.call({
+ method: "erpnext.non_profit.doctype.chapter.chapter.leave",
+ args: {
+ leave_reason: leave,
+ user_id: user_id,
+ title: title
+ },
+ callback: function(r) {
+ if(r.message) {
+ frappe.msgprint(r.message)
+ }
+ }
+ })
+ });
+ })
+ </script>
{% endblock %}
\ No newline at end of file
diff --git a/erpnext/templates/pages/non_profit/leave_chapter.py b/erpnext/templates/pages/non_profit/leave_chapter.py
index 6dbdeca..da2d819 100644
--- a/erpnext/templates/pages/non_profit/leave_chapter.py
+++ b/erpnext/templates/pages/non_profit/leave_chapter.py
@@ -3,13 +3,5 @@
def get_context(context):
context.no_cache = True
chapter = frappe.get_doc('Chapter', frappe.form_dict.name)
- # if frappe.session.user!='Guest':
- if frappe.session.user in [d.user for d in chapter.members]:
- user = frappe.session.user
- parent = frappe.form_dict.name
- frappe.db.sql("""delete from `tabChapter Member` where parent = %s and user = %s """, (parent, user))
- frappe.db.commit()
-
context.member_deleted = True
-
context.chapter = chapter