Skip to content

Commit

Permalink
Fixed bunch of js bugs with comments. Also added development tips
Browse files Browse the repository at this point in the history
  • Loading branch information
dzaporozhets committed Aug 30, 2012
1 parent 92137b7 commit 4a6596a
Show file tree
Hide file tree
Showing 12 changed files with 281 additions and 212 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -39,5 +39,6 @@ Email


## Contribute ## Contribute


[Development Tips](https://github.com/gitlabhq/gitlabhq/blob/master/doc/development.md)
Want to help - send a pull request. Want to help - send a pull request.
We'll accept good pull requests. We'll accept good pull requests.
20 changes: 20 additions & 0 deletions app/assets/javascripts/application.js
Expand Up @@ -128,3 +128,23 @@ function showDiff(link) {
function ajaxGet(url) { function ajaxGet(url) {
$.ajax({type: "GET", url: url, dataType: "script"}); $.ajax({type: "GET", url: url, dataType: "script"});
} }

/**
* Disable button if text field is empty
*/
function disableButtonIfEmtpyField(field_selector, button_selector) {
field = $(field_selector);
if(field.val() == "") {
field.closest("form").find(button_selector).attr("disabled", "disabled").addClass("disabled");
}

field.on('keyup', function(){
var field = $(this);
var closest_submit = field.closest("form").find(button_selector);
if(field.val() == "") {
closest_submit.attr("disabled", "disabled").addClass("disabled");
} else {
closest_submit.removeAttr("disabled").removeClass("disabled");
}
})
}
274 changes: 137 additions & 137 deletions app/assets/javascripts/note.js
@@ -1,174 +1,160 @@
var NoteList = { var NoteList = {


notes_path: null, notes_path: null,
target_params: null, target_params: null,
target_id: 0, target_id: 0,
target_type: null, target_type: null,
first_id: 0, first_id: 0,
last_id: 0, last_id: 0,
disable:false, disable:false,


init: init:
function(tid, tt, path) { function(tid, tt, path) {
this.notes_path = path + ".js"; this.notes_path = path + ".js";
this.target_id = tid; this.target_id = tid;
this.target_type = tt; this.target_type = tt;
this.target_params = "&target_type=" + this.target_type + "&target_id=" + this.target_id; this.target_params = "&target_type=" + this.target_type + "&target_id=" + this.target_id;


// get notes // get notes
this.getContent(); this.getContent();


// get new notes every n seconds // get new notes every n seconds
this.initRefresh(); this.initRefresh();


$('.delete-note').live('ajax:success', function() { $('.delete-note').live('ajax:success', function() {
$(this).closest('li').fadeOut(); }); $(this).closest('li').fadeOut(); });


$('#note_note').on('keyup', function(){ $(".note-form-holder").live("ajax:before", function(){
var field = $(this); $(".submit_note").attr("disabled", "disabled");
var closest_submit = field.closest("form").find(".submit_note"); })
if(field.val() == "") {
closest_submit.attr("disabled", "disabled").addClass("disabled"); $(".note-form-holder").live("ajax:complete", function(){
} else { $(".submit_note").removeAttr("disabled");
closest_submit.removeAttr("disabled").removeClass("disabled"); })
}
}) disableButtonIfEmtpyField(".note-text", ".submit_note");


$("#new_note").live("ajax:before", function(){ $(".note-text").live("focus", function(){
$(".submit_note").attr("disabled", "disabled"); $(this).css("height", "80px");
}) $('.note_advanced_opts').show();

});
$("#new_note").live("ajax:complete", function(){
$(".submit_note").removeAttr("disabled"); $("#note_attachment").change(function(e){
})

$("#note_note").live("focus", function(){
$(this).css("height", "80px");
$('.note_advanced_opts').show();
if($(this).val() == "") {
$(this).closest("form").find(".submit_note").attr("disabled", "disabled").addClass("disabled");
}
});

$("#note_attachment").change(function(e){
var val = $('.input-file').val(); var val = $('.input-file').val();
var filename = val.replace(/^.*[\\\/]/, ''); var filename = val.replace(/^.*[\\\/]/, '');
$(".file_name").text(filename); $(".file_name").text(filename);
}); });


}, },




/** /**
* Load new notes to fresh list called 'new_notes_list': * Load new notes to fresh list called 'new_notes_list':
* - Replace 'new_notes_list' with new list every n seconds * - Replace 'new_notes_list' with new list every n seconds
* - Append new notes to this list after submit * - Append new notes to this list after submit
*/ */


initRefresh: initRefresh:
function() { function() {
// init timer // init timer
var intNew = setInterval("NoteList.getNew()", 10000); var intNew = setInterval("NoteList.getNew()", 10000);
}, },


replace: replace:
function(html) { function(html) {
$("#new_notes_list").html(html); $("#new_notes_list").html(html);
}, },


prepend: prepend:
function(id, html) { function(id, html) {
if(id != this.last_id) { if(id != this.last_id) {
$("#new_notes_list").prepend(html); $("#new_notes_list").prepend(html);
} }
}, },


getNew: getNew:
function() { function() {
// refersh notes list // refersh notes list
$.ajax({ $.ajax({
type: "GET", type: "GET",
url: this.notes_path, url: this.notes_path,
data: "last_id=" + this.last_id + this.target_params, data: "last_id=" + this.last_id + this.target_params,
dataType: "script"}); dataType: "script"});
}, },


refresh: refresh:
function() { function() {
// refersh notes list // refersh notes list
$.ajax({ $.ajax({
type: "GET", type: "GET",
url: this.notes_path, url: this.notes_path,
data: "first_id=" + this.first_id + "&last_id=" + this.last_id + this.target_params, data: "first_id=" + this.first_id + "&last_id=" + this.last_id + this.target_params,
dataType: "script"}); dataType: "script"});
}, },




/** /**
* Init load of notes: * Init load of notes:
* 1. Get content with ajax call * 1. Get content with ajax call
* 2. Set content of notes list with loaded one * 2. Set content of notes list with loaded one
*/ */




getContent: getContent:
function() { function() {
$.ajax({ $.ajax({
type: "GET", type: "GET",
url: this.notes_path, url: this.notes_path,
data: "?" + this.target_params, data: "?" + this.target_params,
complete: function(){ $('.status').removeClass("loading")}, complete: function(){ $('.status').removeClass("loading")},
beforeSend: function() { $('.status').addClass("loading") }, beforeSend: function() { $('.status').addClass("loading") },
dataType: "script"}); dataType: "script"});
}, },


setContent: setContent:
function(fid, lid, html) { function(fid, lid, html) {
this.last_id = lid; this.last_id = lid;
this.first_id = fid; this.first_id = fid;
$("#notes-list").html(html); $("#notes-list").html(html);


// Init infinite scrolling // Init infinite scrolling
this.initLoadMore(); this.initLoadMore();
}, },




/** /**
* Paging for old notes when scroll to bottom: * Paging for old notes when scroll to bottom:
* 1. Init scroll events with 'initLoadMore' * 1. Init scroll events with 'initLoadMore'
* 2. Load onlder notes with 'getOld' method * 2. Load onlder notes with 'getOld' method
* 3. append old notes to bottom of list with 'append' * 3. append old notes to bottom of list with 'append'
* *
*/ */

getOld:

function() {
getOld: $('.loading').show();
function() { $.ajax({
$('.loading').show(); type: "GET",
$.ajax({ url: this.notes_path,
type: "GET", data: "first_id=" + this.first_id + this.target_params,
url: this.notes_path, complete: function(){ $('.status').removeClass("loading")},
data: "first_id=" + this.first_id + this.target_params, beforeSend: function() { $('.status').addClass("loading") },
complete: function(){ $('.status').removeClass("loading")}, dataType: "script"});
beforeSend: function() { $('.status').addClass("loading") }, },
dataType: "script"});
}, append:

function(id, html) {
append: if(this.first_id == id) {
function(id, html) { this.disable = true;
if(this.first_id == id) { } else {
this.disable = true; this.first_id = id;
} else { $("#notes-list").append(html);
this.first_id = id; }
$("#notes-list").append(html); },
}
},



initLoadMore: initLoadMore:
function() { function() {
$(document).endlessScroll({ $(document).endlessScroll({
bottomPixels: 400, bottomPixels: 400,
fireDelay: 1000, fireDelay: 1000,
fireOnce:true, fireOnce:true,
ceaseFire: function() { ceaseFire: function() {
Expand All @@ -177,6 +163,20 @@ initLoadMore:
callback: function(i) { callback: function(i) {
NoteList.getOld(); NoteList.getOld();
} }
}); });
} }
};

var PerLineNotes = {
init:
function() {
$(".line_note_link, .line_note_reply_link").live("click", function(e) {
var form = $(".per_line_form");
$(this).closest("tr").after(form);
form.find("#note_line_code").val($(this).attr("line_code"));
form.show();
return false;
});
disableButtonIfEmtpyField(".line-note-text", ".submit_inline_note");
}
} }
2 changes: 1 addition & 1 deletion app/assets/stylesheets/sections/notes.scss
Expand Up @@ -30,7 +30,7 @@
} }


#new_note { #new_note {
#note_note { .note-text {
height:25px; height:25px;
} }
.attach_holder { .attach_holder {
Expand Down
10 changes: 2 additions & 8 deletions app/views/commits/show.html.haml
Expand Up @@ -5,12 +5,6 @@




:javascript :javascript
$(document).ready(function(){ $(function(){
$(".line_note_link, .line_note_reply_link").live("click", function(e) { PerLineNotes.init();
var form = $(".per_line_form");
$(this).parent().parent().after(form);
form.find("#note_line_code").val($(this).attr("line_code"));
form.show();
return false;
});
}); });
11 changes: 6 additions & 5 deletions app/views/notes/_create_common.js.haml
@@ -1,11 +1,12 @@
- if note.valid? - if note.valid?
:plain :plain
$("#new_note .error").remove(); $(".note-form-holder .error").remove();
$('#new_note textarea').val(""); $('.note-form-holder textarea').val("");
$('#preview-link').text('Preview'); $('.note-form-holder #preview-link').text('Preview');
$('#preview-note').hide(); $('#note_note').show(); $('.note-form-holder #preview-note').hide();
$('.note-form-holder').show();
NoteList.prepend(#{note.id}, "#{escape_javascript(render partial: "notes/show", locals: {note: note})}"); NoteList.prepend(#{note.id}, "#{escape_javascript(render partial: "notes/show", locals: {note: note})}");
- else - else
:plain :plain
$("#new_note").replaceWith("#{escape_javascript(render('form'))}"); $(".note-form-holder").replaceWith("#{escape_javascript(render('form'))}");


0 comments on commit 4a6596a

Please sign in to comment.