##// END OF EJS Templates
notifications: fixing alerts when gist has been edited
lisaq -
r837:7fa43a0b default
parent child Browse files
Show More
@@ -1,140 +1,136 b''
1 ## -*- coding: utf-8 -*-
1 ## -*- coding: utf-8 -*-
2 <%inherit file="/base/base.html"/>
2 <%inherit file="/base/base.html"/>
3
3
4 <%def name="title()">
4 <%def name="title()">
5 ${_('Edit Gist')} &middot; ${c.gist.gist_access_id}
5 ${_('Edit Gist')} &middot; ${c.gist.gist_access_id}
6 %if c.rhodecode_name:
6 %if c.rhodecode_name:
7 &middot; ${h.branding(c.rhodecode_name)}
7 &middot; ${h.branding(c.rhodecode_name)}
8 %endif
8 %endif
9 </%def>
9 </%def>
10
10
11 <%def name="breadcrumbs_links()">
11 <%def name="breadcrumbs_links()">
12 ${_('Edit Gist')} &middot; ${c.gist.gist_access_id}
12 ${_('Edit Gist')} &middot; ${c.gist.gist_access_id}
13 </%def>
13 </%def>
14
14
15 <%def name="menu_bar_nav()">
15 <%def name="menu_bar_nav()">
16 ${self.menu_items(active='gists')}
16 ${self.menu_items(active='gists')}
17 </%def>
17 </%def>
18
18
19 <%def name="main()">
19 <%def name="main()">
20 <div class="box">
20 <div class="box">
21 <!-- box / title -->
21 <!-- box / title -->
22 <div class="title">
22 <div class="title">
23 ${self.breadcrumbs()}
23 ${self.breadcrumbs()}
24 </div>
24 </div>
25
25
26 <div class="table">
26 <div class="table">
27 <div id="edit_error" class="flash_msg" style="display:none;">
28 <div class="alert alert-warning">
29 ${h.literal(_('Gist was updated since you started editing. Copy your changes and click %(here)s to reload the new version.')
30 % {'here': h.link_to('here',h.url('edit_gist', gist_id=c.gist.gist_access_id))})}
31 </div>
32 </div>
33
27
34 <div id="files_data">
28 <div id="files_data">
35 ${h.secure_form(h.url('edit_gist', gist_id=c.gist.gist_access_id), method='post', id='eform')}
29 ${h.secure_form(h.url('edit_gist', gist_id=c.gist.gist_access_id), method='post', id='eform')}
36 <div>
30 <div>
37 <input type="hidden" value="${c.file_last_commit.raw_id}" name="parent_hash">
31 <input type="hidden" value="${c.file_last_commit.raw_id}" name="parent_hash">
38 <textarea id="description" name="description"
32 <textarea id="description" name="description"
39 placeholder="${_('Gist description ...')}">${c.gist.gist_description}</textarea>
33 placeholder="${_('Gist description ...')}">${c.gist.gist_description}</textarea>
40 <div>
34 <div>
41 <span class="gist-gravatar">
35 <span class="gist-gravatar">
42 ${self.gravatar(h.email_or_none(c.rhodecode_user.full_contact), 30)}
36 ${self.gravatar(h.email_or_none(c.rhodecode_user.full_contact), 30)}
43 </span>
37 </span>
44 <label for='lifetime'>${_('Gist lifetime')}</label>
38 <label for='lifetime'>${_('Gist lifetime')}</label>
45 ${h.dropdownmenu('lifetime', '0', c.lifetime_options)}
39 ${h.dropdownmenu('lifetime', '0', c.lifetime_options)}
46
40
47 <label for='gist_acl_level'>${_('Gist access level')}</label>
41 <label for='gist_acl_level'>${_('Gist access level')}</label>
48 ${h.dropdownmenu('gist_acl_level', c.gist.acl_level, c.acl_options)}
42 ${h.dropdownmenu('gist_acl_level', c.gist.acl_level, c.acl_options)}
49 </div>
43 </div>
50 </div>
44 </div>
51
45
52 ## peppercorn schema
46 ## peppercorn schema
53 <input type="hidden" name="__start__" value="nodes:sequence"/>
47 <input type="hidden" name="__start__" value="nodes:sequence"/>
54 % for cnt, file in enumerate(c.files):
48 % for cnt, file in enumerate(c.files):
55 <input type="hidden" name="__start__" value="file:mapping"/>
49 <input type="hidden" name="__start__" value="file:mapping"/>
56 <div id="codeblock" class="codeblock" >
50 <div id="codeblock" class="codeblock" >
57 <div class="code-header">
51 <div class="code-header">
58 <div class="form">
52 <div class="form">
59 <div class="fields">
53 <div class="fields">
60 <input type="hidden" name="filename_org" value="${file.path}" >
54 <input type="hidden" name="filename_org" value="${file.path}" >
61 <input id="filename_${h.FID('f',file.path)}" name="filename" size="30" type="text" value="${file.path}">
55 <input id="filename_${h.FID('f',file.path)}" name="filename" size="30" type="text" value="${file.path}">
62 ${h.dropdownmenu('mimetype' ,'plain',[('plain',_('plain'))],enable_filter=True, id='mimetype_'+h.FID('f',file.path))}
56 ${h.dropdownmenu('mimetype' ,'plain',[('plain',_('plain'))],enable_filter=True, id='mimetype_'+h.FID('f',file.path))}
63 </div>
57 </div>
64 </div>
58 </div>
65 </div>
59 </div>
66 <div class="editor_container">
60 <div class="editor_container">
67 <pre id="editor_pre"></pre>
61 <pre id="editor_pre"></pre>
68 <textarea id="editor_${h.FID('f',file.path)}" name="content" >${file.content}</textarea>
62 <textarea id="editor_${h.FID('f',file.path)}" name="content" >${file.content}</textarea>
69 </div>
63 </div>
70 </div>
64 </div>
71 <input type="hidden" name="__end__" />
65 <input type="hidden" name="__end__" />
72
66
73 ## dynamic edit box.
67 ## dynamic edit box.
74 <script type="text/javascript">
68 <script type="text/javascript">
75 $(document).ready(function(){
69 $(document).ready(function(){
76 var myCodeMirror = initCodeMirror(
70 var myCodeMirror = initCodeMirror(
77 "editor_${h.FID('f',file.path)}", '');
71 "editor_${h.FID('f',file.path)}", '');
78
72
79 var modes_select = $("#mimetype_${h.FID('f',file.path)}");
73 var modes_select = $("#mimetype_${h.FID('f',file.path)}");
80 fillCodeMirrorOptions(modes_select);
74 fillCodeMirrorOptions(modes_select);
81
75
82 // try to detect the mode based on the file we edit
76 // try to detect the mode based on the file we edit
83 var mimetype = "${file.mimetype}";
77 var mimetype = "${file.mimetype}";
84 var detected_mode = detectCodeMirrorMode(
78 var detected_mode = detectCodeMirrorMode(
85 "${file.path}", mimetype);
79 "${file.path}", mimetype);
86
80
87 if(detected_mode){
81 if(detected_mode){
88 $(modes_select).select2("val", mimetype);
82 $(modes_select).select2("val", mimetype);
89 $(modes_select).change();
83 $(modes_select).change();
90 setCodeMirrorMode(myCodeMirror, detected_mode);
84 setCodeMirrorMode(myCodeMirror, detected_mode);
91 }
85 }
92
86
93 var filename_selector = "#filename_${h.FID('f',file.path)}";
87 var filename_selector = "#filename_${h.FID('f',file.path)}";
94 // on change of select field set mode
88 // on change of select field set mode
95 setCodeMirrorModeFromSelect(
89 setCodeMirrorModeFromSelect(
96 modes_select, filename_selector, myCodeMirror, null);
90 modes_select, filename_selector, myCodeMirror, null);
97
91
98 // on entering the new filename set mode, from given extension
92 // on entering the new filename set mode, from given extension
99 setCodeMirrorModeFromInput(
93 setCodeMirrorModeFromInput(
100 modes_select, filename_selector, myCodeMirror, null);
94 modes_select, filename_selector, myCodeMirror, null);
101 });
95 });
102 </script>
96 </script>
103 %endfor
97 %endfor
104 <input type="hidden" name="__end__" />
98 <input type="hidden" name="__end__" />
105
99
106 <div class="pull-right">
100 <div class="pull-right">
107 ${h.submit('update',_('Update Gist'),class_="btn btn-success")}
101 ${h.submit('update',_('Update Gist'),class_="btn btn-success")}
108 <a class="btn" href="${h.url('gist', gist_id=c.gist.gist_access_id)}">${_('Cancel')}</a>
102 <a class="btn" href="${h.url('gist', gist_id=c.gist.gist_access_id)}">${_('Cancel')}</a>
109 </div>
103 </div>
110 ${h.end_form()}
104 ${h.end_form()}
111 </div>
105 </div>
112 </div>
106 </div>
113
107
114 </div>
108 </div>
115 <script>
109 <script>
116 $('#update').on('click', function(e){
110 $('#update').on('click', function(e){
117 e.preventDefault();
111 e.preventDefault();
118
119 // check for newer version.
112 // check for newer version.
120 $.ajax({
113 $.ajax({
121 url: "${h.url('edit_gist_check_revision', gist_id=c.gist.gist_access_id)}",
114 url: "${h.url('edit_gist_check_revision', gist_id=c.gist.gist_access_id)}",
122 data: {
115 data: {
123 'revision': '${c.file_last_commit.raw_id}'
116 'revision': '${c.file_last_commit.raw_id}'
124 },
117 },
125 dataType: 'json',
118 dataType: 'json',
126 type: 'GET',
119 type: 'GET',
127 success: function(data) {
120 success: function(data) {
128 if(data.success === false){
121 if(data.success === false){
129 $('#edit_error').show();
122 message = '${h.literal(_('Gist was updated since you started editing. Copy your changes and click %(here)s to reload the new version.')
130 window.scrollTo(0,0);
123 % {'here': h.link_to('here',h.url('edit_gist', gist_id=c.gist.gist_access_id))})}'
124 alertMessage = [{"message": {
125 "message": message, "force": "true", "level": "warning"}}];
126 $.Topic('/notifications').publish(alertMessage[0]);
131 }
127 }
132 else{
128 else{
133 $('#eform').submit();
129 $('#eform').submit();
134 }
130 }
135 }
131 }
136 });
132 });
137 })
133 })
138
134
139 </script>
135 </script>
140 </%def>
136 </%def>
General Comments 0
You need to be logged in to leave comments. Login now