}
};
})
+ // Example: <button crm-confirm="{message: ts('Frobincation is a footastical operation')}" on-yes="frobnicate(123)">Frobincate</button>
+ // Example: <button crm-confirm="{type: 'disable', obj: myObject}" on-yes="myObject.is_active=0; myObject.save()">Disable</button>
+ .directive('crmConfirm', function () {
+ // Helpers to calculate default options from CRM.confirm()
+ var defaultFuncs = {
+ 'disable': function (options) {
+ return {
+ message: ts('Are you sure you want to disable this?'),
+ options: {no: ts('Cancel'), yes: ts('Disable')},
+ width: 300,
+ title: ts('Disable %1?', {
+ 1: options.obj.title || options.obj.label || options.obj.name || ts('the record')
+ })
+ };
+ },
+ 'delete': function (options) {
+ return {
+ message: ts('Are you sure you want to delete this?'),
+ options: {no: ts('Cancel'), yes: ts('Delete')},
+ width: 300,
+ title: ts('Delete %1?', {
+ 1: options.obj.title || options.obj.label || options.obj.name || ts('the record')
+ })
+ };
+ }
+ };
+ return {
+ template: '',
+ link: function (scope, element, attrs) {
+ $(element).click(function () {
+ var options = scope.$eval(attrs['crmConfirm']);
+ var defaults = (options.type) ? defaultFuncs[options.type](options) : {};
+ CRM.confirm(_.extend(defaults, options))
+ .on('crmConfirm:yes', function () { scope.$apply(attrs['onYes']); })
+ .on('crmConfirm:no', function () { scope.$apply(attrs['onNo']); });
+ });
+ }
+ };
+ })
.run(function($rootScope, $location) {
/// Example: <button ng-click="goto('home')">Go home!</button>
$rootScope.goto = function(path) {
$location.path(path);
};
+ // useful for debugging: $rootScope.log = console.log || function() {};
})
;
crmCaseType.controller('CaseTypeListCtrl', function($scope, crmApi, caseTypes) {
$scope.caseTypes = caseTypes.values;
+ $scope.toggleCaseType = function (caseType) {
+ caseType.is_active = (caseType.is_active == '1') ? '0' : '1';
+ crmApi('CaseType', 'create', caseType, true)
+ .then(function (data) {
+ if (data.is_error) {
+ caseType.is_active = (caseType.is_active == '1') ? '0' : '1'; // revert
+ $scope.$digest();
+ }
+ });
+ };
+ $scope.deleteCaseType = function (caseType) {
+ crmApi('CaseType', 'delete', {id: caseType.id}, true)
+ .then(function (data) {
+ if (!data.is_error) {
+ delete caseTypes.values[caseType.id];
+ $scope.$digest();
+ }
+ });
+ };
});
})(angular, CRM.$, CRM._);
\ No newline at end of file
</tr>
</thead>
<tbody>
- <tr ng-repeat="caseType in caseTypes" ng-class-even="'crm-entity even-row even'" ng-class-odd="'crm-entity odd-row odd'">
+ <tr ng-repeat="caseType in caseTypes"
+ class="crm-entity"
+ ng-class-even="'even-row even'"
+ ng-class-odd="'odd-row odd'"
+ ng-class="{disabled: 0==caseType.is_active}">
<td>{{caseType.title}}</td>
<td>{{caseType.name}}</td>
<td>{{caseType.description}}</td>
<td>{{caseType.is_active == 1 ? 'Yes' : 'No'}}</td>
- <td><a ng-href="#/caseType/{{caseType.id}}">Edit</a></td>
- </tr>
+ <!-- FIXME: Can't figure out how styling in other tables gets the nowrap effect... in absence of a consistent fix, KISS -->
+ <td style="white-space: nowrap">
+ <span>
+ <a class="action-item crm-hover-button" ng-href="#/caseType/{{caseType.id}}">Edit</a>
+
+ <span class="btn-slide crm-hover-button">
+ more
+ <ul class="panel" style="display: none;">
+ <li ng-hide="caseType.is_active">
+ <a class="action-item crm-hover-button" ng-click="toggleCaseType(caseType)">Enable</a>
+ </li>
+ <li ng-show="caseType.is_active">
+ <a class="action-item crm-hover-button" crm-confirm="{type: 'disable', obj: caseType}" on-yes="toggleCaseType(caseType)">Disable</a>
+ </li>
+ <li>
+ <a class="action-item crm-hover-button" crm-confirm="{type: 'delete', obj: caseType}" on-yes="deleteCaseType(caseType)">Delete</a>
+ </li>
+ </ul>
+ </span>
+ </span>
+ </td>
+ </tr>
</tbody>
</table>