Added Text Editing for teams

This commit is contained in:
Deukhoofd 2016-04-12 22:20:09 +02:00
parent 686ac81b27
commit 07dc054ca9
5 changed files with 59 additions and 10 deletions

View File

@ -133,6 +133,7 @@ class @TeambuilderView extends Backbone.View
exportTeam: (e) =>
$team = $(e.currentTarget).closest('.select-team')
id = $team.data('id')
name = $team.data('name')
if not @getTeam(id).hasNonNullPokemon()
alert("You cannot export empty teams. Please add some pokemon first.")
return false
@ -140,9 +141,28 @@ class @TeambuilderView extends Backbone.View
teamJSON = @getTeam(id).toNonNullJSON()
teamString = PokeBattle.exportTeam(teamJSON.pokemon)
$modal = PokeBattle.modal('modals/export_team')
$modal.find('.exported-team').val(teamString)
$modal.find('textarea, input').first().focus().select()
$modal = PokeBattle.modal 'modals/export_team', ($modal) =>
$modal.find('.exported-team').val(teamString)
$modal.on 'click', '.import-team-submit', (e) =>
teamString = $modal.find('.exported-team').val()
pokemonJSON = PokeBattle.parseTeam(teamString)
errors = @validateImportedTeam(pokemonJSON)
if errors.length > 0
listErrors = errors.map((e) -> "<li>#{e}</li>").join('')
$errors = $modal.find('.form-errors')
$errors.html("<ul>#{listErrors}</ul>").removeClass('hidden')
else
jint = 0
for jPkmn in pokemonJSON
@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()
return false
addNewPokemonEvent: =>

View File

@ -7,4 +7,5 @@
.control-group
textarea.exported-team.textarea_modal
.modal-footer
button.button.import-team-submit(data-dismiss="modal", aria-hidden="true", style="margin-right: 5px") Import
button.button(data-dismiss="modal", aria-hidden="true") Close

View File

@ -4,7 +4,7 @@
.team-meta
span.fake_link.export-team
span.icon-upload
| Export
| Text Editor
| |
span.fake_link.clone-team
span.icon-copy

View File

@ -6559,18 +6559,46 @@
};
TeambuilderView.prototype.exportTeam = function(e) {
var $modal, $team, id, teamJSON, teamString;
var $modal, $team, id, name, teamJSON, teamString;
$team = $(e.currentTarget).closest('.select-team');
id = $team.data('id');
name = $team.data('name');
if (!this.getTeam(id).hasNonNullPokemon()) {
alert("You cannot export empty teams. Please add some pokemon first.");
return false;
}
teamJSON = this.getTeam(id).toNonNullJSON();
teamString = PokeBattle.exportTeam(teamJSON.pokemon);
$modal = PokeBattle.modal('modals/export_team');
$modal.find('.exported-team').val(teamString);
$modal.find('textarea, input').first().focus().select();
$modal = PokeBattle.modal('modals/export_team', (function(_this) {
return function($modal) {
$modal.find('.exported-team').val(teamString);
return $modal.on('click', '.import-team-submit', function(e) {
var $errors, errors, jPkmn, jint, listErrors, pokemonJSON, _i, _len;
teamString = $modal.find('.exported-team').val();
pokemonJSON = PokeBattle.parseTeam(teamString);
errors = _this.validateImportedTeam(pokemonJSON);
if (errors.length > 0) {
listErrors = errors.map(function(e) {
return "<li>" + e + "</li>";
}).join('');
$errors = $modal.find('.form-errors');
$errors.html("<ul>" + listErrors + "</ul>").removeClass('hidden');
} else {
jint = 0;
for (_i = 0, _len = pokemonJSON.length; _i < _len; _i++) {
jPkmn = pokemonJSON[_i];
_this.getTeam(id).replace(jint, jPkmn);
jint = jint + 1;
}
_this.getTeam(id).save();
$modal.find('.imported-team').val("");
$modal.modal('hide');
}
return false;
});
};
})(this));
$modal.find('.exported-team').first().focus();
return false;
};

View File

@ -552,7 +552,7 @@ var locals_ = (locals || {}),title = locals_.title,body = locals_.body;buf.push(
this["JST"]["modals/export_team"] = function anonymous(locals
/**/) {
var buf = [];
buf.push("<div id=\"export-team-modal\" class=\"modal hide\"><div class=\"modal-header\"><button type=\"button\" data-dismiss=\"modal\" aria-hidden=\"true\" class=\"close\">×</button><h3>Your exported team</h3></div><div class=\"modal-body\"><form class=\"form-horizontal\"><div class=\"control-group\"><textarea class=\"exported-team textarea_modal\"></textarea></div></form></div><div class=\"modal-footer\"><button data-dismiss=\"modal\" aria-hidden=\"true\" class=\"button\">Close</button></div></div>");;return buf.join("");
buf.push("<div id=\"export-team-modal\" class=\"modal hide\"><div class=\"modal-header\"><button type=\"button\" data-dismiss=\"modal\" aria-hidden=\"true\" class=\"close\">×</button><h3>Your exported team</h3></div><div class=\"modal-body\"><form class=\"form-horizontal\"><div class=\"control-group\"><textarea class=\"exported-team textarea_modal\"></textarea></div></form></div><div class=\"modal-footer\"><button data-dismiss=\"modal\" aria-hidden=\"true\" style=\"margin-right: 5px\" class=\"button import-team-submit\">Import</button><button data-dismiss=\"modal\" aria-hidden=\"true\" class=\"button\">Close</button></div></div>");;return buf.join("");
};
this["JST"]["modals/import_team"] = function anonymous(locals
@ -1077,7 +1077,7 @@ 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> Export</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>" + (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