2018-11-18 20:50:09 +00:00
|
|
|
/**
|
|
|
|
* This model is used by gallery/explore_users.blade.php, to handle following/unfollowing users profiles.
|
|
|
|
* @constructor
|
|
|
|
*/
|
|
|
|
function ExploreUsersViewModel(urls)
|
|
|
|
{
|
|
|
|
this.el = '#explore-users-app';
|
|
|
|
|
|
|
|
this.data = {
|
|
|
|
};
|
|
|
|
|
|
|
|
this.computed = {
|
|
|
|
};
|
|
|
|
|
|
|
|
this.methods = {
|
|
|
|
followUser: function(e)
|
|
|
|
{
|
|
|
|
var userIDToFollow = $(e.target).data('user-id');
|
|
|
|
var urlToPost = urls.follow_user_url.replace('/-1/', '/' + userIDToFollow + '/');
|
|
|
|
|
|
|
|
$.post(urlToPost, '', function(data)
|
|
|
|
{
|
|
|
|
window.location.reload(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
e.preventDefault();
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
unFollowUser: function(e)
|
|
|
|
{
|
|
|
|
var userIDToUnfollow = $(e.target).data('user-id');
|
|
|
|
var urlToPost = urls.unfollow_user_url.replace('/-1/', '/' + userIDToUnfollow + '/');
|
|
|
|
|
|
|
|
$.post(urlToPost, '', function(data)
|
|
|
|
{
|
|
|
|
window.location.reload(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
e.preventDefault();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-09-18 10:19:47 +01:00
|
|
|
/**
|
|
|
|
* This model is used by gallery/photo.blade.php, to handle comments and individual photo actions.
|
|
|
|
* @constructor
|
|
|
|
*/
|
2018-09-18 14:28:59 +01:00
|
|
|
function PhotoViewModel(urls) {
|
2018-09-18 10:19:47 +01:00
|
|
|
this.el = '#photo-app';
|
|
|
|
|
|
|
|
this.data = {
|
|
|
|
is_reply_form_loading: false,
|
|
|
|
reply_comment_id: 0
|
|
|
|
};
|
|
|
|
|
2018-09-18 14:28:59 +01:00
|
|
|
this.computed = {
|
|
|
|
replyFormStyle: function()
|
|
|
|
{
|
|
|
|
return {
|
|
|
|
'display': this.is_reply_form_loading ? 'none' : 'block'
|
|
|
|
};
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-09-18 10:19:47 +01:00
|
|
|
this.methods = {
|
2018-09-18 14:28:59 +01:00
|
|
|
init: function() {
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
// Load the right comment reply form
|
|
|
|
$('#comment-reply-modal').on('show.bs.modal', function (event) {
|
|
|
|
var url = urls.reply_comment_form.replace(/-1$/, self.reply_comment_id);
|
|
|
|
$.get(url, function(result)
|
|
|
|
{
|
|
|
|
$('#comment-reply-form-content').html(result);
|
2018-09-18 22:35:22 +01:00
|
|
|
initTinyMce('#comment-text-reply');
|
2018-09-18 14:28:59 +01:00
|
|
|
self.is_reply_form_loading = false;
|
|
|
|
});
|
|
|
|
});
|
2018-09-19 09:44:20 +01:00
|
|
|
|
|
|
|
$('#comment-reply-modal').on('hide.bs.modal', function (event) {
|
|
|
|
tinymce.remove('#comment-text-reply');
|
|
|
|
});
|
2018-09-18 14:28:59 +01:00
|
|
|
},
|
|
|
|
postCommentReply: function() {
|
|
|
|
var form = $('form', '#comment-reply-form-content');
|
|
|
|
var formUrl = $(form).attr('action');
|
|
|
|
|
2018-09-19 09:44:20 +01:00
|
|
|
// Seems like the TinyMCE editor in the BS modal does not persist back to the textarea correctly - so do
|
|
|
|
// this manually (bit of a hack!)
|
|
|
|
$('#comment-text-reply', form).html(tinymce.get('comment-text-reply').getContent());
|
|
|
|
|
2018-09-18 14:28:59 +01:00
|
|
|
var formData = form.serialize();
|
2018-09-19 09:44:20 +01:00
|
|
|
|
2018-09-18 14:28:59 +01:00
|
|
|
$.post(formUrl, formData, function(result)
|
|
|
|
{
|
2018-09-18 15:50:12 +01:00
|
|
|
if (result.redirect_url)
|
|
|
|
{
|
|
|
|
window.location = result.redirect_url;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-09-19 09:44:20 +01:00
|
|
|
tinymce.remove('#comment-text-reply');
|
2018-09-18 15:50:12 +01:00
|
|
|
$('#comment-reply-form-content').html(result);
|
2018-09-19 09:44:20 +01:00
|
|
|
initTinyMce('#comment-text-reply');
|
2018-09-18 15:50:12 +01:00
|
|
|
}
|
2018-09-18 14:28:59 +01:00
|
|
|
});
|
|
|
|
},
|
2018-09-18 10:19:47 +01:00
|
|
|
replyToComment: function(e) {
|
|
|
|
var replyButton = $(e.target).closest('.photo-comment');
|
|
|
|
this.reply_comment_id = replyButton.data('comment-id');
|
|
|
|
|
|
|
|
this.is_reply_form_loading = true;
|
|
|
|
$('#comment-reply-modal').modal('show');
|
2018-09-19 09:44:20 +01:00
|
|
|
|
2018-10-09 22:16:43 +01:00
|
|
|
e.preventDefault();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This model is used by gallery/user_profile.blade.php, to handle a user's profile.
|
|
|
|
* @constructor
|
|
|
|
*/
|
|
|
|
function UserViewModel(urls)
|
|
|
|
{
|
|
|
|
this.el = '#user-app';
|
|
|
|
|
|
|
|
this.data = {
|
|
|
|
feed_items: [],
|
|
|
|
is_loading: true,
|
2018-10-10 13:46:42 +01:00
|
|
|
selected_view: 'profile',
|
|
|
|
user_id: 0
|
2018-10-09 22:16:43 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
this.computed = {
|
|
|
|
isFeed: function() {
|
|
|
|
return this.selected_view === 'feed';
|
|
|
|
},
|
|
|
|
isProfile: function() {
|
|
|
|
return this.selected_view === 'profile';
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
this.methods = {
|
2018-10-10 13:46:42 +01:00
|
|
|
followUser: function(e)
|
|
|
|
{
|
|
|
|
$.post(urls.follow_user_url, '', function(data)
|
|
|
|
{
|
|
|
|
window.location.reload(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
e.preventDefault();
|
|
|
|
return false;
|
|
|
|
},
|
2018-10-09 22:16:43 +01:00
|
|
|
loadFeedItems: function(e)
|
|
|
|
{
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
$.get(urls.feed_url, function (data)
|
|
|
|
{
|
|
|
|
for (var i = 0; i < data.length; i++)
|
|
|
|
{
|
|
|
|
// User name
|
|
|
|
if (data[i].params.user_name && data[i].params.user_url)
|
|
|
|
{
|
|
|
|
data[i].description = data[i].description
|
|
|
|
.replace(
|
|
|
|
':user_name',
|
|
|
|
'<a href="' + data[i].params.user_url + '">' + data[i].params.user_name + '</a>'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Photo name
|
|
|
|
if (data[i].params.photo_name && data[i].params.photo_url)
|
|
|
|
{
|
|
|
|
data[i].description = data[i].description
|
|
|
|
.replace(
|
|
|
|
':photo_name',
|
|
|
|
'<a href="' + data[i].params.photo_url + '">' + data[i].params.photo_name + '</a>'
|
|
|
|
);
|
|
|
|
}
|
2018-11-18 21:39:19 +00:00
|
|
|
|
|
|
|
// Album name
|
|
|
|
if (data[i].params.album_name && data[i].params.album_url)
|
|
|
|
{
|
|
|
|
data[i].description = data[i].description
|
|
|
|
.replace(
|
|
|
|
':album_name',
|
|
|
|
'<a href="' + data[i].params.album_url + '">' + data[i].params.album_name + '</a>'
|
|
|
|
);
|
|
|
|
}
|
2018-11-19 13:26:44 +00:00
|
|
|
|
|
|
|
// App name
|
|
|
|
if (data[i].params.app_name && data[i].params.app_url)
|
|
|
|
{
|
|
|
|
data[i].description = data[i].description
|
|
|
|
.replace(
|
|
|
|
':app_name',
|
|
|
|
'<a href="' + data[i].params.app_url + '">' + data[i].params.app_name + '</a>'
|
|
|
|
);
|
|
|
|
}
|
2018-10-09 22:16:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
self.feed_items = data;
|
|
|
|
self.is_loading = false;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
switchToFeed: function(e) {
|
|
|
|
this.selected_view = 'feed';
|
2018-10-10 12:58:43 +01:00
|
|
|
history.pushState('', '', urls.current_url + '?tab=feed');
|
2018-10-09 22:16:43 +01:00
|
|
|
|
|
|
|
e.preventDefault();
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
switchToProfile: function(e) {
|
|
|
|
this.selected_view = 'profile';
|
2018-10-10 12:58:43 +01:00
|
|
|
history.pushState('', '', urls.current_url + '?tab=profile');
|
2018-10-09 22:16:43 +01:00
|
|
|
|
2018-10-10 13:46:42 +01:00
|
|
|
e.preventDefault();
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
unFollowUser: function(e)
|
|
|
|
{
|
|
|
|
$.post(urls.unfollow_user_url, '', function(data)
|
|
|
|
{
|
|
|
|
window.location.reload(true);
|
|
|
|
});
|
|
|
|
|
2018-09-19 09:44:20 +01:00
|
|
|
e.preventDefault();
|
|
|
|
return false;
|
2018-09-18 10:19:47 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|