Browse Source

HUE-4190 [oozie] Option to return coordinator id instead of redirect in coordinator submission popup

Enrico Berti 9 years ago
parent
commit
37d2ff6

+ 18 - 0
apps/oozie/src/oozie/templates/editor2/submit_job_popup.mako

@@ -79,6 +79,9 @@
            <input type="checkbox" name="dryrun_checkbox" /> ${ _('Do a dryrun before submitting the job?') }
          </label>
       % endif
+      % if return_json:
+        <input type="hidden" name="format" value="json">
+      % endif
   </div>
   <div class="modal-footer">
     <a href="#" class="btn" data-dismiss="modal">${ _('Cancel') }</a>
@@ -154,4 +157,19 @@
     });
    _el.datepicker('show');
   });
+
+  % if return_json:
+    $('.submit-form').submit(function (e) {
+      $.ajax({
+        type: "POST",
+        url: '${ action }',
+        data: $('.submit-form').serialize(),
+        success: function (data) {
+          huePubSub.publish('submit.popup.return', data);
+        }
+      });
+      e.preventDefault();
+    });
+  % endif
+
 </script>

+ 8 - 4
apps/oozie/src/oozie/views/editor2.py

@@ -709,10 +709,13 @@ def submit_coordinator(request, doc_id):
     if params_form.is_valid():
       mapping = dict([(param['name'], param['value']) for param in params_form.cleaned_data])
       mapping['dryrun'] = request.POST.get('dryrun_checkbox') == 'on'
+      jsonify = request.POST.get('format') == 'json'
       job_id = _submit_coordinator(request, coordinator, mapping)
-
-      request.info(_('Coordinator submitted.'))
-      return redirect(reverse('oozie:list_oozie_coordinator', kwargs={'job_id': job_id}))
+      if jsonify:
+        return JsonResponse({'status': 0, 'job_id': job_id}, safe=False)
+      else:
+        request.info(_('Coordinator submitted.'))
+        return redirect(reverse('oozie:list_oozie_coordinator', kwargs={'job_id': job_id}))
     else:
       request.error(_('Invalid submission form: %s' % params_form.errors))
   else:
@@ -724,7 +727,8 @@ def submit_coordinator(request, doc_id):
                  'params_form': params_form,
                  'name': coordinator.name,
                  'action': reverse('oozie:editor_submit_coordinator',  kwargs={'doc_id': coordinator.id}),
-                 'show_dryrun': True
+                 'show_dryrun': True,
+                 'return_json': request.GET.get('format') == 'json'
                 }, force_template=True).content
   return JsonResponse(popup, safe=False)
 

+ 1 - 0
desktop/libs/notebook/src/notebook/static/notebook/js/notebook.ko.js

@@ -1622,6 +1622,7 @@
 
     self.showSubmitPopup = function () {
       $.get('/oozie/editor/coordinator/submit/' + self.dependentsCoordinator()[0].id(), {
+        format: 'json'
       }, function (data) {
         $(document).trigger("showSubmitPopup", data);
       }).fail(function (xhr, textStatus, errorThrown) {

+ 6 - 0
desktop/libs/notebook/src/notebook/templates/editor_components.mako

@@ -3228,6 +3228,12 @@ ${ hueIcons.symbols() }
         }
       });
 
+      huePubSub.subscribe('submit.popup.return', function(data){
+        console.log('Job id', data.job_id);
+        $.jHueNotify.info('${_('Coordinator submitted.')}');
+        $('.submit-modal').modal('hide');
+      });
+
       $(document).on("gridShown", function (e, snippet) {
         window.setTimeout(function () {
           resizeToggleResultSettings(snippet);