Skip to content

Instantly share code, notes, and snippets.

@mecachisenros
Last active April 5, 2017 22:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mecachisenros/834e8a38cf4204a5e4d554b471f1f2cf to your computer and use it in GitHub Desktop.
Save mecachisenros/834e8a38cf4204a5e4d554b471f1f2cf to your computer and use it in GitHub Desktop.
(function(angular, $, _) {
// Declare Angular module
var crmMailSubjectReview = angular.module( 'crmMailSubjectReview', [] );
// Hook into crmMailing module and append directive into crmMailingBlockReview directive
angular.module( 'crmMailing' ).config( function( $provide ){
$provide.decorator( 'crmMailingBlockReviewDirective', function( $delegate ){
var directive = $delegate[0];
var link = directive.link;
directive.compile = function( Element, Attrs ){
Element.children( ":first" ).children( ":first" ).children( ":first" ).children( ":nth-child(2)" ).after( '<div crm-subject-review></div>' );
return function( scope, elem, attr ){
link.apply( this, arguments );
};
};
return $delegate;
});
});
// crmSubjectReview directive
angular.module( 'crmMailing' ).directive( 'crmSubjectReview', function(){
return { templateUrl: CRM.resourceUrls['uk.menas.subcustom'] + '/js/crmSubjectReview.html',
controller: 'crmSubjectReviewCtrl',
};
});
// crmSubjectReview factory
angular.module('crmMailing').factory('crmSubjectReviewFactory', function(){
return {
editEnabled: false,
enableEdit: function() {
this.editEnabled = true;
},
disableEdit: function() {
this.editEnabled = false;
}
}
});
// crmSubjectReview controller
angular.module( 'crmMailing' ).controller( 'crmSubjectReviewCtrl', function( $scope, crmSubjectReviewFactory ){
$scope.crmSubjectReview = crmSubjectReviewFactory;
});
})(angular, CRM.$, CRM._);
@mecachisenros
Copy link
Author

here's the directive

<div crm-ui-field="{title: ts('Subject')}">
    <div ng-hide="crmSubjectReview.editEnabled">
      	{{mailing.subject}}
      	<a class="crm-hover-button action-item" ng-click="crmSubjectReview.enableEdit()">{{ts('Edit')}}</a>
    </div>
    <div ng-show="crmSubjectReview.editEnabled">
      	<input calss="crm-form-text" name="subject" ng-model="mailing.subject" ng-show="crmSubjectReview.editEnabled">
      	<a class="crm-hover-button action-item" ng-click="crmSubjectReview.disableEdit()">{{ts('Done')}}</a>
    </div>
</div>

@mecachisenros
Copy link
Author

and here the result
subject-review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment