Skip to content
This repository has been archived by the owner on Aug 21, 2018. It is now read-only.

Commit

Permalink
[#952] Show Members of a Course on a Nation (#969)
Browse files Browse the repository at this point in the history
  • Loading branch information
razu9861 authored and lmmrssa committed Oct 10, 2017
1 parent 3ce43b9 commit c5969a5
Show file tree
Hide file tree
Showing 7 changed files with 227 additions and 71 deletions.
6 changes: 3 additions & 3 deletions app/MyApp/app/Home-Urdu.css
Original file line number Diff line number Diff line change
Expand Up @@ -1252,8 +1252,8 @@ form > fieldset > ul > li.bbf-field.field-selectLanguage {
#addIndividualResource{
width:110px;
}
#CommunitySelect{
.DropDownOptn{
float: left;
margin-top: -45px;
margin-right: 15px;
margin-left: 20px;
position: relative;
}
6 changes: 3 additions & 3 deletions app/MyApp/app/Home.css
Original file line number Diff line number Diff line change
Expand Up @@ -1060,8 +1060,8 @@ form > fieldset > ul > li.bbf-field.field-selectLanguage {
width:97%;
margin-left:20px;
}
#CommunitySelect{
.DropDownOptn{
float: right;
margin-top: -45px;
margin-right: 15px;
margin-right: 20px;
position: relative;
}
30 changes: 29 additions & 1 deletion app/MyApp/app/Router.js
Original file line number Diff line number Diff line change
Expand Up @@ -3055,10 +3055,38 @@ $(function() {
CourseMembers: function(cId) {
var courseMembers = new App.Views.CourseMembers()
courseMembers.courseId = cId;
App.$el.children('.body').empty();
App.$el.children('.body').html('<div class="DropDownOptn"></div>')
App.$el.children('.body').append('<div class="courseEditStep"></div>');
courseMembers.render();
$('.courseEditStep').append(courseMembers.el);
var CoursecommunityList = "";
if(App.configuration.get('type') == 'nation'){
$.ajax({
url: '/community/_design/bell/_view/getCommunityByCode',
type: 'GET',
dataType: "jsonp",
async: false,
success: function(json){
CoursecommunityList = '<option value="">'+App.languageDict.attributes.All+'</option>';
CoursecommunityList += '<option value="'+App.configuration.get('code')+'">'+App.configuration.get('name')+'</option>';
$.each(json.rows, function(rec, index) {
CoursecommunityList += '<option value="'+this.value.Code+'">'+this.value.Name+'</option>';
})
CoursecommunityList = '<select id="CommunitySelect">'+CoursecommunityList+'</select>';
$('.DropDownOptn').append(CoursecommunityList);
}
});
}
$('#CommunitySelect').change(function(){
var selectedvalue = $('#CommunitySelect').val();
var courseMembers = new App.Views.CourseMembers()
courseMembers.courseId = cId;
courseMembers.randerTable(selectedvalue);
if(selectedvalue == "" || selectedvalue == undefined){
courseMembers.render();
}

});
var directionOfLang = App.languageDict.get('directionOfLang');
if(directionOfLang.toLowerCase()==="right") {
$('.courseEditStep').find('h3').css('margin-right','5%');
Expand Down
241 changes: 180 additions & 61 deletions app/MyApp/app/views/CourseMembers.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,15 @@ $(function () {

App.Views.CourseMembers = Backbone.View.extend({
vars: {},

initialize: function () {},

removeMember:function(e){
var memberId = e.currentTarget.value
var that = this
var courseModel = new App.Models.Course({
_id: this.courseId
})
courseModel.fetch({
success:function(result){
success:function(result){
var members = result.get('members')
members.splice(members.indexOf(memberId),1)
result.set('members',members)
Expand All @@ -24,79 +22,200 @@ $(function () {
async:false
})
while (model = memberCoursePro.first()) {
model.destroy();
}
model.destroy();
}
that.render()
alert(App.languageDict.attributes.Member_Removed_From_Course)
}
}
})
},

render: function () {
//MCP courseId fetch
var courseModel = new App.Models.Course({
_id: this.courseId
})
courseModel.fetch({
async: false
})
var memberList = courseModel.get('members')
var configurations = Backbone.Collection.extend({
url: App.Server + '/configurations/_all_docs?include_docs=true'
var memberProgress = new App.Collections.membercourseprogresses()
memberProgress.courseId = this.courseId
memberProgress.fetch({
async: false,
success: function(res){
console.log(res)
member_list = []
if(res.length > 0){
for(var i = 0; i < res.length; i++){
member_list.push(res.models[i].attributes.memberId)
}
if(member_list.length > 0){
var configurations = Backbone.Collection.extend({
url: App.Server + '/configurations/_all_docs?include_docs=true'
})
var config = new configurations()
config.fetch({
async: false
})

var currentConfig = config.first().toJSON()
var code = currentConfig.rows[0].doc.code
var na = currentConfig.rows[0].doc.nationName.substring(3,5);
$('.courseEditStep').empty();
$('.courseEditStep').append('<h3>'+App.languageDict.attributes.Course_Members+ ' | ' + courseModel.get('name') + '</h3>')
var viewtext = '<table id = "Table1" class="btable btable-striped"><th>'+App.languageDict.attributes.Photo+'</th><th>'+App.languageDict.attributes.Name+'</th><th>'+App.languageDict.attributes.Roles+'</th><th colspan=2>'+App.languageDict.attributes.Actions+'</th>'
for (var i = 0; i < member_list.length; i++) {
var mems = new App.Models.Member({
_id: member_list[i]
})
mems.fetch({
async: false,
})
var roleOfMem;
if(courseModel.get('courseLeader').indexOf(mems.get('_id')) > -1) {
roleOfMem=App.languageDict.attributes.Leader
} else {
roleOfMem=App.languageDict.attributes.Learner
}
var mail = mems.get('login') + '.' + code +na+ '@olebell.org'
var src = "img/default.jpg"
var attchmentURL = '/members/' + mems.id + '/'
if (typeof mems.get('_attachments') !== 'undefined') {
attchmentURL = attchmentURL + _.keys(mems.get('_attachments'))[0]
src = attchmentURL
}
viewtext += '<tr><td><img width="45px" height="45px" src="' + src + '"/></td><td>' + mems.get('firstName') + ' ' + mems.get('lastName') + '</td><td>'+roleOfMem+'</td><td><input type="checkbox" name="courseMember" value="' + mail + '">'+App.languageDict.attributes.Send_Email+'</td>'
var loggedIn = new App.Models.Member({
"_id": $.cookie('Member._id')
})
loggedIn.fetch({
async: false
})
var roles = loggedIn.get("roles")
if( courseModel.get('courseLeader') && courseModel.get('courseLeader').indexOf($.cookie('Member._id'))>-1 || roles.indexOf('Manager')>-1) {
var memId=mems.get('_id')+','+res.models[i].attributes.courseId;
viewtext+='<td><button class="btn btn-danger removeMember" value="' + mems.get('_id') + '" onclick=removeMemberFromCourse(\"' + memId + '")>'+App.languageDict.attributes.Remove+'</button></td>'
}
viewtext+='</tr>'
}
viewtext += '<tr><td></td><td></td><td>' +
'<button class="btn" id="selectAllMembersOnMembers" onclick=selectAllMembers()>' +
App.languageDict.attributes.Select_All+'</button>' +
'<button style="" class="btn" ' +
'onclick=showComposePopupMultiple("' + mail + '") id="sendMailButton">'
+App.languageDict.attributes.Send_Email+'</button>' +
'<button class="btn" id="retrunBack" onclick=retrunBack()>'
+App.languageDict.attributes.Back+'</button></td><td></td><td></td></tr>';
viewtext += '</table>';
$('.courseEditStep').append(viewtext)
}
}
},
error: function(status){
console.log("error :" + status)
}
})
var config = new configurations()
config.fetch({
},
randerTable: function(selectedvalue){
$('#Table1').remove()
var courseModel = new App.Models.Course({
_id: this.courseId
})
courseModel.fetch({
async: false
})
var currentConfig = config.first().toJSON()
var code = currentConfig.rows[0].doc.code
var na = currentConfig.rows[0].doc.nationName.substring(3,5);
$('.courseEditStep').empty();
$('.courseEditStep').append('<h3>'+App.languageDict.attributes.Course_Members+ ' | ' + courseModel.get('name') + '</h3>')
var viewtext = '<table class="btable btable-striped"><th>'+App.languageDict.attributes.Photo+'</th><th>'+App.languageDict.attributes.Name+'</th><th>'+App.languageDict.attributes.Roles+'</th><th colspan=2>'+App.languageDict.attributes.Actions+'</th>'
for (var i = 0; i < memberList.length; i++) {
var mem = new App.Models.Member({
_id: memberList[i]
})
mem.fetch({
async: false
})
var roleOfMem;
if(courseModel.get('courseLeader').indexOf(mem.get('_id')) > -1) {
roleOfMem=App.languageDict.attributes.Leader
} else {
roleOfMem=App.languageDict.attributes.Learner
var memberProgress = new App.Collections.membercourseprogresses()
memberProgress.courseId = this.courseId
memberProgress.fetch({
async: false,
success: function(res){
member_list = []
if(res.length > 0){
for(var i = 0; i < res.length; i++){
member_list.push(res.models[i].attributes.memberId)
}
if(member_list.length > 0){
var configurations = Backbone.Collection.extend({
url: App.Server + '/configurations/_all_docs?include_docs=true'
})
var config = new configurations()
config.fetch({
async: false
})
var currentConfig = config.first().toJSON()
var code = currentConfig.rows[0].doc.code
var na = currentConfig.rows[0].doc.nationName.substring(3,5);
$('.courseEditStep').empty();
$('.courseEditStep').append('<h3>'+App.languageDict.attributes.Course_Members+ ' | ' + courseModel.get('name') + '</h3>')
var viewtext = '<table id = "Table1" class="btable btable-striped"><th>'+App.languageDict.attributes.Photo+'</th><th>'+App.languageDict.attributes.Name+'</th><th>'+App.languageDict.attributes.Roles+'</th><th colspan=2>'+App.languageDict.attributes.Actions+'</th>'
var newMember_list = []
for (var i = 0; i < member_list.length; i++) {
var mems = new App.Models.Member({
_id: member_list[i]
})
mems.fetch({
async: false,
})
if(mems.attributes.community == selectedvalue){
newMember_list.push(member_list[i])
}
}
if(newMember_list.length > 0){
for (var i = 0; i < newMember_list.length; i++){
var mems = new App.Models.Member({
_id:newMember_list[i]
})
mems.fetch({
async: false
})
var roleOfMem;
if(courseModel.get('courseLeader').indexOf(mems.get('_id')) > -1) {
roleOfMem=App.languageDict.attributes.Leader
} else {
roleOfMem=App.languageDict.attributes.Learner
}
var mail = mems.get('login') + '.' + code +na+ '@olebell.org'
var src = "img/default.jpg"
var attchmentURL = '/members/' + mems.id + '/'
if (typeof mems.get('_attachments') !== 'undefined') {
attchmentURL = attchmentURL + _.keys(mems.get('_attachments'))[0]
src = attchmentURL
}
viewtext += '<tr><td><img width="45px" height="45px" src="' + src + '"/></td><td>' + mems.get('firstName') + ' ' + mems.get('lastName') + '</td><td>'+roleOfMem+'</td><td><input type="checkbox" name="courseMember" value="' + mail + '">'+App.languageDict.attributes.Send_Email+'</td>'
var loggedIn = new App.Models.Member({
"_id": $.cookie('Member._id')
})
loggedIn.fetch({
async: false
})
var roles = loggedIn.get("roles")
if( courseModel.get('courseLeader') && courseModel.get('courseLeader').indexOf($.cookie('Member._id'))>-1 || roles.indexOf('Manager')>-1) {
var memId=mems.get('_id')+','+this.courseId;
viewtext+='<td><button class="btn btn-danger removeMember" value="' + mems.get('_id') + '" onclick=removeMemberFromCourse(\"' + memId + '")>'+App.languageDict.attributes.Remove+'</button></td>'
}
viewtext+='</tr>'
}
viewtext += '<tr><td></td><td></td><td>' +
'<button class="btn" id="selectAllMembersOnMembers" onclick=selectAllMembers()>' +
App.languageDict.attributes.Select_All+'</button>' +
'<button style="" class="btn" ' +
'onclick=showComposePopupMultiple("' + mail + '") id="sendMailButton">'
+App.languageDict.attributes.Send_Email+'</button>' +
'<button class="btn" id="retrunBack" onclick=retrunBack()>'
+App.languageDict.attributes.Back+'</button></td><td></td><td></td></tr>';
viewtext += '</table>';
$('.courseEditStep').append(viewtext)
} else {
viewtext += '<tr><td></td><td></td><td></td><td></td></tr>';
$('.courseEditStep').append(viewtext)
}
}
}
},
error: function(status){
console.log("error :" + status)
}
var mail = mem.get('login') + '.' + code +na+ '@olebell.org'
var src = "img/default.jpg"
var attchmentURL = '/members/' + mem.id + '/'
if (typeof mem.get('_attachments') !== 'undefined') {
attchmentURL = attchmentURL + _.keys(mem.get('_attachments'))[0]
src = attchmentURL
}
viewtext += '<tr><td><img width="45px" height="45px" src="' + src + '"/></td><td>' + mem.get('firstName') + ' ' + mem.get('lastName') + '</td><td>'+roleOfMem+'</td><td><input type="checkbox" name="courseMember" value="' + mail + '">'+App.languageDict.attributes.Send_Email+'</td>'
var loggedIn = new App.Models.Member({
"_id": $.cookie('Member._id')
})
loggedIn.fetch({
async: false
})
var roles = loggedIn.get("roles")
if( courseModel.get('courseLeader') && courseModel.get('courseLeader').indexOf($.cookie('Member._id'))>-1 || roles.indexOf('Manager')>-1) {
var memId=mem.get('_id')+','+this.courseId;
viewtext+='<td><button class="btn btn-danger removeMember" value="' + mem.get('_id') + '" onclick=removeMemberFromCourse(\"' + memId + '")>'+App.languageDict.attributes.Remove+'</button></td>'
}
viewtext+='</tr>'
}
viewtext += '<tr><td></td><td></td><td>' +
'<button class="btn" id="selectAllMembersOnMembers" onclick=selectAllMembers()>' +
App.languageDict.attributes.Select_All+'</button>' +
'<button style="" class="btn" ' +
'onclick=showComposePopupMultiple("' + mail + '") id="sendMailButton">'
+App.languageDict.attributes.Send_Email+'</button>' +
'<button class="btn" id="retrunBack" onclick=retrunBack()>'
+App.languageDict.attributes.Back+'</button></td></tr>';
viewtext += '</table>';
$('.courseEditStep').append(viewtext)
})
}
})
})
})
4 changes: 2 additions & 2 deletions databases/membercourseprogress.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ ddoc.views = {
}
}
},
GetCourseResult: {
GetCourseResult: {
map: function(doc) {
if (doc.courseId) {
emit(doc.courseId, true)
Expand Down Expand Up @@ -43,4 +43,4 @@ ddoc.views = {
}
}

module.exports = ddoc;
module.exports = ddoc;
7 changes: 7 additions & 0 deletions databases/members.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,13 @@ ddoc.views = {
}
}
},
FilterByCommunity: {
map: function(doc) {
if (doc._id && doc.community) {
emit(doc._id, doc.community)
}
}
},
allMembers: {
map: function(doc) {
if (doc && doc.kind == 'Member') {
Expand Down
Loading

0 comments on commit c5969a5

Please sign in to comment.