Permalink
Browse files

Fixed bunch of js bugs with comments. Also added development tips

  • Loading branch information...
dzaporozhets committed Aug 30, 2012
1 parent 92137b7 commit 4a6596af274c01036aaf9f49a5b38cd678716873
View
@@ -39,5 +39,6 @@ Email
## Contribute
+[Development Tips](https://github.com/gitlabhq/gitlabhq/blob/master/doc/development.md)
Want to help - send a pull request.
We'll accept good pull requests.
@@ -128,3 +128,23 @@ function showDiff(link) {
function ajaxGet(url) {
$.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");
+ }
+ })
+}
@@ -1,174 +1,160 @@
var NoteList = {
-notes_path: null,
-target_params: null,
-target_id: 0,
-target_type: null,
-first_id: 0,
-last_id: 0,
-disable:false,
-
-init:
- function(tid, tt, path) {
- this.notes_path = path + ".js";
- this.target_id = tid;
- this.target_type = tt;
- this.target_params = "&target_type=" + this.target_type + "&target_id=" + this.target_id;
-
- // get notes
- this.getContent();
-
- // get new notes every n seconds
- this.initRefresh();
-
- $('.delete-note').live('ajax:success', function() {
- $(this).closest('li').fadeOut(); });
-
- $('#note_note').on('keyup', function(){
- var field = $(this);
- var closest_submit = field.closest("form").find(".submit_note");
- if(field.val() == "") {
- closest_submit.attr("disabled", "disabled").addClass("disabled");
- } else {
- closest_submit.removeAttr("disabled").removeClass("disabled");
- }
- })
-
- $("#new_note").live("ajax:before", function(){
- $(".submit_note").attr("disabled", "disabled");
- })
-
- $("#new_note").live("ajax:complete", function(){
- $(".submit_note").removeAttr("disabled");
- })
-
- $("#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){
+ notes_path: null,
+ target_params: null,
+ target_id: 0,
+ target_type: null,
+ first_id: 0,
+ last_id: 0,
+ disable:false,
+
+ init:
+ function(tid, tt, path) {
+ this.notes_path = path + ".js";
+ this.target_id = tid;
+ this.target_type = tt;
+ this.target_params = "&target_type=" + this.target_type + "&target_id=" + this.target_id;
+
+ // get notes
+ this.getContent();
+
+ // get new notes every n seconds
+ this.initRefresh();
+
+ $('.delete-note').live('ajax:success', function() {
+ $(this).closest('li').fadeOut(); });
+
+ $(".note-form-holder").live("ajax:before", function(){
+ $(".submit_note").attr("disabled", "disabled");
+ })
+
+ $(".note-form-holder").live("ajax:complete", function(){
+ $(".submit_note").removeAttr("disabled");
+ })
+
+ disableButtonIfEmtpyField(".note-text", ".submit_note");
+
+ $(".note-text").live("focus", function(){
+ $(this).css("height", "80px");
+ $('.note_advanced_opts').show();
+ });
+
+ $("#note_attachment").change(function(e){
var val = $('.input-file').val();
var filename = val.replace(/^.*[\\\/]/, '');
$(".file_name").text(filename);
- });
+ });
- },
+ },
-/**
- * Load new notes to fresh list called 'new_notes_list':
- * - Replace 'new_notes_list' with new list every n seconds
- * - Append new notes to this list after submit
- */
+ /**
+ * Load new notes to fresh list called 'new_notes_list':
+ * - Replace 'new_notes_list' with new list every n seconds
+ * - Append new notes to this list after submit
+ */
-initRefresh:
- function() {
- // init timer
- var intNew = setInterval("NoteList.getNew()", 10000);
- },
+ initRefresh:
+ function() {
+ // init timer
+ var intNew = setInterval("NoteList.getNew()", 10000);
+ },
-replace:
- function(html) {
- $("#new_notes_list").html(html);
- },
+ replace:
+ function(html) {
+ $("#new_notes_list").html(html);
+ },
-prepend:
- function(id, html) {
- if(id != this.last_id) {
- $("#new_notes_list").prepend(html);
- }
- },
+ prepend:
+ function(id, html) {
+ if(id != this.last_id) {
+ $("#new_notes_list").prepend(html);
+ }
+ },
-getNew:
- function() {
- // refersh notes list
- $.ajax({
- type: "GET",
+ getNew:
+ function() {
+ // refersh notes list
+ $.ajax({
+ type: "GET",
url: this.notes_path,
data: "last_id=" + this.last_id + this.target_params,
dataType: "script"});
- },
+ },
-refresh:
- function() {
- // refersh notes list
- $.ajax({
- type: "GET",
+ refresh:
+ function() {
+ // refersh notes list
+ $.ajax({
+ type: "GET",
url: this.notes_path,
data: "first_id=" + this.first_id + "&last_id=" + this.last_id + this.target_params,
dataType: "script"});
- },
+ },
-/**
- * Init load of notes:
- * 1. Get content with ajax call
- * 2. Set content of notes list with loaded one
- */
+ /**
+ * Init load of notes:
+ * 1. Get content with ajax call
+ * 2. Set content of notes list with loaded one
+ */
-getContent:
- function() {
- $.ajax({
- type: "GET",
+ getContent:
+ function() {
+ $.ajax({
+ type: "GET",
url: this.notes_path,
data: "?" + this.target_params,
complete: function(){ $('.status').removeClass("loading")},
beforeSend: function() { $('.status').addClass("loading") },
dataType: "script"});
- },
+ },
-setContent:
- function(fid, lid, html) {
+ setContent:
+ function(fid, lid, html) {
this.last_id = lid;
this.first_id = fid;
$("#notes-list").html(html);
// Init infinite scrolling
this.initLoadMore();
- },
-
-
-/**
- * Paging for old notes when scroll to bottom:
- * 1. Init scroll events with 'initLoadMore'
- * 2. Load onlder notes with 'getOld' method
- * 3. append old notes to bottom of list with 'append'
- *
- */
-
-
-getOld:
- function() {
- $('.loading').show();
- $.ajax({
- type: "GET",
- url: this.notes_path,
- data: "first_id=" + this.first_id + this.target_params,
- complete: function(){ $('.status').removeClass("loading")},
- beforeSend: function() { $('.status').addClass("loading") },
- dataType: "script"});
- },
-
-append:
- function(id, html) {
- if(this.first_id == id) {
- this.disable = true;
- } else {
- this.first_id = id;
- $("#notes-list").append(html);
- }
- },
-
+ },
+
+
+ /**
+ * Paging for old notes when scroll to bottom:
+ * 1. Init scroll events with 'initLoadMore'
+ * 2. Load onlder notes with 'getOld' method
+ * 3. append old notes to bottom of list with 'append'
+ *
+ */
+ getOld:
+ function() {
+ $('.loading').show();
+ $.ajax({
+ type: "GET",
+ url: this.notes_path,
+ data: "first_id=" + this.first_id + this.target_params,
+ complete: function(){ $('.status').removeClass("loading")},
+ beforeSend: function() { $('.status').addClass("loading") },
+ dataType: "script"});
+ },
+
+ append:
+ function(id, html) {
+ if(this.first_id == id) {
+ this.disable = true;
+ } else {
+ this.first_id = id;
+ $("#notes-list").append(html);
+ }
+ },
-initLoadMore:
- function() {
- $(document).endlessScroll({
- bottomPixels: 400,
+ initLoadMore:
+ function() {
+ $(document).endlessScroll({
+ bottomPixels: 400,
fireDelay: 1000,
fireOnce:true,
ceaseFire: function() {
@@ -177,6 +163,20 @@ initLoadMore:
callback: function(i) {
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");
+ }
}
@@ -30,7 +30,7 @@
}
#new_note {
- #note_note {
+ .note-text {
height:25px;
}
.attach_holder {
@@ -5,12 +5,6 @@
:javascript
- $(document).ready(function(){
- $(".line_note_link, .line_note_reply_link").live("click", function(e) {
- var form = $(".per_line_form");
- $(this).parent().parent().after(form);
- form.find("#note_line_code").val($(this).attr("line_code"));
- form.show();
- return false;
- });
+ $(function(){
+ PerLineNotes.init();
});
@@ -1,11 +1,12 @@
- if note.valid?
:plain
- $("#new_note .error").remove();
- $('#new_note textarea').val("");
- $('#preview-link').text('Preview');
- $('#preview-note').hide(); $('#note_note').show();
+ $(".note-form-holder .error").remove();
+ $('.note-form-holder textarea').val("");
+ $('.note-form-holder #preview-link').text('Preview');
+ $('.note-form-holder #preview-note').hide();
+ $('.note-form-holder').show();
NoteList.prepend(#{note.id}, "#{escape_javascript(render partial: "notes/show", locals: {note: note})}");
- else
:plain
- $("#new_note").replaceWith("#{escape_javascript(render('form'))}");
+ $(".note-form-holder").replaceWith("#{escape_javascript(render('form'))}");
Oops, something went wrong.

0 comments on commit 4a6596a

Please sign in to comment.