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

Commit

Permalink
[#828] Push resources between nation
Browse files Browse the repository at this point in the history
  • Loading branch information
Rupesh87 committed Oct 5, 2017
1 parent f6112c6 commit 47806a8
Show file tree
Hide file tree
Showing 3 changed files with 236 additions and 2 deletions.
30 changes: 29 additions & 1 deletion app/MyApp/app/Router.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ $(function() {
'checksum(/:nation/:url)': 'checkSum',
'listLearnersCredits/:cid': 'showLearnersListForCredits',
'passwordResetEmail': 'showPasswordResetEmail',
'password-reset': 'showPasswordReset'
'password-reset': 'showPasswordReset',
'syncResources': 'SyncResources'
},
addOrUpdateWelcomeVideoDoc: function() {
// fetch existing welcome video doc if there is any
Expand Down Expand Up @@ -1341,6 +1342,33 @@ $(function() {
$('#olelogo').remove();
applyCorrectStylingSheet(directionOfLang);
},
SyncResources: function() {
var languageDictValue;
var clanguage;
if($.cookie('languageFromCookie'))
{
clanguage= $.cookie('languageFromCookie');
}
else
{
clanguage = 'English'
$.cookie('languageFromCookie',clanguage);
}
languageDictValue = getSpecificLanguage(clanguage);
App.languageDict = languageDictValue;
var directionOfLang = languageDictValue.get('directionOfLang');
applyCorrectStylingSheet(directionOfLang);
var configCollection = new App.Collections.Configurations();
configCollection.fetch({
async: false
});
commConfigModel = configCollection.first();
var commConfigForm = new App.Views.SyncBetweenNation({
model: commConfigModel
})
commConfigForm.render();
App.$el.children('.body').html(commConfigForm.el);
},

MemberForm: function(memberId) {
this.modelForm('Member', 'Member', memberId, 'login')
Expand Down
163 changes: 163 additions & 0 deletions app/MyApp/app/views/SyncBetweenNation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
$(function() {
//This form/view is binded with Configuration model
App.Views.SyncBetweenNation = Backbone.View.extend({

className: "SyncNation-form",

vars: {},
events: {
"change select#from-nation": 'showOptions',
"click #syncResources": 'syncResources',
"click #selectAllButton": function() {
var isChecked = $('#selectAllButton').prop('checked');
if(isChecked){
$("input[name='result']").each(function() {
$(this).prop('checked', true);
})
}else{
$("input[name='result']").each(function() {
$(this).prop('checked', false);
})
}
}

},

template: $('#template-syncBetweenNation').html(),

syncResources: function() {
App.startActivityIndicator();
var resourcesIds =[]
var that = this
var sender_nation = $("#from-nation").val();
var recevier_nation = $("#to-nation").val();
var str = sender_nation.split(",");
var s_admin_name = str[0];
var s_nationUrl = str[1];
var str1 = recevier_nation.split(",");
var r_admin_name = str1[0];
var r_nationUrl = str1[1];

if ($("#from-nation").val() != $("#to-nation").val()) {
$("input[name='result']").each(function() {
if ($(this).is(":checked")) {
resourcesIds.push($(this).val())
}
});
console.log(resourcesIds)
$.ajax({
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json; charset=utf-8'
},
type: 'POST',
url: '/_replicate',
dataType: 'json',
data: JSON.stringify({
"source": 'http://'+ s_admin_name +':'+App.password+'@'+ s_nationUrl + '/resources',
"target": 'http://'+ r_admin_name +':'+App.password+'@'+ r_nationUrl + '/resources',
'doc_ids': resourcesIds
}),
async: false,
success: function (response) {
console.log(response)
App.stopActivityIndicator();
alert(App.languageDict.attributes.Resources_Synced_Success);
},
error: function(status){
console.log(status);
App.stopActivityIndicator();
alert(App.languageDict.attributes.Resources_Synced_Error);
}
});
} else {
alert("sender and recevier are same")
}
},
showOptions: function(e){
if(e.currentTarget.value != ""){
$('#list_courses_resources').show();
$('a#aResources').css({"text-decoration": "underline","font-size": "30px"});
this.showResources(e.currentTarget.value);
}
},
showResources: function(r_options){
App.startActivityIndicator();
var that = this;
$('tbody#tbodyList').children('tr').remove();
if(r_options != ""){
var str = r_options.split(",");
admin_name = str[0];
nationUrl = str[1];
$.ajax({
url: 'http://'+ admin_name + ':oleoleole@' + nationUrl + '/resources/_all_docs?include_docs=true',
type: 'GET',
dataType: 'jsonp',
success: function (response) {
if(response.rows.length > 1){
var tbodyList = "";
for(var i = 0; i < response.rows.length; i++){
var title = response.rows[i].doc.title;
var publisher = response.rows[i].doc.Publisher;
var author = response.rows[i].doc.author;
var id = response.rows[i].id;
if(publisher != undefined){
console.log( response.rows[i].doc)
var checkbox = "<input id="+ id +" type='checkbox' name='result' value="+ id +" >";
tbodyList += "<tr><td>" + checkbox + "</td><td>" + title + "</td><td>" + author + "</td><td>" + publisher + "</td></tr>";
}
}
$("tbody#tbodyList").append(tbodyList);
App.stopActivityIndicator();
}else{
console.log("There is no data available !!!");
App.stopActivityIndicator();
}
},
error: function(status) {
console.log(status);
App.stopActivityIndicator();
}
});
App.stopActivityIndicator();
}else{
App.stopActivityIndicator();
}

},

render: function() {
var configDoc = getCommunityConfigs();
var centralNationUrl = getCentralNationUrl();
var that = this;
var vars = {};
vars["nations"] = [];
vars["languages"] = [];
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++) {
vars.nations.push(json.rows[i].value);
}
that.$el.append(_.template(that.template, vars));
},
error: function (status) {
console.log(status);
}
});
} /*else {
alert(App.languageDict.get('offline_Status_warning'));
that.$el.append(_.template(that.template, vars));
if(that.model.get('_id') != undefined) {
that.setFormValues()
}
}*/
}

})

})
45 changes: 44 additions & 1 deletion 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/SyncBetweenNation.js"></script> <!-- app/views.js -->


<!-- javaScript -->
Expand Down Expand Up @@ -704,7 +705,49 @@ <h5><%= languageDict.attributes.Set_Password %></h5>
<%} %>
</td>
</script>

<script type="text/template" id="template-syncBetweenNation">
<div>
<h3>Sync Between Nation</h3>
</div>
<div class='form-field'>
<span style='font-size:17px'>From Nation</span>
<select id="from-nation" name="select-nation">
<option value="Select Nation" >Select Nation</option>
<% for (var i=0; i<nations.length; i++){%>
<option value="<%= nations[i].admin_name %>,<%= nations[i].nationurl %>"><%= nations[i].name %> </option>
<% }%>
</select>
</div>
<div class='form-field'>
<span style='font-size:17px'>To Nations</span>
<select id="to-nation" name="select-nation" >
<option value="Select Nation" >Select Nation</option>
<% for (var i=0; i<nations.length; i++){%>
<option value="<%= nations[i].admin_name %>,<%= nations[i].nationurl %>"><%= nations[i].name %> </option>
<% }%>
</select>
</div>
<div class='form-field'>
<button class="btn btn-success" id="syncResources">Sync</button>
</div>
<div class="container" id="list_courses_resources" style="display:none;">
<p id="optionsList"><a title="Resources" class="alink" id="aResources"><%= languageDict.attributes.Resources %></a> </p>
<div class="table-responsive">
<table class="table">
<thead>
<tr>
<th><input type="checkbox" id="selectAllButton"></th>
<th>Title</th>
<th>Author</th>
<th>Publisher</th>
</tr>
</thead>
<tbody id="tbodyList">
</tbody>
</table>
</div>
</div>
</script>
<script type="text/template" id="template-addCommunity">

<div>
Expand Down

0 comments on commit 47806a8

Please sign in to comment.