Skip to content

Commit

Permalink
add site_avatar image and upload
Browse files Browse the repository at this point in the history
  • Loading branch information
smpallen99 committed Apr 7, 2018
1 parent 8f88744 commit 087e654
Show file tree
Hide file tree
Showing 19 changed files with 445 additions and 301 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
* Move the infinity_one_pages dependency into the one_pages plugin
* Added new Users Guide
* Added new Administration Guide
* Add site avatar to admin for customizing the desktop app icon
* Add site_client_name to admin for customizing the desktop app tooltip

### Bug Fixes

Expand Down
9 changes: 9 additions & 0 deletions assets/css/app.scss
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,14 @@ aside.side-nav nav.options {
}
}
}
.dropzone.site-avatar-dropzone {
height: 125px;
width: calc(100% - 178px);
}
.dropzone.site-avatar-dropzone span {
top: calc(50% - 8px);
}
.site-avatar-dropzone,
.avatar-dropzone {
border: 1px dashed #ddd;
border-radius: 5px;
Expand All @@ -494,6 +502,7 @@ aside.side-nav nav.options {
display: inline-block;
text-align: center;
z-index: 9999;
position: relative;

&.over {
border: 1px dashed #666;
Expand Down
136 changes: 69 additions & 67 deletions assets/js/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,52 +6,55 @@ console.log('loading admin');
const reset_i = '<i class="icon-ccw secondary-font-color color-error-contrast"></i>'

OneChat.on_load(function(one_chat) {
one_chat.admin = new Admin(one_chat)
})
one_chat.admin = new Admin(one_chat);
});

class Admin {
constructor(one_chat) {
this.one_chat = one_chat
this.modifed = false
this.register_events(this)
this.one_chat = one_chat;
this.modifed = false;
this.register_events(this);
}

enable_save_button() {
let save = $('button.save')
let save = $('button.save');
if (save.attr('disabled') == 'disabled') {
save.removeAttr('disabled')
save.parent().prepend(`<button class="button danger discard"><i class="icon-send"></i><span>${gettext.cancel}</span></button>`)
this.modified = true
save.removeAttr('disabled');
save.parent().prepend(`<button class="button danger discard"><i class="icon-send"></i><span>${gettext.cancel}</span></button>`);
this.modified = true;
}
}
disable_save_button() {
let save = $('button.save')
this.modified = false
save.attr('disabled', 'disabled')
$('button.discard').remove()
let save = $('button.save');
this.modified = false;
save.attr('disabled', 'disabled');
$('button.discard').remove();
}
add_reset_setting_button(target, input_line) {
let data_settings = target.getAttribute('name').replace('[', '__').replace(']', '')
let reset = `<button text='Reset' data-setting="${data_settings}"
class="reset-settings button danger" rebel-click="admin_reset_setting_click">${reset_i}</button>`
if (input_line.find('button.reset-settings').length === 0) {
input_line.append(reset);
let name = target.getAttribute('name');
if (name) {
let data_settings = name.replace('[', '__').replace(']', '');
let reset = `<button text='Reset' data-setting="${data_settings}";
class="reset-settings button danger" rebel-click="admin_reset_setting_click">${reset_i}</button>`;
if (input_line.find('button.reset-settings').length === 0) {
input_line.append(reset);

Rebel.set_event_handlers($(target).selector);
Rebel.set_event_handlers($(target).selector);
}
}
}
handle_change(e) {
let target = e.currentTarget;
let input_line = $(target).closest('.input-line');
this.enable_save_button()
input_line.addClass('setting-changed')
this.enable_save_button();
input_line.addClass('setting-changed');
this.add_reset_setting_button(target, input_line);
}
register_events(admin) {
$('body')
.on('click', 'button.discard', () => {
// admin.disable_save_button()
$('a.admin-link[data-id="admin_info"]').click()
$('a.admin-link[data-id="admin_info"]').click();
})
.on('change', '.admin-settings form input:not(.search)', (e) => {
this.handle_change(e);
Expand All @@ -66,74 +69,74 @@ class Admin {
this.handle_change(e);
})
.on('change', '.permissions-manager [type="checkbox"]', function(e, t) {
e.preventDefault()
console.log('checkbox change t', $(this))
let name = $(this).attr('name')
let value = $(this).is(':checked')
e.preventDefault();
console.log('checkbox change t', $(this));
let name = $(this).attr('name');
let value = $(this).is(':checked');

if (!value) { value = "false" }
OneChat.userchan.push('admin:permissions:change:' + name, {value: value})
.receive("ok", resp => {
// stop_loading_animation()
toastr.success('Room ' + name + ' updated successfully.')
toastr.success('Room ' + name + ' updated successfully.');
})
})
.on('click', '.page-settings .section button.expand', function(e) {
e.preventDefault()
e.preventDefault();
$(this)
.addClass('collapse')
.removeClass('expand')
.first().html('Collapse')
.closest('.section-collapsed')
.removeClass('section-collapsed')
.removeClass('section-collapsed');
})
.on('click', '.page-settings .section button.collapse', function(e) {
e.preventDefault()
e.preventDefault();
$(this)
.removeClass('collapse')
.addClass('expand')
.first().html('Expand')
.closest('.section-title')
.parent()
.addClass('section-collapsed')
.addClass('section-collapsed');
})
.on('click', '.admin-settings button.save', function(e) {
//console.log('saving form....', $('form').data('id'))
e.preventDefault()
OneChat.userchan.push('admin:save:' + $('form').data('id'), $('form').serializeArray())
.receive("ok", resp => {
if (resp.success) {
admin.disable_save_button()
toastr.success(resp.success)
admin.disable_save_button();
toastr.success(resp.success);
} else if (resp.error) {
toastr.error(resp.error)
toastr.error(resp.error);
}
})
})
.on('click', 'button.refresh', function(e) {
let page = $(this).closest('section').data('page')
$('a.admin-link[data-id="' + page + '"]').click()
let page = $(this).closest('section').data('page');
$('a.admin-link[data-id="' + page + '"]').click();
})
.on('click', 'section.admin .list-view.channel-settings span[data-edit]', (e) => {
let channel_id = $(e.currentTarget).closest('[data-id]').data('id')
this.userchan_push('edit', {channel_id: channel_id, field: $(e.currentTarget).data('edit')})
let channel_id = $(e.currentTarget).closest('[data-id]').data('id');
this.userchan_push('edit', {channel_id: channel_id, field: $(e.currentTarget).data('edit')});
})
.on('click', 'section.admin .channel-settings button.save', e => {
let channel_id = $(e.currentTarget).closest('[data-id]').data('id')
let params = $('.channel-settings form').serializeArray()
this.userchan_push('save', {channel_id: channel_id, params: params})
let channel_id = $(e.currentTarget).closest('[data-id]').data('id');
let params = $('.channel-settings form').serializeArray();
this.userchan_push('save', {channel_id: channel_id, params: params});
})
.on('click', 'section.admin .channel-settings button.cancel', e => {
let channel_id = $(e.currentTarget).closest('[data-id]').data('id')
this.userchan_push('cancel', {channel_id: channel_id})
let channel_id = $(e.currentTarget).closest('[data-id]').data('id');
this.userchan_push('cancel', {channel_id: channel_id});
})
.on('click', '#showPassword', e => {
let prefix = "";
if ($('#user_password').length > 0) {
prefix = "user_";
}
let password_name = `#${prefix}password`
let password_confirmation_name = `#${prefix}password_confirmation`
let password_name = `#${prefix}password`;
let password_confirmation_name = `#${prefix}password_confirmation`;
$(e.currentTarget).hide();
$('#hidePassword').show();
$(password_name).attr('type','text');
Expand All @@ -144,63 +147,62 @@ class Admin {
if ($('#user_password').length > 0) {
prefix = "user_";
}
let password_name = `#${prefix}password`
let password_confirmation_name = `#${prefix}password_confirmation`
let password_name = `#${prefix}password`;
let password_confirmation_name = `#${prefix}password_confirmation`;
$(e.currentTarget).hide();
$('#showPassword').show();
$(password_name).attr('type','password');
$(password_confirmation_name).attr('type','password');
})
.on('click', '#randomPassword', e => {
let new_password = OneChat.randomString(12)
let new_password = OneChat.randomString(12);
let prefix = "";
if ($('#user_password').length > 0) {
prefix = "user_";
}
let password_name = `#${prefix}password`
let password_confirmation_name = `#${prefix}password_confirmation`
let password_name = `#${prefix}password`;
let password_confirmation_name = `#${prefix}password_confirmation`;

e.preventDefault()
e.stopPropagation()
$(password_name).attr('type', 'password').val(new_password)
$(password_confirmation_name).attr('type', 'password').val(new_password)
e.preventDefault();
e.stopPropagation();
$(password_name).attr('type', 'password').val(new_password);
$(password_confirmation_name).attr('type', 'password').val(new_password);
$('#showPassword').show();
$('#hidePassword').hide();
})
.on('click', 'section.admin form.user button.save', e => {
OneChat.userchan.push('admin:save:user', $('form.user').serializeArray())
.receive("ok", resp => {
if (resp.success) {
toastr.success(resp.success)
this.close_edit_form($('form.user').data('username'))
toastr.success(resp.success);
this.close_edit_form($('form.user').data('username'));
} else if (resp.error) {
toastr.error(resp.error)
toastr.error(resp.error);
}
})
.receive("error", resp => {
console.log('error resp', resp)
console.log('error resp', resp);
if (resp.error) {
toastr.error(resp.error)
toastr.error(resp.error);
}
if (resp.errors) {
this.show_form_errors(resp.errors)
this.show_form_errors(resp.errors);
}
})
})
.on('click', 'section.admin form.user button.cancel', e => {
this.close_edit_form($('form.user').data('username'))
this.close_edit_form($('form.user').data('username'));
})
.on('click', 'a.new-role', e => {
OneChat.userchan.push('admin:permissions:role:new', {})
OneChat.userchan.push('admin:permissions:role:new', {});
})
.on('click', 'a[href="#admin-permissions-edit"]', e => {
let name = $(e.currentTarget).attr('name')
console.log('permissions edit', name)
OneChat.userchan.push('admin:permissions:role:edit', {name: name})
let name = $(e.currentTarget).attr('name');
OneChat.userchan.push('admin:permissions:role:edit', {name: name});
})
.on('click', '.admin-role.delete', e => {
let name = $(e.currentTarget).attr('data-name')
OneChat.userchan.push('admin:permissions:role:delete', {name: name})
let name = $(e.currentTarget).attr('data-name');
OneChat.userchan.push('admin:permissions:role:delete', {name: name});
})
.on('click', 'a[href="/admin/permissions"]', e => {
e.preventDefault();
Expand Down
39 changes: 23 additions & 16 deletions assets/js/chat_dropzone.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,40 +6,47 @@ $(document).ready(() => {
return (('draggable' in div) || ('ondragstart' in div && 'ondrop' in div)) && 'FormData' in window && 'FileReader' in window;
}();
if (isAdvancedUpload) {
let droppedFiles = false
let droppedFiles = false;
let enterTarget = null;
let obj = $('.dropzone')
let obj = $('.dropzone');

$('body').on('drag dragstart dragend dragover dragenter dragleave drop', '.dropzone', e => {
e.preventDefault()
e.stopPropagation()
e.preventDefault();
e.stopPropagation();
})
.on('dragover dragenter', '.dropzone', (e) => {
if (chat_settings.allow_upload) {
enterTarget = e.target
$('.dropzone').addClass('over')
enterTarget = e.target;
$('.dropzone').addClass('over');
}
})
.on('dragleave dragend drop', '.dropzone', (e) => {
if (enterTarget == e.target) {
$('.dropzone').removeClass('over')
$('.dropzone').removeClass('over');
}
})
.on('drop', '.avatar-dropzone', event => {
// handle the avatar image file drop
if (chat_settings.allow_upload) {
let e = event.originalEvent || event
let files = e.dataTransfer.files || []
OneChat.fileUpload.handleAvatarUpload(files, obj)
let e = event.originalEvent || event;
let files = e.dataTransfer.files || [];
OneChat.fileUpload.handleAvatarUpload(files, obj);
}
})
.on('drop', '.dropzone:not(.avatar-dropzone)', event => {
// handle the attachment file drop
.on('drop', '.site-avatar-dropzone', event => {
if (chat_settings.allow_upload) {
let e = event.originalEvent || event
let files = e.dataTransfer.files || []
OneChat.fileUpload.handleFileUpload(files, obj)
let e = event.originalEvent || event;
let files = e.dataTransfer.files || [];
OneChat.fileUpload.handleSiteAvatarUpload(files, obj);
}
})
.on('drop', '.attachment-dropzone', event => {
// handle the attachment file drop
if (chat_settings.allow_upload) {
let e = event.originalEvent || event;
let files = e.dataTransfer.files || [];
OneChat.fileUpload.handleFileUpload(files, obj);
}
});
}
})
});
Loading

0 comments on commit 087e654

Please sign in to comment.