Merge pull request #4831 from williamtheaker/master
[civicrm-core.git] / js / view / crm.designer.js
index 8f0e1c3557a58298714ddcd3cddf129f8d3f8a05..e62167f89538522aa001fdb86312cfd15be8cd5a 100644 (file)
 
     initialize: function(options) {
       CRM.designerApp.vent.on('ufUnsaved', this.onUfChanged, this);
+      CRM.designerApp.vent.on('ufSaved', this.onUfSaved, this);
     },
     onClose: function() {
-      this.undoAlert && this.undoAlert.close && this.undoAlert.close();
+      if (this.undoAlert && this.undoAlert.close) this.undoAlert.close();
       CRM.designerApp.vent.off('ufUnsaved', this.onUfChanged, this);
     },
     onUfChanged: function(isUfUnsaved) {
       this.isUfUnsaved = isUfUnsaved;
     },
+    onUfSaved: function() {
+      CRM.designerApp.vent.off('ufUnsaved', this.onUfChanged, this);
+      this.isUfUnsaved = false;
+    },
     onRender: function() {
       var designerDialog = this;
       designerDialog.$el.dialog({
@@ -64,7 +69,7 @@
         title: ts('Edit Profile'),
         modal: true,
         width: '75%',
-        height: parseInt($(window).height() *.8, 10),
+        height: parseInt($(window).height() * 0.8, 10),
         minWidth: 500,
         minHeight: 600, // to allow dropping in big whitespace, coordinate with min-height of .crm-designer-fields
         open: function() {
               return designerDialog.oldOnBeforeUnload.apply(arguments);
             }
           };
-          designerDialog.undoAlert && designerDialog.undoAlert.close && designerDialog.undoAlert.close();
+          if (designerDialog.undoAlert && designerDialog.undoAlert.close) designerDialog.undoAlert.close();
           designerDialog.isDialogOpen = true;
           // Initialize new dialog if we are not re-opening unsaved changes
           if (designerDialog.undoState === false) {
-            designerDialog.designerRegion && designerDialog.designerRegion.close && designerDialog.designerRegion.close();
+            if (designerDialog.designerRegion && designerDialog.designerRegion.close) designerDialog.designerRegion.close();
             designerDialog.$el.block();
             designerDialog.options.findCreateUfGroupModel({
               onLoad: function(ufGroupModel) {
           window.onbeforeunload = designerDialog.oldOnBeforeUnload;
           designerDialog.isDialogOpen = false;
 
-          designerDialog.undoAlert && designerDialog.undoAlert.close && designerDialog.undoAlert.close();
+          if (designerDialog.undoAlert && designerDialog.undoAlert.close) designerDialog.undoAlert.close();
           if (designerDialog.isUfUnsaved) {
-            designerDialog.undoAlert = CRM.alert('<p>' + ts('Your changes to "%1" have not been saved.', {1: designerDialog.model.get('title')}) + '</p><a href="#" class="crm-undo">' + ts('Restore unsaved changes') + '</a>', ts('Unsaved Changes'), 'alert', {expires: 60000});
-            $('.ui-notify-message a.crm-undo').click(function(e) {
+            designerDialog.undoAlert = CRM.alert('<p>' + ts('%1 has not been saved.', {1: designerDialog.model.get('title')}) + '</p><a href="#" class="crm-undo">' + ts('Restore') + '</a>', ts('Unsaved Changes'), 'alert', {expires: 60000});
+            $('.ui-notify-message a.crm-undo').button({icons: {primary: 'ui-icon-arrowreturnthick-1-w'}}).click(function(e) {
               e.preventDefault();
               designerDialog.undoState = true;
               designerDialog.$el.dialog('open');
       'click .crm-designer-preview': 'doPreview'
     },
     onRender: function() {
-      this.$('.crm-designer-save').button().attr({
+      this.$('.crm-designer-save').button({icons: {primary: 'ui-icon-check'}}).attr({
         disabled: 'disabled',
-        style: 'opacity:.5; box-shadow:none; cursor:default;'
+        style: 'opacity:.5; cursor:default;'
       });
-      this.$('.crm-designer-preview').button();
+      this.$('.crm-designer-preview').button({icons: {primary: 'ui-icon-search'}});
     },
     initialize: function(options) {
       CRM.designerApp.vent.on('ufUnsaved', this.onUfChanged, this);
         return;
       }
       var $dialog = this.$el.closest('.crm-designer-dialog'); // FIXME use events
-      $dialog.block({message: 'Saving...', theme: true});
+      $dialog.block();
       var profile = ufGroupModel.toStrictJSON();
       profile["api.UFField.replace"] = {values: ufGroupModel.getRel('ufFieldCollection').toSortedJSON(), 'option.autoweight': 0};
       CRM.api('UFGroup', 'create', profile, {
       if (!this.previewMode) {
         $('.crm-designer-preview-canvas').html('');
         $('.crm-designer-canvas > *, .crm-designer-palette-region').show();
-        $('.crm-designer-preview span').html(ts('Preview'));
+        $('.crm-designer-preview').button('option', {icons: {primary: 'ui-icon-search'}}).find('span').text(ts('Preview'));
         return;
       }
       if (this.model.getRel('ufFieldCollection').hasDuplicates()) {
         return;
       }
       var $dialog = this.$el.closest('.crm-designer-dialog'); // FIXME use events
-      $dialog.block({message: 'Loading...', theme: true});
+      $dialog.block();
       // CRM-12188
       CRM.designerApp.clearPreviewArea();
       $.post(CRM.url("civicrm/ajax/inline"), {
         $dialog.unblock();
         $('.crm-designer-canvas > *, .crm-designer-palette-region').hide();
         $('.crm-designer-preview-canvas').html(data).show().trigger('crmLoad').find(':input').prop('readOnly', true);
-        $('.crm-designer-preview span').html(ts('Edit'));
+        $('.crm-designer-preview').button('option', {icons: {primary: 'ui-icon-pencil'}}).find('span').text(ts('Edit'));
       });
     }
   });
               }
             });
           }
-        })
+        });
       });
 
       this.$('.crm-designer-palette-tree').jstree({
           connectToSortable: '.crm-designer-fields' // FIXME: tight canvas/palette coupling
         });
         paletteView.model.getRel('ufFieldCollection').each(function(ufFieldModel) {
-          paletteView.toggleActive(ufFieldModel, paletteView.model.getRel('ufFieldCollection'))
+          paletteView.toggleActive(ufFieldModel, paletteView.model.getRel('ufFieldCollection'));
         });
         paletteView.$('.crm-designer-palette-add a').replaceWith('<button>' + $('.crm-designer-palette-add a').first().text() + '</<button>');
         paletteView.$('.crm-designer-palette-tree > ul').append('<li><button id="crm-designer-add-custom-set">+ ' + ts('Add Set of Custom Fields') + '</button></li>');
       CRM.loadForm(url, {refreshAction: ['next']})
         .on('crmFormSuccess', function(e, data) {
           // When form switches to create custom field context, modify button behavior to only continue for "save and new"
-          data.customField && ($(this).data('civiCrmSnippet').options.crmForm.refreshAction = ['next_new']);
+          if (data.customField) ($(this).data('civiCrmSnippet').options.crmForm.refreshAction = ['next_new']);
           paletteView.doRefresh(data.customField ? 'custom_' + data.id : null);
         });
     },
       }
     },
     toggleAll: function(e) {
-      if ($('.crm-designer-palette-search input').val() == '') {
+      if (_.isEmpty($('.crm-designer-palette-search input').val())) {
         $('.crm-designer-palette-tree').jstree($(e.target).attr('rel'));
       }
       e.preventDefault();
       this.openTreeNodes = [];
       this.$('.crm-designer-palette-section.jstree-open').each(function() {
         paletteView.openTreeNodes.push($(this).data('section'));
-      })
+      });
     }
   });
 
             ufFieldCanvasView.model.getRel('ufFieldCollection'),
             {skipWeights: true}
           );
-          if (null == ufFieldModel) {
+          if (_.isEmpty(ufFieldModel)) {
             ufFieldCanvasView.$('.crm-designer-fields .ui-draggable').remove();
           } else {
             // Move from end to the 'dropped' position
         model: this.model,
         fieldSchema: this.model.getFieldSchema()
       }));
-      this.onChangeIsDuplicate(this.model, this.model.get('is_duplicate'))
+      this.onChangeIsDuplicate(this.model, this.model.get('is_duplicate'));
       if (!this.expanded) {
         this.detail.$el.hide();
       }