Skip to content

Instantly share code, notes, and snippets.

@bosconian-dynamics
Created February 5, 2016 21:50
Show Gist options
  • Save bosconian-dynamics/b38bceee2133e45f3d92 to your computer and use it in GitHub Desktop.
Save bosconian-dynamics/b38bceee2133e45f3d92 to your computer and use it in GitHub Desktop.
Quick and dirty utility to copy and paste ProBoards board-labels in the administrative front-end.
var forumLabels = {
labels: {},
insertionIndex: 0,
copy: function() {
var labels = this.labels = [];
$('div.list.ui-autoform').children().each( function() {
var name = $(this).find( 'input.tl-name-input' ).val();
if( '' == name )
return;
labels.push({
name: name,
color: $(this).find( 'input.tl-color-input' ).val(),
perms: {
access: $(this).find( 'input.tl-permissions_accessible-input' ).val(),
view: $(this).find( 'input.tl-permissions_viewable-input' ).val()
}
});
} );
},
paste: function() {
if( 0 == this.labels.length )
return;
this.insertionIndex = 0;
this.insertNextLabels();
},
insertNextLabels() {
var label = this.labels[ this.insertionIndex++ ];
var list = $('.thread_label_div.ui-autoform .list.ui-autoform');
var newItem = list.find('.ui-autoform-new-item:last');
if( this.labels.length > this.insertionIndex )
list.one( 'DOMNodeInserted', '.ui-autoform-new-item', this.insertNextLabels.bind(this) );
$('#colorPicker').css({visibility: 'hidden'});
newItem
.find('input.tl-color-input')
.val( label.color )
.trigger( 'focus' )
.trigger( 'change' )
.trigger( 'blur' )
.end()
.find('input.tl-permissions_accessible-input')
.val( label.perms.access )
.end()
.find('input.tl-permissions_viewable-input')
.val( label.perms.view )
.end()
.find('input.tl-name-input')
.val( label.name )
.trigger( 'change' );
$('#colorPicker').css({visibility: ''});
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment