Commit 0b981eb9 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

coffescript refactoring pt.1

parent 37f3d0f2
@Commit = class Commit
init: -> constructor: ->
$('.files .file').each -> $('.files .file').each ->
new CommitFile(this) new CommitFile(this)
@Commit = Commit
window.dashboardPage = -> class Dashboard
Pager.init 20, true constructor: ->
initSidebarTab() Pager.init 20, true
$(".event_filter_link").bind "click", (event) -> @initSidebarTab()
event.preventDefault()
toggleFilter $(this) $(".event_filter_link").bind "click", (event) =>
reloadActivities() event.preventDefault()
@toggleFilter($(event.currentTarget))
reloadActivities = -> @reloadActivities()
$(".content_list").html ''
Pager.init 20, true reloadActivities: ->
$(".content_list").html ''
toggleFilter = (sender) -> Pager.init 20, true
sender.parent().toggleClass "inactive"
event_filters = $.cookie("event_filter") toggleFilter: (sender) ->
filter = sender.attr("id").split("_")[0] sender.parent().toggleClass "inactive"
if event_filters event_filters = $.cookie("event_filter")
event_filters = event_filters.split(",") filter = sender.attr("id").split("_")[0]
else if event_filters
event_filters = new Array() event_filters = event_filters.split(",")
else
index = event_filters.indexOf(filter) event_filters = new Array()
if index is -1
event_filters.push filter index = event_filters.indexOf(filter)
else if index is -1
event_filters.splice index, 1 event_filters.push filter
else
$.cookie "event_filter", event_filters.join(",") event_filters.splice index, 1
initSidebarTab = -> $.cookie "event_filter", event_filters.join(",")
key = "dashboard_sidebar_filter"
initSidebarTab: ->
# store selection in cookie key = "dashboard_sidebar_filter"
$('.dash-sidebar-tabs a').on 'click', (e) ->
$.cookie(key, $(e.target).attr('id')) # store selection in cookie
$('.dash-sidebar-tabs a').on 'click', (e) ->
# show tab from cookie $.cookie(key, $(e.target).attr('id'))
sidebar_filter = $.cookie(key)
$("#" + sidebar_filter).tab('show') if sidebar_filter # show tab from cookie
sidebar_filter = $.cookie(key)
$("#" + sidebar_filter).tab('show') if sidebar_filter
@Dashboard = Dashboard
...@@ -4,16 +4,27 @@ $ -> ...@@ -4,16 +4,27 @@ $ ->
class Dispatcher class Dispatcher
constructor: () -> constructor: () ->
page = $('body').attr('data-page') page = $('body').attr('data-page')
project_id = $('body').attr('data-project-id')
console.log(page) console.log(page)
path = page.split(':')
switch page switch page
when 'issues:index' then Issues.init() when 'issues:index'
when 'dashboard:show' then dashboardPage() Issues.init()
when 'commit:show' then Commit.init() when 'dashboard:show'
new Dashboard()
when 'commit:show'
new Commit()
when 'groups:show', 'teams:show', 'projects:show' when 'groups:show', 'teams:show', 'projects:show'
Pager.init(20, true) Pager.init(20, true)
when 'projects:new', 'projects:edit' when 'projects:new', 'projects:edit'
new Projects() new Project()
when 'admin:teams:show', 'admin:groups:show', 'admin:logs:show', 'admin:users:new' when 'walls:show'
Admin.init() new Wall(project_id)
switch path.first()
when 'admin' then Admin.init()
when 'wikis' then new Wikis()
class Project
constructor: ->
$('.new_project, .edit_project').on 'ajax:before', ->
$('.project_new_holder, .project_edit_holder').hide()
$('.save-project-loader').show()
$('form #project_default_branch').chosen()
disableButtonIfEmptyField '#project_name', '.project-submit'
$('#project_issues_enabled').change ->
if ($(this).is(':checked') == true)
$('#project_issues_tracker').removeAttr('disabled')
else
$('#project_issues_tracker').attr('disabled', 'disabled')
$('#project_issues_tracker').change()
$('#project_issues_tracker').change ->
if ($(this).val() == gon.default_issues_tracker || $(this).is(':disabled'))
$('#project_issues_tracker_id').attr('disabled', 'disabled')
else
$('#project_issues_tracker_id').removeAttr('disabled')
@Project = Project
$ ->
# Git clone panel switcher
scope = $ '.project_clone_holder'
if scope.length > 0
$('a, button', scope).click ->
$('a, button', scope).removeClass 'active'
$(@).addClass 'active'
$('#project_clone', scope).val $(@).data 'clone'
# Ref switcher
$('.project-refs-select').on 'change', ->
$(@).parents('form').submit()
window.Projects = ->
$('.new_project, .edit_project').on 'ajax:before', ->
$('.project_new_holder, .project_edit_holder').hide()
$('.save-project-loader').show()
$('form #project_default_branch').chosen()
disableButtonIfEmptyField '#project_name', '.project-submit'
$ ->
# Git clone panel switcher
scope = $ '.project_clone_holder'
if scope.length > 0
$('a, button', scope).click ->
$('a, button', scope).removeClass 'active'
$(@).addClass 'active'
$('#project_clone', scope).val $(@).data 'clone'
# Ref switcher
$('.project-refs-select').on 'change', ->
$(@).parents('form').submit()
$('#project_issues_enabled').change ->
if ($(this).is(':checked') == true)
$('#project_issues_tracker').removeAttr('disabled')
else
$('#project_issues_tracker').attr('disabled', 'disabled')
$('#project_issues_tracker').change()
$('#project_issues_tracker').change ->
if ($(this).val() == gon.default_issues_tracker || $(this).is(':disabled'))
$('#project_issues_tracker_id').attr('disabled', 'disabled')
else
$('#project_issues_tracker_id').removeAttr('disabled')
@Wall = class Wall
note_ids: [] constructor: (project_id) ->
project_id: null @project_id = project_id
@note_ids = []
init: (project_id) -> @getContent()
Wall.project_id = project_id @initRefresh()
Wall.getContent() @initForm()
Wall.initRefresh()
Wall.initForm()
# #
# Gets an initial set of notes. # Gets an initial set of notes.
# #
getContent: -> getContent: ->
Api.notes Wall.project_id, (notes) -> Api.notes @project_id, (notes) =>
$.each notes, (i, note) -> $.each notes, (i, note) =>
# render note if it not present in loaded list # render note if it not present in loaded list
# or skip if rendered # or skip if rendered
if $.inArray(note.id, Wall.note_ids) == -1 if $.inArray(note.id, @note_ids) == -1
Wall.note_ids.push(note.id) @note_ids.push(note.id)
Wall.renderNote(note) @renderNote(note)
Wall.scrollDown() @scrollDown()
$("abbr.timeago").timeago() $("abbr.timeago").timeago()
initRefresh: -> initRefresh: ->
setInterval("Wall.refresh()", 10000) setInterval =>
@refresh()
, 10000
refresh: -> refresh: ->
Wall.getContent() @getContent()
scrollDown: -> scrollDown: ->
notes = $('ul.notes') notes = $('ul.notes')
...@@ -36,8 +36,8 @@ ...@@ -36,8 +36,8 @@
form = $('.wall-note-form') form = $('.wall-note-form')
form.find("#target_type").val('wall') form.find("#target_type").val('wall')
form.on 'ajax:success', -> form.on 'ajax:success', =>
Wall.refresh() @refresh()
form.find(".js-note-text").val("").trigger("input") form.find(".js-note-text").val("").trigger("input")
form.on 'ajax:complete', -> form.on 'ajax:complete', ->
...@@ -58,7 +58,7 @@ ...@@ -58,7 +58,7 @@
form.show() form.show()
renderNote: (note) -> renderNote: (note) ->
template = Wall.noteTemplate() template = @noteTemplate()
template = template.replace('{{author_name}}', note.author.name) template = template.replace('{{author_name}}', note.author.name)
template = template.replace('{{created_at}}', note.created_at) template = template.replace('{{created_at}}', note.created_at)
template = template.replace('{{text}}', linkify(sanitize(note.body))) template = template.replace('{{text}}', linkify(sanitize(note.body)))
...@@ -81,3 +81,5 @@ ...@@ -81,3 +81,5 @@
</span> </span>
<abbr class="timeago" title="{{created_at}}">{{created_at}}</abbr> <abbr class="timeago" title="{{created_at}}">{{created_at}}</abbr>
</li>' </li>'
@Wall = Wall
class Wikis
constructor: ->
modal = $('#modal-new-wiki').modal({modal: true, show:false})
$('.add-new-wiki').bind "click", ->
modal.show()
$('.build-new-wiki').bind "click", ->
field = $('#new_wiki_path')
slug = field.val()
path = field.attr('data-wikis-path')
if(slug.length > 0)
location.href = path + "/" + slug
$('.modal-header .close').bind "click", ->
modal.hide()
@Wikis = Wikis
...@@ -7,11 +7,10 @@ ...@@ -7,11 +7,10 @@
:javascript :javascript
var branch_graph; var branch_graph;
$(function(){
branch_graph = new BranchGraph($("#holder"), { branch_graph = new BranchGraph($("#holder"), {
url: '#{project_graph_path(@project, @ref, q: @q, format: :json)}', url: '#{project_graph_path(@project, @ref, q: @q, format: :json)}',
commit_url: '#{project_commit_path(@project, 'ae45ca32').gsub("ae45ca32", "%s")}', commit_url: '#{project_commit_path(@project, 'ae45ca32').gsub("ae45ca32", "%s")}',
ref: '#{@ref}', ref: '#{@ref}',
commit_id: '#{@commit.id}' commit_id: '#{@commit.id}'
});
}); });
!!! 5 !!! 5
%html{ lang: "en"} %html{ lang: "en"}
= render "layouts/head", title: @project.name_with_namespace = render "layouts/head", title: @project.name_with_namespace
%body{class: "#{app_theme} project", :'data-page' => body_data_page} %body{class: "#{app_theme} project", :'data-page' => body_data_page, :'data-project-id' => @project.id }
= render "layouts/head_panel", title: project_title(@project) = render "layouts/head_panel", title: project_title(@project)
= render "layouts/flash" = render "layouts/flash"
- if can?(current_user, :download_code, @project) - if can?(current_user, :download_code, @project)
......
...@@ -26,14 +26,12 @@ ...@@ -26,14 +26,12 @@
:javascript :javascript
var merge_request; var merge_request;
$(function(){
merge_request = new MergeRequest({
url_to_automerge_check: "#{automerge_check_project_merge_request_path(@project, @merge_request)}",
check_enable: #{@merge_request.unchecked? ? "true" : "false"},
url_to_ci_check: "#{ci_status_project_merge_request_path(@project, @merge_request)}",
ci_enable: #{@project.gitlab_ci? ? "true" : "false"},
current_status: "#{@merge_request.merge_status_name}",
action: "#{controller.action_name}"
});
});
merge_request = new MergeRequest({
url_to_automerge_check: "#{automerge_check_project_merge_request_path(@project, @merge_request)}",
check_enable: #{@merge_request.unchecked? ? "true" : "false"},
url_to_ci_check: "#{ci_status_project_merge_request_path(@project, @merge_request)}",
ci_enable: #{@project.gitlab_ci? ? "true" : "false"},
current_status: "#{@merge_request.merge_status_name}",
action: "#{controller.action_name}"
});
...@@ -21,8 +21,3 @@ ...@@ -21,8 +21,3 @@
.hint.pull-right CTRL + Enter to send message .hint.pull-right CTRL + Enter to send message
.clearfix .clearfix
:javascript
$(function(){
Wall.init(#{@project.id});
});
...@@ -5,27 +5,8 @@ ...@@ -5,27 +5,8 @@
.modal-body .modal-body
= label_tag :new_wiki_path do = label_tag :new_wiki_path do
%span Page slug %span Page slug
= text_field_tag :new_wiki_path, nil, placeholder: 'how-to-setup', class: 'input-xlarge', required: true = text_field_tag :new_wiki_path, nil, placeholder: 'how-to-setup', class: 'input-xlarge', required: true, :'data-wikis-path' => project_wikis_path(@project)
%p.hint %p.hint
Please dont use spaces and slashes Please dont use spaces and slashes
.modal-footer .modal-footer
= link_to 'Build', '#', class: 'build-new-wiki btn btn-create' = link_to 'Build', '#', class: 'build-new-wiki btn btn-create'
:javascript
$(function(){
var modal = $('#modal-new-wiki').modal({modal: true, show:false});
$('.add-new-wiki').bind("click", function(){
modal.show();
});
$('.build-new-wiki').bind("click", function(){
var slug = $('#new_wiki_path').val();
if(slug.length > 0) {
location.href = "#{project_wikis_path(@project)}/" + slug;
}
});
$('.modal-header .close').bind("click", function(){
modal.hide();
})
})
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment