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

Commit

Permalink
[#828] Push publication between nations
Browse files Browse the repository at this point in the history
  • Loading branch information
Rupesh87 committed Sep 19, 2017
1 parent 8e18485 commit 75ed81e
Show file tree
Hide file tree
Showing 8 changed files with 972 additions and 39 deletions.
215 changes: 179 additions & 36 deletions app/MyApp/app/Router.js

Large diffs are not rendered by default.

595 changes: 595 additions & 0 deletions app/MyApp/app/views/NationPublicationTable.js

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions app/MyApp/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@

<script src="app/views/AnswerReview.js"></script> <!-- app/views.js -->
<script src="app/views/PasswordReset.js"></script> <!-- app/views.js -->
<script src="app/views/NationPublicationTable.js"></script> <!-- app/views.js -->


<!-- javaScript -->
Expand Down Expand Up @@ -566,6 +567,7 @@ <h5><%= languageDict.attributes.Set_Password %></h5>
</tr>
<tr>
<% if(type == "nation") {%>
<td><button id="newPublication" class="btn btn-hg btn-primary" style="display:none;color: Red;background-color: lightgrey;font-weight: bold;"><%= languageDict.attributes.Publications%>(<%=new_publication_count%>)</button></td>
<td><button id="pendingResources" class="btn btn-hg btn-primary" style="display:none;color: Red;background-color: lightgrey;font-weight: bold;" onclick="document.location.href='../MyApp/index.html#resources/pending'" ><%=languageDict.attributes.Resources%>(<%=pending_resource_count%>)</button></a></td>
<td><button id="pendingRequests" class="btn btn-hg btn-primary" style="display:none;color: Red;background-color: lightgrey;font-weight: bold;" onclick="document.location.href='../nation/index.html#listCommunity'" ><%=languageDict.attributes.Communities%>(<%=pending_request_count%>)</button></a></td>
<%} else {%>
Expand Down
32 changes: 31 additions & 1 deletion app/nation/app/Router.js
Original file line number Diff line number Diff line change
Expand Up @@ -4284,7 +4284,7 @@ $(function() {
var lang = App.Router.getLanguage(loginOfMem);
App.languageDictValue=App.Router.loadLanguageDocs(lang);
App.$el.children('.body').html('<div id="parentDiv"></div>');
$('#parentDiv').append('<div id="parentChildDiv" style="margin-top:10px"><h6 style="float:left;">'+App.languageDictValue.get('IssueNumber')+ ' '+ publicationObject.get('IssueNo') + '</h6> <a class="btn btn-success" style="margin-left:20px" href="#courses/' + publicationId + '">'+App.languageDictValue.get('Add_Course')+'</a> <a class="btn btn-success" href = "../MyApp/index.html#search-bell/' + publicationId + '" style="float:left;margin-left:20px;margin-bottom:10px;">'+App.languageDictValue.get('Add_Resource')+'</a><button class="btn btn-info" style="margin-left:20px" onclick="SelectCommunity(\'' + publicationId + '\')">'+App.languageDictValue.get('Send_Publication')+'</button></div>')
$('#parentDiv').append('<div id="parentChildDiv" style="margin-top:10px"><h6 style="float:left;">'+App.languageDictValue.get('IssueNumber')+ ' '+ publicationObject.get('IssueNo') + '</h6> <a class="btn btn-success" style="margin-left:20px" href="#courses/' + publicationId + '">'+App.languageDictValue.get('Add_Course')+'</a> <a class="btn btn-success" href = "../MyApp/index.html#search-bell/' + publicationId + '" style="float:left;margin-left:20px;margin-bottom:10px;">'+App.languageDictValue.get('Add_Resource')+'</a><button class="btn btn-info" style="margin-left:20px" onclick="SelectCommunity(\'' + publicationId + '\')">'+App.languageDictValue.get('Send_Publication')+'</button><button class="btn btn-info" style="margin-left:20px" onclick="SelectNation(\'' + publicationId + '\')">'+App.languageDictValue.get('Push_Nation')+'</button></div>')
if( publicationObject.attributes.autoPublication == undefined || publicationObject.attributes.autoPublication == false){
$('#parentChildDiv').append(" <a role='button' id='auto_publication' style='margin-left: 15px;' class='btn btn-success auto_publication'>"+App.languageDictValue.get('Enable_Auto_Sync')+"</a>");
}else{
Expand Down Expand Up @@ -4477,6 +4477,36 @@ $(function() {
}
},

SelectNations: function(pId) {
var centralNationUrl = App.Router.getCentralNationUrl();
$('#invitationdiv').fadeIn(1000)
var inviteForm = new App.Views.listNationView()
inviteForm.pId = pId
inviteForm.render()
$('#invitationdiv').html('&nbsp')
$('#invitationdiv').append(inviteForm.el)
var nationUrl = App.configuration.get('nationUrl');
if(navigator.onLine){ //Check if there is a stable internet connection
$.ajax({
url: 'http://' + centralNationUrl + '/nations/_design/bell/_view/getAllNations?_include_docs=true',
type: 'GET',
dataType: 'jsonp',
async: false,
success: function (json) {
for(var i = 0 ; i < json.rows.length ; i++) {
if(json.rows[i].value.nationurl != nationUrl)
$('#nationSelect').append("<option value='" + json.rows[i].value.name + "'>" + json.rows[i].value.name + "</option>")
}
}
});
}
$('#addQuestion').css('pointer-events','none');
if(App.languageDictValue.get('directionOfLang').toLowerCase()==="right")
{
$('#invitationdiv').css({"direction":"rtl"});
}
},

criteriaList: function(surveyId) {
var loginOfMem = $.cookie('Member.login');
var lang = App.Router.getLanguage(loginOfMem);
Expand Down
149 changes: 149 additions & 0 deletions app/nation/app/views/listNationView.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
$(function() {

App.Views.listNationView = Backbone.View.extend({

id: "invitationForm",

events: {
"click #cancelButton": "hidediv",
"click #formButton": "syncData"
},
hidediv: function() {
$('#invitationdiv').fadeOut(1000)

setTimeout(function() {
$('#invitationdiv').hide()
}, 1000);
$('#addQuestion').css('pointer-events','auto');
},
render: function() {
var loginOfMem = $.cookie('Member.login');
var lang = App.Router.getLanguage(loginOfMem);
App.languageDictValue=App.Router.loadLanguageDocs(lang);
var $button = $('<h6>'+App.languageDictValue.get('Select_Nations')+'</h6><select multiple id="nationSelect" size ="15" style="width: 380px;"></select><br><br><a class="btn btn-success" id="formButton">'+App.languageDictValue.get('Send')+'</button>')
this.$el.append($button)
this.$el.append('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;')
this.$el.append('<a class="btn btn-warning" id="cancelButton">'+App.languageDictValue.get('Cancel')+'</button>')
},
syncData: function() {
var loginOfMem = $.cookie('Member.login');
var lang = App.Router.getLanguage(loginOfMem);
var languageDictValue=App.Router.loadLanguageDocs(lang);
var selectedValues = $('#nationSelect').val();
if (!selectedValues) {
alert(languageDictValue.attributes.Prompt_Nation_First)
return
}
var that = this;
if (that.pId != undefined && that.pId != null) {
if (that.pId) {
that.syncPublicationsData(that.pId, selectedValues);
}
}
},
syncPublicationsData: function(p_id, selectedValues) {
var that = this
var loginOfMem = $.cookie('Member.login');
var lang = App.Router.getLanguage(loginOfMem);
var languageDictValue=App.Router.loadLanguageDocs(lang);
App.startActivityIndicator()
var sendPub = new Array()
//******if starts********************************************
if (selectedValues.length > 0) {
//******for loop start*************
var pubResult;
var i;
var selectedNations = [];
for (i = 0; i < selectedValues.length; i++) {
sendPub.splice(0, sendPub.length);
var nName = $("#nationSelect option[value='" + selectedValues[i] + "']").text()
var x = p_id;
//***********************************************************
//extra code for #100
$.ajax({
url: '/publications/_design/bell/_view/publicationById?include_docs=true&key="' + x + '"',
type: 'GET',
dataType: 'json',
success: function(resResult) {
pubResult = resResult.rows[0];
if(pubResult.doc.nationNames == undefined){
pubResult.doc.nationNames = []
}
if (pubResult.doc.nationNames != [] && pubResult.doc.nationNames.length > 0 && pubResult.doc.nationNames.indexOf(nName) > -1) {
alert( languageDictValue.attributes.Already_Pub_Sent+' '+ nName);
} else {
selectedNations.push(nName);
sendPub.push({
nationName: nName,
publicationId: p_id,
Viewed: false,
createrNationUrl: App.configuration.get('nationUrl'),
createrNationName: App.configuration.get('nationName')
})
$.couch.db("publicationdistribution").bulkSave({
"docs": sendPub
}, {
success: function(data) {
var centralNationUrl = App.Router.getCentralNationUrl();
that.synchPubNationWithCenter(centralNationUrl);
},
error: function(status) {
console.log(status);
},
async: false
});
}

},
async: false
});
}
if(i == selectedValues.length && selectedNations && selectedNations.length > 0) {
pubResult.doc["downloadedByNation"] = [];
pubResult.doc["createrNationUrl"] = App.configuration.get('nationUrl');
pubResult.doc["createrNationName"] = App.configuration.get('nationName');
for(var j = 0 ; j < selectedNations.length ; j++) {
pubResult.doc.nationNames.push(selectedNations[j]);
}
$.couch.db("publications").saveDoc(pubResult.doc, {
success: function(data) {

},
error: function(status) {
console.log(status);
},
async: false
});
}

//******for loop ends******************************
$("#list option[value='2']").text()
$('#invitationdiv').fadeOut(1000)
setTimeout(function() {
$('#invitationdiv').hide()
}, 1000);
App.stopActivityIndicator()
}
},

synchPubNationWithCenter: function(centralNationUrl) {
$.ajax({
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json; charset=utf-8'
},
type: 'POST',
url: '/_replicate',
dataType: 'json',
data: JSON.stringify({
"source": "publicationdistribution",
"target": 'http://' + centralNationUrl + '/publicationdistribution'
}),
success: function(response) {
},
async: false
})
}
})

})
6 changes: 5 additions & 1 deletion app/nation/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@
<script src="app/views/VipLinksView.js"></script> <!-- app/views.js -->
<script src="app/views/PullNations.js"></script> <!-- app/views.js -->
<script src="app/Router.js"></script>
<script src="app/views/listNationView.js"></script> <!-- app/views.js -->


<script>
var limitofRecords = 5;
Expand Down Expand Up @@ -193,7 +195,9 @@
function SelectCommunity(pId){
App.Router.SelectCommunities(pId)
}

function SelectNation(pId){
App.Router.SelectNations(pId)
}
function selectCriteria(surveyId){
document.location.href = "#criteriaList/" + surveyId;
}
Expand Down
7 changes: 7 additions & 0 deletions databases/publicationdistribution.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ ddoc.views = {
emit([doc.communityName, doc.Viewed], true);
}
},
//***********************
getNationPublications: {
map: function(doc) {
if (doc.nationName)
emit([doc.nationName, doc.Viewed], true);
}
},
//***********************
pubdistributionById: {
map: function(doc) {
Expand Down
5 changes: 4 additions & 1 deletion init_docs/Text.json
Original file line number Diff line number Diff line change
Expand Up @@ -941,5 +941,8 @@
"You_choose_the_option_without_correct_answer":"You choose the option without correct answer",
"Auto_Publication":"Auto Publication",
"Enable_Auto_Sync":"Enable Auto Sync",
"Disable_Auto_Sync":"Disable Auto Sync"
"Disable_Auto_Sync":"Disable Auto Sync",
"Push_Nation":"Push Nation",
"Select_Nations":"Select_Nation('s)",
"Prompt_Nation_First": "Please select nation first.",
}

0 comments on commit 75ed81e

Please sign in to comment.