Skip to content

Commit

Permalink
Merge branch 'mobile' into modtools
Browse files Browse the repository at this point in the history
  • Loading branch information
chriscant committed Nov 27, 2018
2 parents 4c04bb2 + ba78f08 commit de69b9f
Show file tree
Hide file tree
Showing 19 changed files with 240 additions and 106 deletions.
9 changes: 6 additions & 3 deletions http/js/iznik/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ define([
"mypost/:id/:id": "userMyPostAction",
"mypost/:id": "userMyPost",
"stories/fornewsletter": "userNewsletterReview",
"stories": "userStories",
"stories(/:id)": "userStories",
"story/:id": "userStory",
"volunteering": "userVolunteerings",
"volunteering/group/(/:id)": "userVolunteerings",
Expand Down Expand Up @@ -385,12 +385,14 @@ define([
}
},

userStories: function() {
userStories: function(groupid) {
if (!MODTOOLS) {
var self = this;

require(["iznik/views/pages/user/stories"], function () {
var page = new Iznik.Views.User.Pages.Stories();
var page = new Iznik.Views.User.Pages.Stories({
groupid: groupid
});
self.loadRoute({page: page});
});
}
Expand Down Expand Up @@ -1083,6 +1085,7 @@ define([
if (ret.ret === 0) {
try {
Storage.set('draft', id);
Storage.set('draftrepost', id);

if (ret.messagetype == 'Offer') {
// Make them reconfirm the location
Expand Down
8 changes: 7 additions & 1 deletion http/js/iznik/views/chat/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,16 @@ define([
updateCounts: function () {
var self = this;
var unseen = 0;
var titleunseen = 0;
// console.log("update Chat counts");

Iznik.Session.chats.each(function (chat) {
var chattype = chat.get('chattype');
unseen += chat.get('unseen');

if (chattype === 'User2User' || chattype === 'User2Mod') {
titleunseen += chat.get('unseen');
}
});
/* CC Iznik.Session.chats.each(function (chat) {
var chatView = Iznik.activeChats.viewManager.findByModel(chat);
Expand All @@ -183,7 +189,7 @@ define([
$(this).empty().hide();
}

Iznik.setTitleCounts(unseen, null);
Iznik.setTitleCounts(titleunseen, null);
}
});

Expand Down
4 changes: 2 additions & 2 deletions http/js/iznik/views/pages/modtools/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -363,10 +363,10 @@ define([
},
{
name: 'mentored',
label: 'Mentored?',
label: 'Mentor Caretakers?',
control: 'radio',
options: [{label: 'Yes', value: 1}, {label: 'No', value:0 }],
helpMessage: '(Freegle only) If Yes, this group is being run by Mentors until a local owner can be found.',
helpMessage: '(Freegle only) If Yes, this group is being run by Mentor Caretakers.',
disabled: !Iznik.Session.isAdminOrSupport()
},
{
Expand Down
16 changes: 13 additions & 3 deletions http/js/iznik/views/pages/pages.js
Original file line number Diff line number Diff line change
Expand Up @@ -455,9 +455,18 @@ define([
e.preventDefault();
e.stopPropagation();

self.notifications.allSeen().then(function() {
$('.js-notifholder .js-notifcount').css('visibility', 'hidden');
});
// Make the count go away.
$('.js-notifholder .js-notifcount').css('visibility', 'hidden');

// Fake a click on the notifications to close it. This also means that when
// we reopen it we will refetch it, and then the backgrounds on each notification
// will be correct.
if ($('.dropdown').find('.dropdown-menu').is(":hidden")){
$('.dropdown-toggle').dropdown('toggle');
}

// Update the server in the background.
self.notifications.allSeen();
});
}

Expand Down Expand Up @@ -848,6 +857,7 @@ define([

render: function() {
var self = this;

var p = Iznik.resolvedPromise(self);

if (!self.rendered) {
Expand Down
22 changes: 21 additions & 1 deletion http/js/iznik/views/pages/user/explore.js
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,9 @@ define([

events: {
'click .js-join': 'join',
'click .js-leave': 'leave'
'click .js-leave': 'leave',
'click .js-locgive': 'locGive',
'click .js-locfind': 'locFind'
},

join: function() {
Expand Down Expand Up @@ -493,6 +495,24 @@ define([
}) ;
},

locGive: function() {
// This group has a default location. Set it as our location and skip the "where am I" page.
var self = this;
Storage.set('myhomegroup', self.model.get('id'));
Storage.set('myhomegrouptime', (new Date()).getTime());
Storage.set('mylocation', JSON.stringify(self.model.get('defaultlocation')))
Router.navigate('/give/whatisit', true);
},

locFind: function() {
// This group has a default location. Set it as our location and skip straight to post a wanted
var self = this;
Storage.set('myhomegroup', self.model.get('id'));
Storage.set('myhomegrouptime', (new Date()).getTime());
Storage.set('mylocation', JSON.stringify(self.model.get('defaultlocation')))
Router.navigate('/find/whatisit', true);
},

filter: function(model) {
var thetype = model.get('type');

Expand Down
4 changes: 2 additions & 2 deletions http/js/iznik/views/pages/user/home.js
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ define([
// We don't have the full model, because we only fetched a summary. Get the full
// version and re-render.
self.expanded = true;
self.model.fetch().then(self.render);
self.model.fetch().then(_.bind(self.render, self));

// Abort the panel toggle - will happen once next render fires.
return (false);
Expand Down Expand Up @@ -545,7 +545,7 @@ define([
// We don't have the full model, because we only fetched a summary. Get the full
// version and re-render.
self.expanded = true;
self.model.fetch().then(self.render);
self.model.fetch().then(_.bind(self.render, self));

// Abort the panel toggle - will happen once next render fires.
return(false);
Expand Down
112 changes: 61 additions & 51 deletions http/js/iznik/views/pages/user/pages.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,6 @@ define([
}

try {
console.log("Save home group", val);
Storage.set('myhomegroup', val);
Storage.set('myhomegrouptime', (new Date()).getTime());
} catch (e) {}
Expand Down Expand Up @@ -263,7 +262,6 @@ define([
self.$('.js-next').hide();
self.$('.js-external').hide();

console.log("changeGroup", first);
if (first) {
self.$('.js-closestgroupname').html(first.namedisplay);

Expand Down Expand Up @@ -324,74 +322,86 @@ define([
if (groups.length > 0) {
// We have a group select dropdown on the page.
if (self.groupsnear) {
// We have some groups near their chosen location.
var homegroup = null;
var homegrouptime = null;
var homegroupfound = false;
var firstonhere = null;

try {
homegroup = Storage.get('myhomegroup');
homegrouptime = Storage.get('myhomegrouptime');
} catch (e) {};

// If the first group has been founded since the home group was set up, then we want to
// use that rather than a previous preference. Otherwise new groups don't get existing
// members from their area.
if (self.groupsnear.length > 0) {
var g = self.groupsnear[0];
if (g) {
var founded = (new Date(g.founded)).getTime();
if (!homegrouptime || homegrouptime < founded) {
homegroup = g.id;
try {
Storage.set('myhomegroup', homegroup);
Storage.set('myhomegrouptime', (new Date()).getTime());
} catch (e) {};
self.listenToOnce(Iznik.Session, 'isLoggedIn', function (loggedIn) {
// We have some groups near their chosen location.
var mygroups = Iznik.Session.get('groups');
mygroups.each(function(group) {
if (group.get('type') == 'Freegle' &&
group.get('privategroup')) {
// We are a member of a private group. That should appear at the top.
groups.append('<option value="' + group.get('id') + '" />');
groups.find('option:last').text(group.get('namedisplay'));
}
}
}
});

// Show home group if it's present.
var addedGroups = [];
groups.empty();
_.each(self.groupsnear, function(groupnear) {
if (homegroup == groupnear.id) {
homegroupfound = true;
}
var homegroup = null;
var homegrouptime = null;
var homegroupfound = false;
var firstonhere = null;

if (!firstonhere && groupnear.onhere) {
firstonhere = groupnear.id;
try {
homegroup = Storage.get('myhomegroup');
homegrouptime = Storage.get('myhomegrouptime');
} catch (e) {};

// If the first group has been founded since the home group was set up, then we want to
// use that rather than a previous preference. Otherwise new groups don't get existing
// members from their area.
if (self.groupsnear.length > 0) {
var g = self.groupsnear[0];
if (g) {
var founded = (new Date(g.founded)).getTime();
if (!homegrouptime || homegrouptime < founded) {
homegroup = g.id;
try {
Storage.set('myhomegroup', homegroup);
Storage.set('myhomegrouptime', (new Date()).getTime());
} catch (e) {};
}
}
}
groups.append('<option value="' + groupnear.id + '" />');
groups.find('option:last').text(groupnear.namedisplay);
addedGroups.push(groupnear.id);
});

// Add remaining Freegle groups we're a member of - maybe we have a reason to post on them.
self.listenToOnce(Iznik.Session, 'isLoggedIn', function (loggedIn) {
// Show home group if it's present.
var addedGroups = [];
groups.empty();
_.each(self.groupsnear, function(groupnear) {
if (homegroup == groupnear.id) {
homegroupfound = true;
}

if (!firstonhere && groupnear.onhere) {
firstonhere = groupnear.id;
}
groups.append('<option value="' + groupnear.id + '" />');
groups.find('option:last').text(groupnear.namedisplay);
addedGroups.push(groupnear.id);
});

// Add remaining Freegle groups we're a member of - maybe we have a reason to post on them.
if (loggedIn) {
var mygroups = Iznik.Session.get('groups');
mygroups.each(function(group) {
if (group.get('type') == 'Freegle' && addedGroups.indexOf(group.get('id'))) {
if (group.get('type') == 'Freegle' &&
!group.get('privategroup') &&
addedGroups.indexOf(group.get('id'))) {
groups.append('<option value="' + group.get('id') + '" />');
groups.find('option:last').text(group.get('namedisplay'));
}
});
}

if (homegroupfound) {
groups.val(homegroup);
}

self.changeGroup();
groups.on('change', _.bind(self.changeGroup, self));
});

Iznik.Session.testLoggedIn([
'me',
'groups'
]);

if (homegroupfound) {
groups.val(homegroup);
}

self.changeGroup();
groups.on('change', _.bind(self.changeGroup, self));
}
} else {
// We don't have a groups drop down. Hide that section, but still check for whether we need to
Expand Down
10 changes: 8 additions & 2 deletions http/js/iznik/views/pages/user/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ define([
clearDraft: function() {
var self = this;
Storage.remove('draft');
Storage.remove('draftrepost');
self.render();
},

Expand Down Expand Up @@ -200,7 +201,7 @@ define([
},

save: function () {
// Save the current message as a draft.
// Save the current message as a draft. It may already be one.
var self = this;

var item = this.getItem();
Expand All @@ -224,6 +225,7 @@ define([
});

var data = {
id: Storage.get('draft') ? Storage.get('draft') : null,
collection: 'Draft',
locationid: locationid,
messagetype: self.msgType,
Expand Down Expand Up @@ -459,7 +461,10 @@ define([
// clear out our local storage but still have submitted the message. In that case
// we don't want to use it.
if (self.msgType == msg.get('type') && msg.get('isdraft')) {
self.$('.js-olddraft').fadeIn('slow');
if (id !== Storage.get('draftrepost')) {
// And we're not reposting it.
self.$('.js-olddraft').fadeIn('slow');
}

// Parse out item from subject.
var matches = /(.*?)\:([^)].*)\((.*)\)/.exec(msg.get('subject'));
Expand Down Expand Up @@ -543,6 +548,7 @@ define([
// The draft has now been sent.
Storage.set('lastpost', id);
Storage.remove('draft');
Storage.remove('draftrepost');
} catch (e) {}

if (ret.newuser) {
Expand Down
3 changes: 2 additions & 1 deletion http/js/iznik/views/pages/user/stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ define([

self.collection.fetch({
data: {
reviewnewsletter: self.options.reviewnewsletter
reviewnewsletter: self.options.reviewnewsletter,
groupid: self.options.groupid
}
});
});
Expand Down
Loading

0 comments on commit de69b9f

Please sign in to comment.