add back buttopn on edit
authorymh <ymh.work@gmail.com>
Thu, 12 Sep 2013 17:26:15 +0200
changeset 74 ad7d84868c98
parent 73 d1b176885515
child 75 eb6530b77b0e
add back buttopn on edit
src/p4l/settings.py
src/p4l/static/p4l/js/p4l.js
src/p4l/templates/p4l/p4l_home.html
src/p4l/templates/p4l/record_update_form.html
src/p4l/views.py
--- a/src/p4l/settings.py	Thu Sep 12 11:42:29 2013 +0200
+++ b/src/p4l/settings.py	Thu Sep 12 17:26:15 2013 +0200
@@ -141,6 +141,7 @@
 
 TEMPLATE_CONTEXT_PROCESSORS = global_settings.TEMPLATE_CONTEXT_PROCESSORS + (
     'django.core.context_processors.i18n',
+    'django.core.context_processors.request',
 )
 
 # A sample logging configuration. The only tangible logging
--- a/src/p4l/static/p4l/js/p4l.js	Thu Sep 12 11:42:29 2013 +0200
+++ b/src/p4l/static/p4l/js/p4l.js	Thu Sep 12 17:26:15 2013 +0200
@@ -241,9 +241,15 @@
         
     $scope.submitRecord = function() {
         $scope.saving = true;
-        $scope.record.$save({recordId: context.record_id}).then(function(response) { $scope.saving=false;});
+        $scope.record.$save({recordId: context.record_id})
+            .then(function(response) {
+                $scope.saving=false;
+            });
     }
     
+    $scope.getPreviousUrl = function() {
+        return context.urls.previous || context.urls.home;
+    }    
     
 });
 
--- a/src/p4l/templates/p4l/p4l_home.html	Thu Sep 12 11:42:29 2013 +0200
+++ b/src/p4l/templates/p4l/p4l_home.html	Thu Sep 12 17:26:15 2013 +0200
@@ -48,7 +48,7 @@
       <td>&nbsp;</td>
       <td>
         <a class="btn btn-default" href="{% url 'p4l_record_view' slug=record.identifier %}"><i class="glyphicon glyphicon-eye-open"></i></a>
-        <a class="btn btn-default" href="{% url 'p4l_record_edit' slug=record.identifier %}"><i class="glyphicon glyphicon-pencil"></i></a>
+        <a class="btn btn-default" href="{% url 'p4l_record_edit' slug=record.identifier %}?previous={{request.get_full_path|urlencode}}"><i class="glyphicon glyphicon-pencil"></i></a>
       </td>
     </tr>
   {% empty %}
--- a/src/p4l/templates/p4l/record_update_form.html	Thu Sep 12 11:42:29 2013 +0200
+++ b/src/p4l/templates/p4l/record_update_form.html	Thu Sep 12 17:26:15 2013 +0200
@@ -28,7 +28,9 @@
             csrf_token: "{{ csrf_token }}",
             urls: {
                 base_static: "{% get_static_prefix %}",
-                record_api: "{% url 'record-detail' identifier=':recordId' %}".replace("\%3A",":"),                
+                record_api: "{% url 'record-detail' identifier=':recordId' %}".replace("\%3A",":"),
+                previous: "{{request.GET.previous}}",
+                home: "{% url 'p4l_home' %}"
             },
             query_dicts: angular.fromJson('{{ query_dicts | safe | addslashes}}'),
             languages_list: angular.fromJson('{{ languages_list | safe | addslashes}}'),
@@ -43,6 +45,7 @@
 {% block content %}
 {% verbatim %}
 <div ng-app="recordApp" ng-controller="RecordCtrl" ng-cloak>
+<form name="recordForm">
 <table class="table record-table">
   <thead>
     <tr><td>{{'property' | translate}}</td><td>{{'value' | translate }}</td></tr>
@@ -178,10 +181,15 @@
     </tr>
   </tbody>
 </table>
-<button type="button" class="btn btn-primary" ng-click="submitRecord()" id="record-submit">
+<button type="submit" class="btn btn-primary" id="record-submit" ng-click="submitRecord()">
     <span ng-class="['glyphicon', saving?'spinner':'glyphicon-save']"></span>
     <span>{{ 'Save' | translate }}</span>
 </button>
+<a class="btn btn-primary" id="record-back" href="{{getPreviousUrl()}}">
+    <span class="glyphicon glyphicon-arrow-left"></span>
+    <span>{{ 'Cancel' | translate }}</span>
+</a>
+</form>
 </div>
 {% endverbatim %}
 {% endblock %}
\ No newline at end of file
--- a/src/p4l/views.py	Thu Sep 12 11:42:29 2013 +0200
+++ b/src/p4l/views.py	Thu Sep 12 17:26:15 2013 +0200
@@ -6,7 +6,6 @@
 '''
 
 from django.conf import settings
-from django.utils.decorators import method_decorator
 from django.views.generic import ListView, DetailView
 from p4l.forms import RecordFilterForm
 from p4l.models import Record
@@ -182,7 +181,7 @@
         
         # Languages list used in drop down list
         context['languages_list'] = json.dumps(settings.LANGUAGES_LIST)
-        
+                
         return context
         
         
\ No newline at end of file