Andreas Loupasakis avatar Andreas Loupasakis committed 9016ce6

Fixed lock extend action and links for locking and unlocking in actions popup.

Comments (0)

Files changed (2)

transifex/addons/locks/templates/lock_resource_action.html

 
 {% url resource_language_lock resource.project.slug resource.slug language.code as url_lock %}
 {% url resource_language_unlock resource.project.slug resource.slug language.code as url_unlock %}
+{% url resource_language_extend resource.project.slug resource.slug language.code as url_extend %}
 
 {% with lock.owner as owner %}
 
       {% endif %}
       {% blocktrans with lock.expires|timeuntil as lock_expires %}({{ lock_expires }} left){% endblocktrans %}
 
-      {% if is_unlockable %}(<span class="clickable">{% trans "unlock" %}</span>){% endif %}
+      {% if is_unlockable %}(<span class="clickable unlock_action">{% trans "unlock" %}</span>){% endif %}
 
     {% if is_owner %}
         <ul>
          <li id="locked-extend-{{ lock_html_id }}" class="i16 lock_add image_submit_type">
-          <span id="locked-extend-message-{{ lock_html_id }}" class="clickable tipsy_enable" title="{% trans "Click to renew your lock for a fresh period of time." %}">
+          <span id="locked-extend-message-{{ lock_html_id }}" class="clickable tipsy_enable lock_extend_action" title="{% trans "Click to renew your lock for a fresh period of time." %}">
             {% blocktrans count locks_lifetime as hours %}Extend lock by {{hours}} hour.{% plural %}Extend lock by {{hours}} hours.{% endblocktrans %}
           </span>
          </li>
 {% else %}
     {% if can_lock %}
         <li id="unlocked-lockable-{{ lock_html_id }}" class="top i16 lock_none image_submit_type">
-            <span class="clickable">{% trans "Lock this translation to notify others you're working with it." %}</span>
+            <span class="clickable lock_action">{% trans "Lock this translation to notify others you're working with it." %}</span>
         </li>
     {% else %}
         <li id="unlocked-nonlockable-{{ lock_html_id }}" class="i16 lock_none top">
     {% endif %}
 {% endif %}
 
-{% endwith %}
 
 <script type="text/javascript">
 
-    $("#unlocked-lockable-{{ lock_html_id }}").click(function(){
+    $("#unlocked-lockable-{{ lock_html_id }} .lock_action").click(function(){
         $.ajax({
             url : '{{ url_lock }}',
             contentType : 'application/json',
 
     {% if is_unlockable %}
 
-    $("#locked-{{ lock_html_id }}").click(function(){
+    $("#locked-{{ lock_html_id }} .unlock_action").click(function(){
         $.ajax({
             url : '{{ url_unlock }}',
             contentType : 'application/json',
 
     {% endif %}
 
+    {% if is_owner %}
+    $("#locked-{{ lock_html_id }} .lock_extend_action").click(function(){
+        $.ajax({
+            url : '{{ url_extend }}',
+            contentType : 'application/json',
+            type : 'POST',
+            beforeSend: function(){
+            $("div#notification-container div").html('{% trans "Extending lock..." %}');
+            $("div#notification-container").fadeIn("fast");
+            },
+            complete : function(xmlhttpreq, textStatus) {
+                if (textStatus=='success'){
+                    response = xmlhttpreq['responseText'];
+                    $("div#notification-container div").html(response['message']);
+                }
+                $("div#notification-container").fadeOut("fast");
+                window.location= '{{ next }}';
+            }
+        });
+    });
+    {% endif %}
+
 </script>
+
+{% endwith %}

transifex/addons/locks/urls.py

         regex = r'^projects/p/(?P<project_slug>[-\w]+)/resource/(?P<resource_slug>[-\w]+)/l/(?P<language_code>[\-_@\w]+)/unlock/$',
         view = resource_language_unlock,
         name = 'resource_language_unlock',),
+    # We exploit the create_update to do the extend lock action with the same view as lock creation.
+    url(
+        regex = r'^projects/p/(?P<project_slug>[-\w]+)/resource/(?P<resource_slug>[-\w]+)/l/(?P<language_code>[\-_@\w]+)/extend/$',
+        view = resource_language_lock,
+        name = 'resource_language_extend',),
 )
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.