1
1
var NoteList = {
2
2
3
- notes_path : null ,
4
- target_params : null ,
5
- target_id : 0 ,
6
- target_type : null ,
7
- first_id : 0 ,
8
- last_id : 0 ,
9
- disable :false ,
10
-
11
- init :
12
- function ( tid , tt , path ) {
13
- this . notes_path = path + ".js" ;
14
- this . target_id = tid ;
15
- this . target_type = tt ;
16
- this . target_params = "&target_type=" + this . target_type + "&target_id=" + this . target_id ;
17
-
18
- // get notes
19
- this . getContent ( ) ;
20
-
21
- // get new notes every n seconds
22
- this . initRefresh ( ) ;
23
-
24
- $ ( '.delete-note' ) . live ( 'ajax:success' , function ( ) {
25
- $ ( this ) . closest ( 'li' ) . fadeOut ( ) ; } ) ;
26
-
27
- $ ( '#note_note' ) . on ( 'keyup' , function ( ) {
28
- var field = $ ( this ) ;
29
- var closest_submit = field . closest ( "form" ) . find ( ".submit_note" ) ;
30
- if ( field . val ( ) == "" ) {
31
- closest_submit . attr ( "disabled" , "disabled" ) . addClass ( "disabled" ) ;
32
- } else {
33
- closest_submit . removeAttr ( "disabled" ) . removeClass ( "disabled" ) ;
34
- }
35
- } )
36
-
37
- $ ( "#new_note" ) . live ( "ajax:before" , function ( ) {
38
- $ ( ".submit_note" ) . attr ( "disabled" , "disabled" ) ;
39
- } )
40
-
41
- $ ( "#new_note" ) . live ( "ajax:complete" , function ( ) {
42
- $ ( ".submit_note" ) . removeAttr ( "disabled" ) ;
43
- } )
44
-
45
- $ ( "#note_note" ) . live ( "focus" , function ( ) {
46
- $ ( this ) . css ( "height" , "80px" ) ;
47
- $ ( '.note_advanced_opts' ) . show ( ) ;
48
- if ( $ ( this ) . val ( ) == "" ) {
49
- $ ( this ) . closest ( "form" ) . find ( ".submit_note" ) . attr ( "disabled" , "disabled" ) . addClass ( "disabled" ) ;
50
- }
51
- } ) ;
52
-
53
- $ ( "#note_attachment" ) . change ( function ( e ) {
3
+ notes_path : null ,
4
+ target_params : null ,
5
+ target_id : 0 ,
6
+ target_type : null ,
7
+ first_id : 0 ,
8
+ last_id : 0 ,
9
+ disable :false ,
10
+
11
+ init :
12
+ function ( tid , tt , path ) {
13
+ this . notes_path = path + ".js" ;
14
+ this . target_id = tid ;
15
+ this . target_type = tt ;
16
+ this . target_params = "&target_type=" + this . target_type + "&target_id=" + this . target_id ;
17
+
18
+ // get notes
19
+ this . getContent ( ) ;
20
+
21
+ // get new notes every n seconds
22
+ this . initRefresh ( ) ;
23
+
24
+ $ ( '.delete-note' ) . live ( 'ajax:success' , function ( ) {
25
+ $ ( this ) . closest ( 'li' ) . fadeOut ( ) ; } ) ;
26
+
27
+ $ ( ".note-form-holder" ) . live ( "ajax:before" , function ( ) {
28
+ $ ( ".submit_note" ) . attr ( "disabled" , "disabled" ) ;
29
+ } )
30
+
31
+ $ ( ".note-form-holder" ) . live ( "ajax:complete" , function ( ) {
32
+ $ ( ".submit_note" ) . removeAttr ( "disabled" ) ;
33
+ } )
34
+
35
+ disableButtonIfEmtpyField ( ".note-text" , ".submit_note" ) ;
36
+
37
+ $ ( ".note-text" ) . live ( "focus" , function ( ) {
38
+ $ ( this ) . css ( "height" , "80px" ) ;
39
+ $ ( '.note_advanced_opts' ) . show ( ) ;
40
+ } ) ;
41
+
42
+ $ ( "#note_attachment" ) . change ( function ( e ) {
54
43
var val = $ ( '.input-file' ) . val ( ) ;
55
44
var filename = val . replace ( / ^ .* [ \\ \/ ] / , '' ) ;
56
45
$ ( ".file_name" ) . text ( filename ) ;
57
- } ) ;
46
+ } ) ;
58
47
59
- } ,
48
+ } ,
60
49
61
50
62
- /**
63
- * Load new notes to fresh list called 'new_notes_list':
64
- * - Replace 'new_notes_list' with new list every n seconds
65
- * - Append new notes to this list after submit
66
- */
51
+ /**
52
+ * Load new notes to fresh list called 'new_notes_list':
53
+ * - Replace 'new_notes_list' with new list every n seconds
54
+ * - Append new notes to this list after submit
55
+ */
67
56
68
- initRefresh :
69
- function ( ) {
70
- // init timer
71
- var intNew = setInterval ( "NoteList.getNew()" , 10000 ) ;
72
- } ,
57
+ initRefresh :
58
+ function ( ) {
59
+ // init timer
60
+ var intNew = setInterval ( "NoteList.getNew()" , 10000 ) ;
61
+ } ,
73
62
74
- replace :
75
- function ( html ) {
76
- $ ( "#new_notes_list" ) . html ( html ) ;
77
- } ,
63
+ replace :
64
+ function ( html ) {
65
+ $ ( "#new_notes_list" ) . html ( html ) ;
66
+ } ,
78
67
79
- prepend :
80
- function ( id , html ) {
81
- if ( id != this . last_id ) {
82
- $ ( "#new_notes_list" ) . prepend ( html ) ;
83
- }
84
- } ,
68
+ prepend :
69
+ function ( id , html ) {
70
+ if ( id != this . last_id ) {
71
+ $ ( "#new_notes_list" ) . prepend ( html ) ;
72
+ }
73
+ } ,
85
74
86
- getNew :
87
- function ( ) {
88
- // refersh notes list
89
- $ . ajax ( {
90
- type : "GET" ,
75
+ getNew :
76
+ function ( ) {
77
+ // refersh notes list
78
+ $ . ajax ( {
79
+ type : "GET" ,
91
80
url : this . notes_path ,
92
81
data : "last_id=" + this . last_id + this . target_params ,
93
82
dataType : "script" } ) ;
94
- } ,
83
+ } ,
95
84
96
- refresh :
97
- function ( ) {
98
- // refersh notes list
99
- $ . ajax ( {
100
- type : "GET" ,
85
+ refresh :
86
+ function ( ) {
87
+ // refersh notes list
88
+ $ . ajax ( {
89
+ type : "GET" ,
101
90
url : this . notes_path ,
102
91
data : "first_id=" + this . first_id + "&last_id=" + this . last_id + this . target_params ,
103
92
dataType : "script" } ) ;
104
- } ,
93
+ } ,
105
94
106
95
107
- /**
108
- * Init load of notes:
109
- * 1. Get content with ajax call
110
- * 2. Set content of notes list with loaded one
111
- */
96
+ /**
97
+ * Init load of notes:
98
+ * 1. Get content with ajax call
99
+ * 2. Set content of notes list with loaded one
100
+ */
112
101
113
102
114
- getContent :
115
- function ( ) {
116
- $ . ajax ( {
117
- type : "GET" ,
103
+ getContent :
104
+ function ( ) {
105
+ $ . ajax ( {
106
+ type : "GET" ,
118
107
url : this . notes_path ,
119
108
data : "?" + this . target_params ,
120
109
complete : function ( ) { $ ( '.status' ) . removeClass ( "loading" ) } ,
121
110
beforeSend : function ( ) { $ ( '.status' ) . addClass ( "loading" ) } ,
122
111
dataType : "script" } ) ;
123
- } ,
112
+ } ,
124
113
125
- setContent :
126
- function ( fid , lid , html ) {
114
+ setContent :
115
+ function ( fid , lid , html ) {
127
116
this . last_id = lid ;
128
117
this . first_id = fid ;
129
118
$ ( "#notes-list" ) . html ( html ) ;
130
119
131
120
// Init infinite scrolling
132
121
this . initLoadMore ( ) ;
133
- } ,
134
-
135
-
136
- /**
137
- * Paging for old notes when scroll to bottom:
138
- * 1. Init scroll events with 'initLoadMore'
139
- * 2. Load onlder notes with 'getOld' method
140
- * 3. append old notes to bottom of list with 'append'
141
- *
142
- */
143
-
144
-
145
- getOld :
146
- function ( ) {
147
- $ ( '.loading' ) . show ( ) ;
148
- $ . ajax ( {
149
- type : "GET" ,
150
- url : this . notes_path ,
151
- data : "first_id=" + this . first_id + this . target_params ,
152
- complete : function ( ) { $ ( '.status' ) . removeClass ( "loading" ) } ,
153
- beforeSend : function ( ) { $ ( '.status' ) . addClass ( "loading" ) } ,
154
- dataType : "script" } ) ;
155
- } ,
156
-
157
- append :
158
- function ( id , html ) {
159
- if ( this . first_id == id ) {
160
- this . disable = true ;
161
- } else {
162
- this . first_id = id ;
163
- $ ( "#notes-list" ) . append ( html ) ;
164
- }
165
- } ,
166
-
122
+ } ,
123
+
124
+
125
+ /**
126
+ * Paging for old notes when scroll to bottom:
127
+ * 1. Init scroll events with 'initLoadMore'
128
+ * 2. Load onlder notes with 'getOld' method
129
+ * 3. append old notes to bottom of list with 'append'
130
+ *
131
+ */
132
+ getOld :
133
+ function ( ) {
134
+ $ ( '.loading' ) . show ( ) ;
135
+ $ . ajax ( {
136
+ type : "GET" ,
137
+ url : this . notes_path ,
138
+ data : "first_id=" + this . first_id + this . target_params ,
139
+ complete : function ( ) { $ ( '.status' ) . removeClass ( "loading" ) } ,
140
+ beforeSend : function ( ) { $ ( '.status' ) . addClass ( "loading" ) } ,
141
+ dataType : "script" } ) ;
142
+ } ,
143
+
144
+ append :
145
+ function ( id , html ) {
146
+ if ( this . first_id == id ) {
147
+ this . disable = true ;
148
+ } else {
149
+ this . first_id = id ;
150
+ $ ( "#notes-list" ) . append ( html ) ;
151
+ }
152
+ } ,
167
153
168
- initLoadMore :
169
- function ( ) {
170
- $ ( document ) . endlessScroll ( {
171
- bottomPixels : 400 ,
154
+ initLoadMore :
155
+ function ( ) {
156
+ $ ( document ) . endlessScroll ( {
157
+ bottomPixels : 400 ,
172
158
fireDelay : 1000 ,
173
159
fireOnce :true ,
174
160
ceaseFire : function ( ) {
@@ -177,6 +163,20 @@ initLoadMore:
177
163
callback : function ( i ) {
178
164
NoteList . getOld ( ) ;
179
165
}
180
- } ) ;
181
- }
166
+ } ) ;
167
+ }
168
+ } ;
169
+
170
+ var PerLineNotes = {
171
+ init :
172
+ function ( ) {
173
+ $ ( ".line_note_link, .line_note_reply_link" ) . live ( "click" , function ( e ) {
174
+ var form = $ ( ".per_line_form" ) ;
175
+ $ ( this ) . closest ( "tr" ) . after ( form ) ;
176
+ form . find ( "#note_line_code" ) . val ( $ ( this ) . attr ( "line_code" ) ) ;
177
+ form . show ( ) ;
178
+ return false ;
179
+ } ) ;
180
+ disableButtonIfEmtpyField ( ".line-note-text" , ".submit_inline_note" ) ;
181
+ }
182
182
}
0 commit comments