Added Team reordering

This commit is contained in:
Deukhoofd 2016-04-13 01:28:59 +02:00
parent 07dc054ca9
commit 06d84a29c6
7 changed files with 218 additions and 6 deletions

View File

@ -11,6 +11,34 @@ $pokemon-list-height = 50px
box-sizing border-box
height 28px
.arrow-up
width 0;
height 0;
border-left 7px solid transparent
border-right 7px solid transparent
border-bottom 12px solid #939393
position absolute
left 88%
top 25%
&:hover
border-bottom-color #a8a8a8
&:active
border-bottom-color #696969
.arrow-down
width 0
height 0
border-left 7px solid transparent
border-right 7px solid transparent
border-top 12px solid #939393
position absolute
left 88%
top 40%
&:hover
border-top-color #a8a8a8
&:active
border-top-color #696969
.teambuilder .selectize-input input
height 18px

View File

@ -13,6 +13,8 @@ class @TeambuilderView extends Backbone.View
'click .go-to-team' : 'clickTeam'
'click .import-team' : 'renderImportTeamModal'
'click .get-teams' : 'getAllTeamsAdmin'
'click .arrow-up' : 'moveTeamUp'
'click .arrow-down' : 'moveTeamDown'
# Teambuild view
'click .change-format-dropdown a': 'changeTeamFormat'
@ -157,7 +159,6 @@ class @TeambuilderView extends Backbone.View
@getTeam(id).replace(jint, jPkmn)
jint = jint+1
@getTeam(id).save()
$modal.find('.imported-team').val("")
$modal.modal('hide')
return false
$modal.find('.exported-team').first().focus()
@ -252,7 +253,8 @@ class @TeambuilderView extends Backbone.View
@renderTeams()
renderTeams: =>
@$('.display_teams').html @teamsTemplate(teams: @getAllTeams(), window: window)
allteams = sortByKey(@getAllTeams(), "id")
@$('.display_teams').html @teamsTemplate(teams: allteams, window: window)
@$('.display_teams').removeClass('hidden')
@$('.display_pokemon').addClass('hidden')
this
@ -344,4 +346,59 @@ class @TeambuilderView extends Backbone.View
renderSaved: (team) =>
$team = $(".select-team[data-cid='#{team.cid}']")
$team.find('.show_spinner').addClass('hidden')
$team.find('.show_spinner').addClass('hidden')
moveTeamUp: (e) =>
@resetTeams(PokeBattle.TeamStore)
$team = $(e.currentTarget).closest('.select-team')
id = $team.data('id')
for indexno, team_ of @getAllTeams()
if team_.id is id
team = team_
allTeams = sortByKey(@getAllTeams(), "id")
index = -1
for thisteam, num in allTeams
index = num if thisteam.id is id
if index is 0
return
upTeam = allTeams[index - 1]
upID = upTeam.id
downID = team.id
upTeam.id = downID
team.id = upID
team.save()
upTeam.save()
@resetTeams(PokeBattle.TeamStore)
@renderTeams()
moveTeamDown: (e) =>
@resetTeams(PokeBattle.TeamStore)
$team = $(e.currentTarget).closest('.select-team')
id = $team.data('id')
for indexno, team_ of @getAllTeams()
if team_.id is id
team = team_
allTeams = sortByKey(@getAllTeams(), "id")
index = -1
for thisteam, num in allTeams
index = num if thisteam.id is id
if (index is (allTeams.length - 1))
return
upTeam = allTeams[index + 1]
upID = upTeam.id
downID = team.id
upTeam.id = downID
team.id = upID
team.save()
upTeam.save()
@resetTeams(PokeBattle.TeamStore)
@renderTeams()
sortByKey = (array, key) ->
array.sort (a,b) ->
if a[key] < b[key]
-1
else if a[key] > b[key]
1
else
0

View File

@ -1,5 +1,7 @@
.left.select-team.clickable-box.p1.mt1.ml1.relative(data-id=team.id, data-cid=team.cid)
h2.go-to-team.fake_link= team.getName()
.arrow-up
.arrow-down
!= window.JST['team_small']({team: team, window: window})
.team-meta
span.fake_link.export-team
@ -13,5 +15,6 @@
span.fake_link.delete-team
span.icon-remove
| Delete
.show_spinner.flex-center.fill.bg-faded-white.rounded.hidden
!= window.JST['spinner']()

View File

@ -1,5 +1,8 @@
h2 Your teams
.teambuilder_teams.clearfix
each team in teams
if team.isDefault
!= window.JST['teambuilder/team']({team: team, window: window})
each team in teams
!= window.JST['teambuilder/team']({team: team, window: window})
.button.button_blue.add-new-team Add new team

View File

@ -452,6 +452,12 @@ h1{font-family:"PT Sans Narrow","Helvetica Neue",sans-serif;font-size:2em;font-w
100%{-webkit-transform:translate(200%,100%);-moz-transform:translate(200%,100%);-o-transform:translate(200%,100%);-ms-transform:translate(200%,100%);transform:translate(200%,100%)}
}.Team-Admin{border:1px solid #000;width:40%;margin-left:10px}
.teambuilder input,.teambuilder select{-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;height:28px}
.arrow-up{width:0;height:0;border-left:7px solid transparent;border-right:7px solid transparent;border-bottom:12px solid #939393;position:absolute;left:88%;top:25%;}
.arrow-up:hover{border-bottom-color:#a8a8a8}
.arrow-up:active{border-bottom-color:#696969}
.arrow-down{width:0;height:0;border-left:7px solid transparent;border-right:7px solid transparent;border-top:12px solid #939393;position:absolute;left:88%;top:40%;}
.arrow-down:hover{border-top-color:#a8a8a8}
.arrow-down:active{border-top-color:#696969}
.teambuilder .selectize-input input{height:18px}
.teambuilder{position:absolute;top:0;bottom:0;left:0;right:0;}
.teambuilder select,.teambuilder input{margin-bottom:0 !important;width:100%}

View File

@ -6338,9 +6338,13 @@
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
this.TeambuilderView = (function(_super) {
var sortByKey;
__extends(TeambuilderView, _super);
function TeambuilderView() {
this.moveTeamDown = __bind(this.moveTeamDown, this);
this.moveTeamUp = __bind(this.moveTeamUp, this);
this.renderSaved = __bind(this.renderSaved, this);
this.renderSaving = __bind(this.renderSaving, this);
this.validateImportedTeam = __bind(this.validateImportedTeam, this);
@ -6404,6 +6408,8 @@
'click .go-to-team': 'clickTeam',
'click .import-team': 'renderImportTeamModal',
'click .get-teams': 'getAllTeamsAdmin',
'click .arrow-up': 'moveTeamUp',
'click .arrow-down': 'moveTeamDown',
'click .change-format-dropdown a': 'changeTeamFormat',
'blur .team_name': 'blurTeamName',
'keypress .team_name': 'keypressTeamName',
@ -6591,7 +6597,6 @@
jint = jint + 1;
}
_this.getTeam(id).save();
$modal.find('.imported-team').val("");
$modal.modal('hide');
}
return false;
@ -6716,8 +6721,10 @@
};
TeambuilderView.prototype.renderTeams = function() {
var allteams;
allteams = sortByKey(this.getAllTeams(), "id");
this.$('.display_teams').html(this.teamsTemplate({
teams: this.getAllTeams(),
teams: allteams,
window: window
}));
this.$('.display_teams').removeClass('hidden');
@ -6860,6 +6867,86 @@
return $team.find('.show_spinner').addClass('hidden');
};
TeambuilderView.prototype.moveTeamUp = function(e) {
var $team, allTeams, downID, id, index, indexno, num, team, team_, thisteam, upID, upTeam, _i, _len, _ref;
this.resetTeams(PokeBattle.TeamStore);
$team = $(e.currentTarget).closest('.select-team');
id = $team.data('id');
_ref = this.getAllTeams();
for (indexno in _ref) {
team_ = _ref[indexno];
if (team_.id === id) {
team = team_;
}
}
allTeams = sortByKey(this.getAllTeams(), "id");
index = -1;
for (num = _i = 0, _len = allTeams.length; _i < _len; num = ++_i) {
thisteam = allTeams[num];
if (thisteam.id === id) {
index = num;
}
}
if (index === 0) {
return;
}
upTeam = allTeams[index - 1];
upID = upTeam.id;
downID = team.id;
upTeam.id = downID;
team.id = upID;
team.save();
upTeam.save();
this.resetTeams(PokeBattle.TeamStore);
return this.renderTeams();
};
TeambuilderView.prototype.moveTeamDown = function(e) {
var $team, allTeams, downID, id, index, indexno, num, team, team_, thisteam, upID, upTeam, _i, _len, _ref;
this.resetTeams(PokeBattle.TeamStore);
$team = $(e.currentTarget).closest('.select-team');
id = $team.data('id');
_ref = this.getAllTeams();
for (indexno in _ref) {
team_ = _ref[indexno];
if (team_.id === id) {
team = team_;
}
}
allTeams = sortByKey(this.getAllTeams(), "id");
index = -1;
for (num = _i = 0, _len = allTeams.length; _i < _len; num = ++_i) {
thisteam = allTeams[num];
if (thisteam.id === id) {
index = num;
}
}
if (index === (allTeams.length - 1)) {
return;
}
upTeam = allTeams[index + 1];
upID = upTeam.id;
downID = team.id;
upTeam.id = downID;
team.id = upID;
team.save();
upTeam.save();
this.resetTeams(PokeBattle.TeamStore);
return this.renderTeams();
};
sortByKey = function(array, key) {
return array.sort(function(a, b) {
if (a[key] < b[key]) {
return -1;
} else if (a[key] > b[key]) {
return 1;
} else {
return 0;
}
});
};
return TeambuilderView;
})(Backbone.View);

View File

@ -1077,13 +1077,41 @@ buf.push("</select></div>");
this["JST"]["teambuilder/team"] = function anonymous(locals
/**/) {
var buf = [];
var locals_ = (locals || {}),team = locals_.team,window = locals_.window;buf.push("<div" + (jade.attrs({ 'data-id':(team.id), 'data-cid':(team.cid), "class": [('left'),('select-team'),('clickable-box'),('p1'),('mt1'),('ml1'),('relative')] }, {"data-id":true,"data-cid":true})) + "><h2 class=\"go-to-team fake_link\">" + (jade.escape(null == (jade.interp = team.getName()) ? "" : jade.interp)) + "</h2>" + (null == (jade.interp = window.JST['team_small']({team: team, window: window})) ? "" : jade.interp) + "<div class=\"team-meta\"><span class=\"fake_link export-team\"><span class=\"icon-upload\"></span> Text Editor</span> | <span class=\"fake_link clone-team\"><span class=\"icon-copy\"></span> Clone</span> | <span class=\"fake_link delete-team\"><span class=\"icon-remove\"></span> Delete</span></div><div class=\"show_spinner flex-center fill bg-faded-white rounded hidden\">" + (null == (jade.interp = window.JST['spinner']()) ? "" : jade.interp) + "</div></div>");;return buf.join("");
var locals_ = (locals || {}),team = locals_.team,window = locals_.window;buf.push("<div" + (jade.attrs({ 'data-id':(team.id), 'data-cid':(team.cid), "class": [('left'),('select-team'),('clickable-box'),('p1'),('mt1'),('ml1'),('relative')] }, {"data-id":true,"data-cid":true})) + "><h2 class=\"go-to-team fake_link\">" + (jade.escape(null == (jade.interp = team.getName()) ? "" : jade.interp)) + "</h2><div class=\"arrow-up\"></div><div class=\"arrow-down\"></div>" + (null == (jade.interp = window.JST['team_small']({team: team, window: window})) ? "" : jade.interp) + "<div class=\"team-meta\"><span class=\"fake_link export-team\"><span class=\"icon-upload\"></span> Text Editor</span> | <span class=\"fake_link clone-team\"><span class=\"icon-copy\"></span> Clone</span> | <span class=\"fake_link delete-team\"><span class=\"icon-remove\"></span> Delete</span></div><div class=\"show_spinner flex-center fill bg-faded-white rounded hidden\">" + (null == (jade.interp = window.JST['spinner']()) ? "" : jade.interp) + "</div></div>");;return buf.join("");
};
this["JST"]["teambuilder/teams"] = function anonymous(locals
/**/) {
var buf = [];
var locals_ = (locals || {}),teams = locals_.teams,window = locals_.window;buf.push("<h2>Your teams</h2><div class=\"teambuilder_teams clearfix\">");
// iterate teams
;(function(){
var $$obj = teams;
if ('number' == typeof $$obj.length) {
for (var $index = 0, $$l = $$obj.length; $index < $$l; $index++) {
var team = $$obj[$index];
if ( team.isDefault)
{
buf.push(null == (jade.interp = window.JST['teambuilder/team']({team: team, window: window})) ? "" : jade.interp);
}
}
} else {
var $$l = 0;
for (var $index in $$obj) {
$$l++; var team = $$obj[$index];
if ( team.isDefault)
{
buf.push(null == (jade.interp = window.JST['teambuilder/team']({team: team, window: window})) ? "" : jade.interp);
}
}
}
}).call(this);
// iterate teams
;(function(){
var $$obj = teams;