diff --git a/app/assets/javascripts/src/Metamaps.GlobalUI.js b/app/assets/javascripts/src/Metamaps.GlobalUI.js index c257e4f1..81f0956d 100644 --- a/app/assets/javascripts/src/Metamaps.GlobalUI.js +++ b/app/assets/javascripts/src/Metamaps.GlobalUI.js @@ -221,7 +221,7 @@ Metamaps.GlobalUI.CreateMap = { $(this).parents('.new_map').find('.permText').html(permText); }, submit: function (event) { - event.preventDefault(); + if (event) event.preventDefault(); var self = Metamaps.GlobalUI.CreateMap; @@ -231,23 +231,15 @@ Metamaps.GlobalUI.CreateMap = { } 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('desc', form.find('#map_desc').val()); + self.newMap.set('name', $form.find('#map_name').val()); + self.newMap.set('desc', $form.find('#map_desc').val()); - // TODO validate map attributes if (self.newMap.get('name').length===0){ - console.log('Empty map name.'); - 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.'); + self.throwMapNameError(); return; } - //console.log('self.newMap.get("name").length='+self.newMap.get("name").length.toString()); self.newMap.save(null, { success: self.success @@ -257,6 +249,21 @@ Metamaps.GlobalUI.CreateMap = { Metamaps.GlobalUI.closeLightbox(); 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 = $("
"); + + $form.find('#map_name').after(message); + setTimeout(function(){ + message.fadeOut('fast', function(){ + message.remove(); + }); + }, 5000); + }, success: function (model) { var self = Metamaps.GlobalUI.CreateMap; diff --git a/app/assets/javascripts/src/Metamaps.JIT.js b/app/assets/javascripts/src/Metamaps.JIT.js index 4ecda48b..4cb4ea26 100644 --- a/app/assets/javascripts/src/Metamaps.JIT.js +++ b/app/assets/javascripts/src/Metamaps.JIT.js @@ -682,10 +682,16 @@ Metamaps.JIT = { $(document).trigger(Metamaps.JIT.events.mouseMove, [pos]); }, // onMouseMoveHandler enterKeyHandler: function () { + var creatingMap = Metamaps.GlobalUI.lightbox; + if (creatingMap === "newmap" || creatingMap === "forkmap") { + Metamaps.GlobalUI.CreateMap.submit(); + } // this is to submit new topic creation - if (Metamaps.Create.newTopic.beingCreated) { + else if (Metamaps.Create.newTopic.beingCreated) { Metamaps.Topic.createTopicLocally(); - } else if (Metamaps.Create.newSynapse.beingCreated) { + } + // to submit new synapse creation + else if (Metamaps.Create.newSynapse.beingCreated) { Metamaps.Synapse.createSynapseLocally(); } }, //enterKeyHandler diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index a6e71fed..c58e8698 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -2192,6 +2192,16 @@ and it won't be important on password protected instances */ margin: 15px 0 5px; 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 { float: left; width: 100px; diff --git a/app/views/layouts/_newmap.html.erb b/app/views/layouts/_newmap.html.erb index 91c8b4f1..63825b57 100644 --- a/app/views/layouts/_newmap.html.erb +++ b/app/views/layouts/_newmap.html.erb @@ -8,7 +8,7 @@