Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 4bdcb02da4
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 137 lines (90 sloc) 2.676 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
RailsBackboneRelational.Views.Comments ||= {}

class RailsBackboneRelational.Views.Comments.CommentView extends Backbone.View
  template: JST["backbone/templates/comments/comment"]
 
  
  this.log = _.bind(alert, console);


  events:
    "click .destroy" : "destroy"
    "dblclick .todo-array button": "push_index"

    "click .todo-array button": "whiteSpaceCheck"

    "click .direction" : "toggleDone"
    "click .save" : "save_array"

    "blur .seconds" : "set_delay"
    
    #"hover .todo-array button": "show_tooltip"

  initialize: () ->
   @status = 'saved'
   @seconds = 10
   this.model.bind('change', this.before_render);
 
  before_render:() =>
    @status = 'saved'
    @render()
  
    
  get_array: () ->
    @model.array

  className: 'sspann'

  tagName: "td"

  toggleDone : () ->
    @model.save(
    
      direction : !this.model.get('direction')
    )


    

  destroy: () ->
    @model.destroy()
    this.remove()

    return false



  render: =>
    listed2 = this.splitted2()
    
    comment = @model.toJSON()
    status = @status.toString()
    seconds = @seconds.toString()
   
    console.log(comment)
    tmp = @template(
      'obj': comment
      'listed2': listed2
      'obj2': status
      'obj3': seconds
    )
    $(@el).html(tmp)
    
    return this
  
 
  splitted2: ->
    arr0 = @get_array()
    list = "<% _.each(people, function(name) { %> <button class='btn btn-info btn-block test'><%= name %></button> <% }); %>";
    arr = _.template(list, {people : arr0});
    #console.log(arr)
    arr
 
  show_tooltip: (ev) ->
    num = $(ev.target).index()
    #$(@el).popover({title: 'im the title'})
    alert(num)
   
        
  push_index: (ev) ->
    item = $(ev.target)
    num =(item).index()
    array = @get_array()
    array[num...num] = ['=']
    @array = array
    #@update_status('true')
    @status = 'not saved!'
    @render()
  
  update_status2: (sign) ->
    item = @$('.save')
    console.log(item)
    if(sign)
     $(item).attr('value', 'not Saved');
    else
     
     $(item).attr('background', '#000fff');
     $(item).attr('value', 'Saved');


  save_array: () ->
    text = @get_array().join("")
    @model.save(
     content: text
    )
    

  
  whiteSpaceCheck: (ev) ->
    item = ev.target
    str = $(item).context.innerText
    if(str != '=')
     _.delay(_.bind(this.something, item), @seconds * 1000 , 'logged later')
     $(item).toggleClass("test1")
    else
     @push_index(ev)
  
  something: (msg) ->
     $(this).toggleClass("test1")
  
  set_delay: (ev) ->
    @seconds = ev.target.value
    console.log(@seconds)
   


        
Something went wrong with that request. Please try again.