From 6182ba4e1459bc073bcf8996d8b4b798359cb8a8 Mon Sep 17 00:00:00 2001 From: Shai Date: Sun, 10 Aug 2014 16:52:49 -0400 Subject: [PATCH] data validation --- .../javascripts/metamaps/Metamaps.GlobalUI.js | 15 +- app/views/maps/show.html.erb~ | 133 +++++++++ db/schema.rb | 258 +++++++++--------- 3 files changed, 275 insertions(+), 131 deletions(-) create mode 100644 app/views/maps/show.html.erb~ diff --git a/app/assets/javascripts/metamaps/Metamaps.GlobalUI.js b/app/assets/javascripts/metamaps/Metamaps.GlobalUI.js index 12f9e6ea..c7551761 100644 --- a/app/assets/javascripts/metamaps/Metamaps.GlobalUI.js +++ b/app/assets/javascripts/metamaps/Metamaps.GlobalUI.js @@ -229,13 +229,24 @@ 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()); // 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.'); + return; + } + //console.log('self.newMap.get("name").length='+self.newMap.get("name").length.toString()); + self.newMap.save(null, { success: self.success // TODO add error message diff --git a/app/views/maps/show.html.erb~ b/app/views/maps/show.html.erb~ new file mode 100644 index 00000000..474a6c1a --- /dev/null +++ b/app/views/maps/show.html.erb~ @@ -0,0 +1,133 @@ +<%# + # @file + # Code to display a map + # /maps/:id + #%> + +<% content_for :title, @map.name + " | Metamaps" %> + +
+ +
+ + +<% if authenticated? %> + <% if @map.permission == "commons" || @map.user == user %> +
+
+
Save Layout
+
+
+
+ <% end %> +
+
+
Save To New Map
+
+
+
+ <% if @map.permission == "commons" || @map.user == user %> +
+
+
+

Realtime:

+ OFF +
+
+
    +
  • + <%= user.name %> (me) +
  • +
+
+
+
+ <% end %> +<% end %> +
+
+
+

Filter By Metacode

allnone +
+ <%= render :partial => 'main/filterbymetacode' %> +
+
+ +
+
+ + <%= @map.name %> + +
+ <%= render :partial => 'maps/mapinfobox' %> +
+ +
+
+
+
+
+
+
+ +<% if authenticated? %> + + <% # add these if you have edit permissions on the map %> + <% if @map.permission == "commons" || @map.user == user %> + + <% # for creating and pulling in topics and synapses %> + <%= render :partial => 'newtopic' %> + <%= render :partial => 'newsynapse' %> + + <% # for saving the layout of the map %> + <%= form_for @map, :url => savelayout_path(@map), :html => { :class => "saveMapLayout", :id => "saveMapLayout"}, remote: true do |form| %> + <%= form.hidden_field "coordinates", :value => "" %> + <% end %> + + <% end %> + + <% # for populating the change metacode list on the topic card %> + <%= render :partial => 'main/metacodeoptions' %> +<% end %> + + + \ No newline at end of file diff --git a/db/schema.rb b/db/schema.rb index c3fce2b2..ec86b421 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -1,129 +1,129 @@ -# encoding: UTF-8 -# This file is auto-generated from the current state of the database. Instead -# of editing this file, please use the migrations feature of Active Record to -# incrementally modify your database, and then regenerate this schema definition. -# -# Note that this schema.rb definition is the authoritative source for your -# database schema. If you need to create the application database on another -# system, you should be using db:schema:load, not running all the migrations -# from scratch. The latter is a flawed and unsustainable approach (the more migrations -# you'll amass, the slower it'll run and the greater likelihood for issues). -# -# It's strongly recommended to check this file into your version control system. - -ActiveRecord::Schema.define(:version => 20140707161810) do - - create_table "in_metacode_sets", :force => true do |t| - t.integer "metacode_id" - t.integer "metacode_set_id" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false - end - - add_index "in_metacode_sets", ["metacode_id"], :name => "index_in_metacode_sets_on_metacode_id" - add_index "in_metacode_sets", ["metacode_set_id"], :name => "index_in_metacode_sets_on_metacode_set_id" - - create_table "mappings", :force => true do |t| - t.text "category" - t.integer "xloc" - t.integer "yloc" - t.integer "topic_id" - t.integer "synapse_id" - t.integer "map_id" - t.integer "user_id" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false - end - - create_table "maps", :force => true do |t| - t.text "name" - t.boolean "arranged" - t.text "desc" - t.text "permission" - t.integer "user_id" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false - t.boolean "featured" - end - - create_table "metacode_sets", :force => true do |t| - t.string "name" - t.text "desc" - t.integer "user_id" - t.boolean "mapperContributed" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false - end - - add_index "metacode_sets", ["user_id"], :name => "index_metacode_sets_on_user_id" - - create_table "metacodes", :force => true do |t| - t.text "name" - t.string "icon" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false - end - - create_table "synapses", :force => true do |t| - t.text "desc" - t.text "category" - t.text "weight" - t.text "permission" - t.integer "node1_id" - t.integer "node2_id" - t.integer "user_id" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false - end - - create_table "topics", :force => true do |t| - t.text "name" - t.text "desc" - t.text "link" - t.text "permission" - t.integer "user_id" - t.integer "metacode_id" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false - t.string "image_file_name" - t.string "image_content_type" - t.integer "image_file_size" - t.datetime "image_updated_at" - t.string "audio_file_name" - t.string "audio_content_type" - t.integer "audio_file_size" - t.datetime "audio_updated_at" - end - - create_table "users", :force => true do |t| - t.string "name" - t.string "email" - t.text "settings" - t.string "code", :limit => 8 - t.string "joinedwithcode", :limit => 8 - t.string "crypted_password" - t.string "password_salt" - t.string "persistence_token" - t.string "perishable_token" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false - t.string "encrypted_password", :limit => 128, :default => "" - t.string "remember_token" - t.datetime "remember_created_at" - t.string "reset_password_token" - t.datetime "last_sign_in_at" - t.string "last_sign_in_ip" - t.integer "sign_in_count", :default => 0 - t.datetime "current_sign_in_at" - t.string "current_sign_in_ip" - t.datetime "reset_password_sent_at" - t.boolean "admin" - t.string "image_file_name" - t.string "image_content_type" - t.integer "image_file_size" - t.datetime "image_updated_at" - end - - add_index "users", ["reset_password_token"], :name => "index_users_on_reset_password_token", :unique => true - -end +# encoding: UTF-8 +# This file is auto-generated from the current state of the database. Instead +# of editing this file, please use the migrations feature of Active Record to +# incrementally modify your database, and then regenerate this schema definition. +# +# Note that this schema.rb definition is the authoritative source for your +# database schema. If you need to create the application database on another +# system, you should be using db:schema:load, not running all the migrations +# from scratch. The latter is a flawed and unsustainable approach (the more migrations +# you'll amass, the slower it'll run and the greater likelihood for issues). +# +# It's strongly recommended to check this file into your version control system. + +ActiveRecord::Schema.define(:version => 20140707161810) do + + create_table "in_metacode_sets", :force => true do |t| + t.integer "metacode_id" + t.integer "metacode_set_id" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + end + + add_index "in_metacode_sets", ["metacode_id"], :name => "index_in_metacode_sets_on_metacode_id" + add_index "in_metacode_sets", ["metacode_set_id"], :name => "index_in_metacode_sets_on_metacode_set_id" + + create_table "mappings", :force => true do |t| + t.text "category" + t.integer "xloc" + t.integer "yloc" + t.integer "topic_id" + t.integer "synapse_id" + t.integer "map_id" + t.integer "user_id" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + end + + create_table "maps", :force => true do |t| + t.text "name" + t.boolean "arranged" + t.text "desc" + t.text "permission" + t.integer "user_id" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + t.boolean "featured" + end + + create_table "metacode_sets", :force => true do |t| + t.string "name" + t.text "desc" + t.integer "user_id" + t.boolean "mapperContributed" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + end + + add_index "metacode_sets", ["user_id"], :name => "index_metacode_sets_on_user_id" + + create_table "metacodes", :force => true do |t| + t.text "name" + t.string "icon" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + end + + create_table "synapses", :force => true do |t| + t.text "desc" + t.text "category" + t.text "weight" + t.text "permission" + t.integer "node1_id" + t.integer "node2_id" + t.integer "user_id" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + end + + create_table "topics", :force => true do |t| + t.text "name" + t.text "desc" + t.text "link" + t.text "permission" + t.integer "user_id" + t.integer "metacode_id" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + t.string "image_file_name" + t.string "image_content_type" + t.integer "image_file_size" + t.datetime "image_updated_at" + t.string "audio_file_name" + t.string "audio_content_type" + t.integer "audio_file_size" + t.datetime "audio_updated_at" + end + + create_table "users", :force => true do |t| + t.string "name" + t.string "email" + t.text "settings" + t.string "code", :limit => 8 + t.string "joinedwithcode", :limit => 8 + t.string "crypted_password" + t.string "password_salt" + t.string "persistence_token" + t.string "perishable_token" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + t.string "encrypted_password", :limit => 128, :default => "" + t.string "remember_token" + t.datetime "remember_created_at" + t.string "reset_password_token" + t.datetime "last_sign_in_at" + t.string "last_sign_in_ip" + t.integer "sign_in_count", :default => 0 + t.datetime "current_sign_in_at" + t.string "current_sign_in_ip" + t.datetime "reset_password_sent_at" + t.boolean "admin" + t.string "image_file_name" + t.string "image_content_type" + t.integer "image_file_size" + t.datetime "image_updated_at" + end + + add_index "users", ["reset_password_token"], :name => "index_users_on_reset_password_token", :unique => true + +end