| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298 |
- require [
- "tags"
- "moment"
- "event_tracking"
- "gui"
- "libs/underscore"
- "libs/fineuploader"
- "libs/jquery.storage"
- "UserDetailsUpdater"
- ], (tagsManager, moment)->
- $('.isoDate').each (i, d)->
- html = $(d)
- unparsedDate = html.text().trim()
- formatedDate = moment(unparsedDate).format("Do MMM YYYY, h:mm:ss a")
- html.text(formatedDate)
- refreshProjectFilter = ->
- words = $('#projectFilter').val().split(" ")
- words = _.filter words, (word)->
- word.length > 0
- projects = $('.project_entry')
- _.each projects, (project)->
- name = $(project).find(".projectName").text()
- tagsText = $(project).find(".project-tags").text()
- searchText = "#{name} #{tagsText}".toLowerCase()
- hide = false
- _.each words, (word)->
- if searchText.indexOf(word.toLowerCase()) == -1
- hide = true
- if hide
- $(project).hide()
- else
- $(project).show()
- $('#projectFilter').on "keyup", (e)->
- if(e.keyCode == 13)
- e.preventDefault()
- refreshProjectFilter()
- $('.search .icon-remove').on 'click', (e)->
- $('#projectFilter').val("").focus()
- refreshProjectFilter()
- $('body').on 'click', '.tag-label .text', (event)->
- event.preventDefault()
- event.stopPropagation()
- tag = $(event.target).text()
- $('input#projectFilter').val(tag).focus()
- refreshProjectFilter()
- $('.deleteProject').click (event)->
- event.preventDefault()
- $modal = $('#deleteEntityModal')
- $confirm = $modal.find('.confirm')
- $modal.modal({backdrop:true, show:true, keyboard:true})
- name = $(@).data("name")
- id = $(@).data("id")
- $modal.find(".name").text(name)
- href = this.href
- self = @
- $confirm.on 'click', (e) =>
- $.ajax
- url: href
- type:'DELETE'
- data:
- _csrf: $(@).data("csrf")
- success: (data)->
- $modal.modal('hide')
- if data.message
- new Message data
- else
- $("##{id}").fadeOut(1000)
- $modal.on 'hide', ->
- $confirm.off 'click'
- $modal.find('.cancel').click (e)->
- $modal.modal('hide')
- $('.archiveProject').click (event)->
- event.preventDefault()
- $modal = $('#archiveEntityModal')
- $confirm = $modal.find('.confirm')
- $modal.modal({backdrop:true, show:true, keyboard:true})
- name = $(@).data("name")
- id = $(@).data("id")
- $modal.find(".name").text(name)
- href = this.href
- self = @
- $confirm.on 'click', (e) =>
- $.ajax
- url: href
- type:'DELETE'
- data:
- _csrf: $(@).data("csrf")
- success: (data)->
- $modal.modal('hide')
- if data.message
- new Message data
- else
- $("##{id}").fadeOut(1000)
- $modal.on 'hide', ->
- $confirm.off 'click'
- $modal.find('.cancel').click (e)->
- $modal.modal('hide')
- $('.renameProject').click (event)->
- event.preventDefault()
- $modal = $('#renameProjectModal')
- $confirm = $modal.find('#confirmRename')
- $modal.modal({backdrop:true, show:true, keyboard:true})
- name = $(@).data("name")
- nameEl = $modal.find("#projectNewName").val(name)
- nameEl.select()
- href = this.href
- self = @
- window.r = @
- $confirm.on 'click', (e) =>
- newProjectName = nameEl.val()
- $.ajax
- url: href
- type:'POST'
- data:
- _csrf: $(@).data("csrf")
- newProjectName:newProjectName
- success: (data)->
- $modal.modal('hide')
- if data.message
- new Message data
- else
- $(self.parentNode.parentNode.parentNode.parentNode).find(".projectName").text(newProjectName)
- $(self.parentNode.parentNode).find("li a").each ()->
- $(this).data('name', newProjectName)
- $modal.on 'hide', ->
- $confirm.off 'click'
- $modal.find('.cancel').click (e)->
- $modal.modal('hide')
- $(".leaveProject").click (event) ->
- event.preventDefault()
- $modal = $('#leaveProjectModal')
- $confirm = $modal.find('.confirm')
- $modal.modal({backdrop:true, show:true, keyboard:true})
- name = $(@).data("name")
- id = $(@).data("id")
- nameEl = $modal.find(".name").text(name)
- href = this.href
- self = @
- $confirm.on 'click', (e)=>
- $.ajax
- url: href
- type: 'POST'
- data:
- _csrf: $(@).data("csrf")
- success: (data)->
- $modal.modal('hide')
- if data.message
- new Message data
- else
- $("##{id}").fadeOut(1000)
- $modal.on 'hide', ->
- $confirm.off 'click'
- $modal.find('.cancel').click (e)->
- $modal.modal('hide')
- $('.cloneProject').click (event)->
- event.preventDefault()
- $modal = $('#cloneProjectModal')
- $confirm = $('#confirmCloneProject')
- $modal.modal({backdrop:true, show:true, keyboard:true})
- $modal.find('input').val('').focus()
- href = this.href
- $confirm.click (e)=>
- $confirm.attr("disabled", true)
- $confirm.text("Cloning...")
- projectName = $modal.find('input').val()
- $.ajax
- url: href
- type:'POST'
- data:
- projectName: projectName
- _csrf: $(@).data("csrf")
- success: (data)->
- if data.redir?
- window.location = data.redir
- else if data.project_id?
- window.location = '/project/'+data.project_id
- $modal.on 'hide', ->
- $confirm.off 'click'
- $modal.find('.cancel').click (e)->
- $modal.modal('hide')
- $('.restoreProject').click (event) ->
- event.preventDefault()
- id = $(@).data("id")
- $.ajax
- url: @href
- type: 'POST'
- data:
- _csrf: $(@).data("csrf")
- success: (data)->
- $("##{id}").fadeOut(1000)
- newProject = (template, fileToOpen) ->
- $modal = $('#newProjectModal')
- $confirm = $('#confirmNewProject')
- $modal.modal({backdrop:true, show:true, keyboard:true})
- $modal.find('input').val('').focus()
- $confirm.click (e) =>
- $confirm.attr("disabled", true)
- $confirm.text("Creating...")
- projectName = $modal.find('input').val()?.trim()
- $.ajax
- url: '/project/new'
- type:'POST'
- data:{projectName: projectName, template: template, _csrf: $(@).data("csrf")}
- success: (data)->
- if data.message
- new Message data
- else
- window.location = '/project/'+data.project_id + (if fileToOpen? then ("#" + fileToOpen) else "")
- $modal.on 'hide', ->
- $confirm.off 'click'
- $modal.find('.cancel').click (e)->
- $modal.modal('hide')
-
- $('#blankNewProject').click (event)->
- newProject.call(@, 'none')
- $('#newProjectExample').click (event)->
- newProject.call(@, 'example')
- $('#newProjectVisual').click (event)->
- newProject.call(@, 'visual', 'main.tex')
- $('#uploadNewProject').click (event)->
- event.preventDefault()
-
- $modal = $('#projectUploadModal')
- $modal.modal({backdrop:true, show:true, keyboard:true})
- new qq.FineUploader
- element: document.getElementById('projectFileUpload')
- multiple: false
- disabledCancelForFormUploads: true
- validation:
- allowedExtensions: ["zip"]
- request:
- endpoint: "/project/new/upload"
- forceMultipart: true
- params:
- _csrf: $(@).data("csrf")
- callbacks:
- onComplete: (error, name, response)->
- if response.project_id?
- window.location = '/project/'+response.project_id
- text:
- waitingForResponse: "Creating project..."
- failUpload: "Upload failed. Is it a valid zip file?"
- uploadButton: "Select a .zip file"
- template: """
- <div class="qq-uploader">
- <div class="qq-upload-drop-area"><span>{dragZoneText}</span></div>
- <div class="qq-upload-button btn btn-primary btn-large">
- <div>{uploadButtonText}</div>
- </div>
- <span class="or btn-large"> or </span>
- <span class="drag-here btn-large">drag a .zip file</span>
- <span class="qq-drop-processing"><span>{dropProcessingText}</span><span class="qq-drop-processing-spinner"></span></span>
- <ul class="qq-upload-list"></ul>
- </div>
- """
- $modal.find('.cancel').click (e)->
- $modal.modal('hide')
-
- sysMsgKey = "dismiss-system-message-090114"
- if $.localStorage(sysMsgKey)
- $("#systemMessage").hide()
- else
- $("#systemMessage").show()
- $("a#dismissSystemMessage").on "click", (e) ->
- e.preventDefault()
- $("#systemMessage").hide()
- $.localStorage(sysMsgKey, true)
|