stops user from creating map with empty name, or topic with empty name. sets max length on topic name. allows enter key to create map
This commit is contained in:
parent
3bebc62873
commit
2a9a27c6c5
5 changed files with 40 additions and 17 deletions
|
@ -221,7 +221,7 @@ Metamaps.GlobalUI.CreateMap = {
|
||||||
$(this).parents('.new_map').find('.permText').html(permText);
|
$(this).parents('.new_map').find('.permText').html(permText);
|
||||||
},
|
},
|
||||||
submit: function (event) {
|
submit: function (event) {
|
||||||
event.preventDefault();
|
if (event) event.preventDefault();
|
||||||
|
|
||||||
var self = Metamaps.GlobalUI.CreateMap;
|
var self = Metamaps.GlobalUI.CreateMap;
|
||||||
|
|
||||||
|
@ -231,23 +231,15 @@ Metamaps.GlobalUI.CreateMap = {
|
||||||
}
|
}
|
||||||
|
|
||||||
var formId = Metamaps.GlobalUI.lightbox === 'forkmap' ? '#fork_map' : '#new_map';
|
var formId = Metamaps.GlobalUI.lightbox === 'forkmap' ? '#fork_map' : '#new_map';
|
||||||
var form = $(formId)
|
var $form = $(formId);
|
||||||
|
|
||||||
self.newMap.set('name', form.find('#map_name').val());
|
self.newMap.set('name', $form.find('#map_name').val());
|
||||||
self.newMap.set('desc', form.find('#map_desc').val());
|
self.newMap.set('desc', $form.find('#map_desc').val());
|
||||||
|
|
||||||
// TODO validate map attributes
|
|
||||||
if (self.newMap.get('name').length===0){
|
if (self.newMap.get('name').length===0){
|
||||||
console.log('Empty map name.');
|
self.throwMapNameError();
|
||||||
Metamaps.GlobalUI.notifyUser('map name is mandatory.');
|
|
||||||
return;
|
|
||||||
|
|
||||||
} else if (self.newMap.get('name').length>140){
|
|
||||||
console.log('map name cannot exceed 140 characteres.');
|
|
||||||
Metamaps.GlobalUI.notifyUser('map name cannot exceed 140 characteres.');
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//console.log('self.newMap.get("name").length='+self.newMap.get("name").length.toString());
|
|
||||||
|
|
||||||
self.newMap.save(null, {
|
self.newMap.save(null, {
|
||||||
success: self.success
|
success: self.success
|
||||||
|
@ -257,6 +249,21 @@ Metamaps.GlobalUI.CreateMap = {
|
||||||
Metamaps.GlobalUI.closeLightbox();
|
Metamaps.GlobalUI.closeLightbox();
|
||||||
Metamaps.GlobalUI.notifyUser('Working...');
|
Metamaps.GlobalUI.notifyUser('Working...');
|
||||||
},
|
},
|
||||||
|
throwMapNameError: function () {
|
||||||
|
var self = Metamaps.GlobalUI.CreateMap;
|
||||||
|
|
||||||
|
var formId = Metamaps.GlobalUI.lightbox === 'forkmap' ? '#fork_map' : '#new_map';
|
||||||
|
var $form = $(formId);
|
||||||
|
|
||||||
|
var message = $("<div class='feedback_message'>Please enter a map name...</div>");
|
||||||
|
|
||||||
|
$form.find('#map_name').after(message);
|
||||||
|
setTimeout(function(){
|
||||||
|
message.fadeOut('fast', function(){
|
||||||
|
message.remove();
|
||||||
|
});
|
||||||
|
}, 5000);
|
||||||
|
},
|
||||||
success: function (model) {
|
success: function (model) {
|
||||||
var self = Metamaps.GlobalUI.CreateMap;
|
var self = Metamaps.GlobalUI.CreateMap;
|
||||||
|
|
||||||
|
|
|
@ -682,10 +682,16 @@ Metamaps.JIT = {
|
||||||
$(document).trigger(Metamaps.JIT.events.mouseMove, [pos]);
|
$(document).trigger(Metamaps.JIT.events.mouseMove, [pos]);
|
||||||
}, // onMouseMoveHandler
|
}, // onMouseMoveHandler
|
||||||
enterKeyHandler: function () {
|
enterKeyHandler: function () {
|
||||||
|
var creatingMap = Metamaps.GlobalUI.lightbox;
|
||||||
|
if (creatingMap === "newmap" || creatingMap === "forkmap") {
|
||||||
|
Metamaps.GlobalUI.CreateMap.submit();
|
||||||
|
}
|
||||||
// this is to submit new topic creation
|
// this is to submit new topic creation
|
||||||
if (Metamaps.Create.newTopic.beingCreated) {
|
else if (Metamaps.Create.newTopic.beingCreated) {
|
||||||
Metamaps.Topic.createTopicLocally();
|
Metamaps.Topic.createTopicLocally();
|
||||||
} else if (Metamaps.Create.newSynapse.beingCreated) {
|
}
|
||||||
|
// to submit new synapse creation
|
||||||
|
else if (Metamaps.Create.newSynapse.beingCreated) {
|
||||||
Metamaps.Synapse.createSynapseLocally();
|
Metamaps.Synapse.createSynapseLocally();
|
||||||
}
|
}
|
||||||
}, //enterKeyHandler
|
}, //enterKeyHandler
|
||||||
|
|
|
@ -2192,6 +2192,16 @@ and it won't be important on password protected instances */
|
||||||
margin: 15px 0 5px;
|
margin: 15px 0 5px;
|
||||||
position: relative;
|
position: relative;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.new_map .feedback_message {
|
||||||
|
float: right;
|
||||||
|
width: 388px;
|
||||||
|
background: #c04f4f;
|
||||||
|
margin: 5px 1px;
|
||||||
|
padding: 2px 5px;
|
||||||
|
border-radius: 2px;
|
||||||
|
color: #FFF;
|
||||||
|
}
|
||||||
.new_map label {
|
.new_map label {
|
||||||
float: left;
|
float: left;
|
||||||
width: 100px;
|
width: 100px;
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
|
|
||||||
<div class="inputGroup">
|
<div class="inputGroup">
|
||||||
<label for="map_name">Name: </label>
|
<label for="map_name">Name: </label>
|
||||||
<%= form.text_field :name %>
|
<%= form.text_field :name, :maxlength => 140 %>
|
||||||
<div class="clearfloat"></div>
|
<div class="clearfloat"></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
|
|
||||||
<div class="inputGroup">
|
<div class="inputGroup">
|
||||||
<label for="map_name">Name: </label>
|
<label for="map_name">Name: </label>
|
||||||
<%= form.text_field :name %>
|
<%= form.text_field :name, :maxlength => 140 %>
|
||||||
<div class="clearfloat"></div>
|
<div class="clearfloat"></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue