Skip to content
This repository was archived by the owner on Jul 9, 2019. It is now read-only.

Commit

Permalink
Infinite Buttons Finihsed and Posible
Browse files Browse the repository at this point in the history
  • Loading branch information
Connor Davis committed Jan 30, 2016
1 parent 39e069c commit fa4bb01
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 650 deletions.
79 changes: 50 additions & 29 deletions js/forum/dist/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,25 @@ System.register('davis/socialprofile/components/SocialButtonsModal', ['flarum/co
this.socialaccs = null;
m.request({ method: "GET", url: url }).then(function (result) {
if (result.data.attributes.hasOwnProperty("buttons")) {
_this.socialaccs = JSON.parse(result.data.attributes.buttons);
_this.buttons = [];
for (var k in _this.socialaccs) {
if (_this.socialaccs[k]['title'] != "") {
_this.buttons[k] = {};
_this.buttons[k].index = m.prop(k);
_this.buttons[k].title = m.prop(_this.socialaccs[k]["title"] || "");
_this.buttons[k].url = m.prop(_this.socialaccs[k]["url"] || "");
_this.buttons[k].icon = m.prop(_this.socialaccs[k]["icon"] || "globe");
_this.numberofinputs = k;
if (result.data.attributes.buttons == "[]") {
_this.buttons[0] = {};
_this.buttons[0].index = m.prop(0);
_this.buttons[0].title = m.prop("");
_this.buttons[0].url = m.prop("");
_this.buttons[0].icon = m.prop("globe");
_this.numberofinputs = 0;
} else {
_this.socialaccs = JSON.parse(result.data.attributes.buttons);
_this.buttons = [];
for (var k in _this.socialaccs) {
if (_this.socialaccs[k]['title'] != "") {
_this.buttons[k] = {};
_this.buttons[k].index = m.prop(k);
_this.buttons[k].title = m.prop(_this.socialaccs[k]["title"] || "");
_this.buttons[k].url = m.prop(_this.socialaccs[k]["url"] || "");
_this.buttons[k].icon = m.prop(_this.socialaccs[k]["icon"] || "globe");
_this.numberofinputs = k;
}
}
}
} else {
Expand All @@ -51,20 +60,10 @@ System.register('davis/socialprofile/components/SocialButtonsModal', ['flarum/co
_this.buttons[0].icon = m.prop("globe");
_this.numberofinputs = 0;
}
for (var i = 0; i < _this.numberextras(); i++) {
var currentinput = _this.numberofinputs + (i + 1);
_this.buttons[currentinput] = {};
_this.buttons[k].index = m.prop(0);
_this.buttons[currentinput].title = m.prop("");
_this.buttons[currentinput].url = m.prop("");
_this.buttons[currentinput].icon = m.prop("globe");
_this.numberofinputs = k;
}
m.redraw();
$('.form-group-social').delay(5).slideDown();
});
this.buttons = [];
this.numberextras = m.prop(0);
}
}, {
key: 'className',
Expand All @@ -82,6 +81,7 @@ System.register('davis/socialprofile/components/SocialButtonsModal', ['flarum/co
var _this2 = this;

$(function () {
$('.Modal-content').css('overflow', 'visible');
$(document).on('click', '.action-placement', function (e) {
$('.action-placement').removeClass('active');
$(this).addClass('active');
Expand All @@ -103,7 +103,7 @@ System.register('davis/socialprofile/components/SocialButtonsModal', ['flarum/co
});
});
return [m('div', { className: 'Modal-body' }, [m('div', { className: 'Form' }, [this.buttons.map(function (button) {
return [m('div', { className: 'Form-group form-group-social' }, [m('input', { className: 'SocialFormControl',
return [m('div', { className: 'Form-group form-group-social', id: 'socialgroup' + button.index() }, [m('input', { className: 'SocialFormControl',
placeholder: app.translator.trans('davis-socialprofile.forum.edit.title'),
value: button.title(),
oninput: m.withAttr('value', button.title)
Expand Down Expand Up @@ -132,7 +132,7 @@ System.register('davis/socialprofile/components/SocialButtonsModal', ['flarum/co
children: app.translator.trans('davis-socialprofile.forum.edit.submit')
}), m('div', { className: 'Button Button--primary EditSocialButtons-add', style: 'margin-left: 1%;',
onclick: function onclick() {
var curadd = _this2.buttons.length + 1;
var curadd = _this2.buttons.length;
_this2.buttons[curadd] = {};
_this2.buttons[curadd].index = m.prop(curadd);
_this2.buttons[curadd].title = m.prop("");
Expand All @@ -141,21 +141,37 @@ System.register('davis/socialprofile/components/SocialButtonsModal', ['flarum/co
_this2.numberofinputs = curadd;

m.redraw();
$('.form-group-social').delay(5).slideDown();
} }, [m('span', { className: 'Button-label' }, "Add Button")])])])])];
$('#socialgroup' + curadd).delay(2).slideDown();
} }, [m('i', { className: 'fa fa-fw fa-plus' })]), m('div', { className: 'Button Button--primary EditSocialButtons-add', style: 'margin-left: 1%;',
onclick: function onclick() {
var curdel = _this2.buttons.length - 1;
$('#socialgroup' + curdel).slideUp('normal', function () {
_this2.buttons.splice(curdel, 1);
m.redraw();
});
} }, [m('i', { className: 'fa fa-fw fa-minus' })])])])])];
}
}, {
key: 'onsubmit',
//TODO, TRANSLATE
value: function onsubmit(e) {
var _this3 = this;

e.preventDefault();

this.loading = true;
this.buttons = JSON.stringify(this.buttons);
this.finbuttons = [];
for (var k in this.buttons) {
if (this.buttons[k].title() != "") {
var number = this.finbuttons.length;
this.finbuttons[number] = {};
this.finbuttons[number].title = m.prop(this.buttons[k].title());
this.finbuttons[number].url = m.prop(this.buttons[k].url());
this.finbuttons[number].icon = m.prop(this.buttons[k].icon());
}
}
this.finbuttons = JSON.stringify(this.finbuttons);
var data = new FormData();
data.append('buttons', this.buttons);
data.append('buttons', this.finbuttons);
app.request({
method: 'POST',
url: app.forum.attribute('apiUrl') + '/profile/socialbuttons',
Expand Down Expand Up @@ -210,8 +226,13 @@ System.register('davis/socialprofile/main', ['davis/socialprofile/models/SocialB
this.socialaccs = null;
app.request({ method: "GET", url: theurl }).then(function (result) {
if (result.data.attributes.hasOwnProperty("buttons")) {
_this.socialaccs = JSON.parse(result.data.attributes.buttons);
_this.newuser = false;
if (result.data.attributes.buttons == "[]") {
_this.socialaccs = true;
_this.newuser = true;
} else {
_this.socialaccs = JSON.parse(result.data.attributes.buttons);
_this.newuser = false;
}
} else {
_this.socialaccs = true;
_this.newuser = true;
Expand Down
52 changes: 36 additions & 16 deletions js/forum/src/components/SocialButtonsModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ export default class SocialButtonsModal extends Modal {
this.socialaccs = null;
m.request({method: "GET", url: url}).then(result => {
if(result.data.attributes.hasOwnProperty("buttons")) {
if(result.data.attributes.buttons == "[]"){
this.buttons[0] = {};
this.buttons[0].index = m.prop(0);
this.buttons[0].title = m.prop("");
this.buttons[0].url = m.prop("");
this.buttons[0].icon = m.prop("globe");
this.numberofinputs = 0;
} else {
this.socialaccs = JSON.parse(result.data.attributes.buttons);
this.buttons = [];
for(var k in this.socialaccs) {
Expand All @@ -24,6 +32,7 @@ export default class SocialButtonsModal extends Modal {
this.numberofinputs = k;
}
}
}
} else {
this.buttons[0] = {};
this.buttons[0].index = m.prop(0);
Expand All @@ -32,20 +41,10 @@ export default class SocialButtonsModal extends Modal {
this.buttons[0].icon = m.prop("globe");
this.numberofinputs = 0;
}
for (var i=0; i < this.numberextras(); i++) {
var currentinput = this.numberofinputs + (i + 1);
this.buttons[currentinput] = {};
this.buttons[k].index = m.prop(0);
this.buttons[currentinput].title = m.prop("");
this.buttons[currentinput].url = m.prop("");
this.buttons[currentinput].icon = m.prop("globe");
this.numberofinputs = k;
}
m.redraw()
$('.form-group-social').delay(5).slideDown();
});
this.buttons = [];
this.numberextras = m.prop(0);
}

className() {
Expand All @@ -59,6 +58,7 @@ export default class SocialButtonsModal extends Modal {
content() {

$(function() {
$('.Modal-content').css('overflow', 'visible');
$(document).on('click', '.action-placement', function(e) {
$('.action-placement').removeClass('active');
$(this).addClass('active');
Expand All @@ -84,7 +84,7 @@ export default class SocialButtonsModal extends Modal {
m('div', {className: 'Form'}, [
this.buttons.map(function(button) {
return [
m('div', {className: 'Form-group form-group-social'}, [
m('div', {className: 'Form-group form-group-social', id: 'socialgroup'+button.index()}, [
m('input', {className: 'SocialFormControl',
placeholder: app.translator.trans('davis-socialprofile.forum.edit.title'),
value: button.title(),
Expand Down Expand Up @@ -132,7 +132,7 @@ export default class SocialButtonsModal extends Modal {
}),
m('div', {className: 'Button Button--primary EditSocialButtons-add', style: 'margin-left: 1%;',
onclick: () => {
var curadd = (this.buttons.length + 1);
var curadd = this.buttons.length;
this.buttons[curadd] = {};
this.buttons[curadd].index = m.prop(curadd);
this.buttons[curadd].title = m.prop("");
Expand All @@ -141,9 +141,19 @@ export default class SocialButtonsModal extends Modal {
this.numberofinputs = curadd;

m.redraw();
$('.form-group-social').delay(5).slideDown();
$('#socialgroup'+curadd).delay(2).slideDown();
}}, [
m('i', {className: 'fa fa-fw fa-plus'})
]),
m('div', {className: 'Button Button--primary EditSocialButtons-add', style: 'margin-left: 1%;',
onclick: () => {
var curdel = (this.buttons.length - 1);
$('#socialgroup'+curdel).slideUp('normal', () => {
this.buttons.splice(curdel, 1);
m.redraw();
});
}}, [
m('span', {className: 'Button-label'}, "Add Button"), //TODO, TRANSLATE
m('i', {className: 'fa fa-fw fa-minus'})
]),
]),
]),
Expand All @@ -156,9 +166,19 @@ export default class SocialButtonsModal extends Modal {
e.preventDefault();

this.loading = true;
this.buttons = JSON.stringify(this.buttons);
this.finbuttons = [];
for(var k in this.buttons) {
if (this.buttons[k].title() != "") {
var number = this.finbuttons.length
this.finbuttons[number] = {};
this.finbuttons[number].title = m.prop(this.buttons[k].title());
this.finbuttons[number].url = m.prop(this.buttons[k].url());
this.finbuttons[number].icon = m.prop(this.buttons[k].icon());
}
}
this.finbuttons = JSON.stringify(this.finbuttons);
const data = new FormData();
data.append('buttons', this.buttons);
data.append('buttons', this.finbuttons);
app.request({
method: 'POST',
url: app.forum.attribute('apiUrl') + '/profile/socialbuttons',
Expand Down
5 changes: 5 additions & 0 deletions js/forum/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,13 @@ app.initializers.add('davis-socialprofile-forum', function() {
this.socialaccs = null;
app.request({method: "GET", url: theurl}).then(result => {
if(result.data.attributes.hasOwnProperty("buttons")) {
if (result.data.attributes.buttons == "[]") {
this.socialaccs = true;
this.newuser = true;
} else {
this.socialaccs = JSON.parse(result.data.attributes.buttons);
this.newuser = false;
}
} else {
this.socialaccs = true;
this.newuser = true;
Expand Down
Loading

0 comments on commit fa4bb01

Please sign in to comment.