Commit 1505cb60 authored by Rich's avatar Rich

wip, can list, edit, add new

parent b9644f9d
......@@ -9,9 +9,10 @@
<table>
<thead>
<tr>
<th>Resource</th>
<th>Description</th>
<th>Active</th>
<th>Name</th>
<th>Description</th>
<th>Resource</th>
<th>Process</th>
<th>Use Count</th>
<th>Actions</th>
......@@ -19,9 +20,11 @@
</thead>
<tbody>
<tr ng-repeat="row in actionLinks">
<td><a href="{{row.allowed_url}}" target="_blank" rel="noopener">{{row.allowed_url}}</a></td>
<td>{{row.description}}</td>
<td>{{row.is_active ? 'Active' : 'Inactive' }}</td>
<td>{{row.name}}</td>
<td>{{row.description || ''}}</td>
<td><a ng-show="row.allowed_url" href="{{row.allowed_url}}" target="_blank" rel="noopener">{{row.allowed_url}}</a>
</td>
<td>{{row.form_processor_name || '(None)'}}</td>
<td>{{row.use_count}}</td>
<td>
......@@ -40,12 +43,13 @@
<div class="crm-block">
<div class="crm-group">
<div crm-ui-field="{name: 'editLinkForm.description', title: ts('Name')}">
<div crm-ui-field="{name: 'editLinkForm.name', title: ts('Name')}">
<input
type="text"
crm-ui-id="editLinkForm.name"
name="name"
ng-model="editLinkForm.name"
required
ng-model="editData.name"
class="crm-form-text"
/>
</div>
......@@ -59,10 +63,89 @@
></textarea>
</div>
<div crm-ui-field="{name: 'myForm.is_active', title: ts('Active')}">
<input type="checkbox"
crm-ui-id="myForm.is_active"
name="is_active"
ng-model="editData.is_active"
class="crm-form-radio"
>
</div>
<div crm-ui-field="{name: 'editLinkForm.allowed_url', title: ts('Link URL')}">
<input
type="text"
crm-ui-id="editLinkForm.allowed_url"
name="allowed_url"
ng-model="editData.allowed_url"
class="crm-form-text"
/>
</div>
<div crm-ui-field="{name: 'editLinkForm.denied_url', title: ts('Fallback URL (if denied)')}">
<input
type="text"
crm-ui-id="editLinkForm.denied_url"
name="denied_url"
ng-model="editData.denied_url"
class="crm-form-text"
/>
</div>
<div crm-ui-field="{name: 'editLinkForm.form_processor_name', title: ts('Form Processor')}">
<select
crm-ui-id="editLinkForm.form_processor_name"
ng-model="editData.form_processor_name"
name="form_processor_name"
class="crm-form-select"
>
</select>
</div>
<div crm-ui-field="{name: 'myForm.form_processor_params', title: ts('Form Processor params')}">
<textarea
crm-ui-id="myForm.form_processor_params"
name="form_processor_params"
ng-model="editData.form_processor_params"
class="crm-form-textarea"
></textarea>
</div>
<div crm-ui-field="{name: 'editLinkForm.use_limit', title: ts('Max uses')}">
<input
type="number"
min=1
crm-ui-id="editLinkForm.use_limit"
name="use_limit"
ng-model="editData.use_limit"
class="crm-form-text"
/>
</div>
<div crm-ui-field="{name: 'editLinkForm.use_by', title: ts('When to stop allowing access')}">
<!-- @todo date time -->
<input
type="text"
crm-ui-id="editLinkForm.use_by"
name="use_by"
ng-model="editData.use_by"
class="crm-form-text"
/>
</div>
<div crm-ui-field="{name: 'myForm.contact_required', title: ts('Active')}">
<input type="checkbox"
crm-ui-id="myForm.contact_required"
name="contact_required"
ng-model="editData.contact_required"
class="crm-form-radio"
>
</div>
</div>
</div>
<div class="crm-block">
<button ng-click="saveRow()">{{ts('Save')}}</button>
<button class="btn btn-secondary cancel" ng-click="cancelEdit()">{{ts('Cancel')}}</button>
<button class="btn btn-primary save" ng-click="saveRow()">{{ts('Save')}}</button>
</div>
</form>
</div>
......
......@@ -15,12 +15,13 @@
// The controller uses *injection*. This default injects a few things:
// $scope -- This is the set of variables shared between JS and HTML.
// crmApi, crmStatus, crmUiHelp -- These are services provided by civicrm-core.
angular.module('actionlinksext').controller('ActionLinksExtAdmin', function($scope, crmApi, crmStatus, crmUiHelp) {
angular.module('actionlinksext').controller('ActionLinksExtAdmin', function($scope, crmApi4, crmStatus, crmUiHelp) {
// The ts() and hs() functions help load strings for this module.
var ts = $scope.ts = CRM.ts('actionlinks');
//var hs = $scope.hs = crmUiHelp({file: 'CRM/actionlinksext/ActionLinksExtAdmin'}); // See: templates/CRM/actionlinksext/ActionLinksExtAdmin.hlp
$scope.isLoaded = false;
$scope.error = '';
$scope.view = 'list';
$scope.actionLinks = [];
......@@ -31,7 +32,7 @@
description: '',
allowed_url: '',
name: '',
is_active: '',
is_active: true,
use_limit: '',
contact_required: false,
use_by: '',
......@@ -40,9 +41,19 @@
form_processor_params: '',
};
}
function reloadData() {
console.log("reloadData");
crmApi4('ActionLink', 'get', {
orderBy: {"is_active":"DESC", "name":"ASC"}
}).then(function(actionLinks) {
// do something with actionLinks array
console.log("actionLinks", actionLinks);
$scope.actionLinks = actionLinks;
$scope.isLoaded = true;
}, function(failure) {
console.error(failure);
});
}
$scope.editRow = function editRow(row) {
......@@ -57,23 +68,69 @@
console.warn("deleteRow @todo");
}
};
$scope.cancelEdit = function cancelEdit() {
$scope.view = 'list';
resetEditData();
};
$scope.saveRow = function saveRow() {
console.warn("saveRow @todo");
return;
var apiParams = Object.assign({}, $scope.editData);
if (!apiParams.id) {
delete apiParams.id;
}
return crmStatus(
// Status messages. For defaults, just use "{}"
{start: ts('Saving...'), success: ts('Saved')},
// The save action. Note that crmApi() returns a promise.
crmApi('Contact', 'create', {
id: myContact.id,
first_name: myContact.first_name,
last_name: myContact.last_name
crmApi4('ActionLink', 'save', {records: [apiParams],
chain: {"the_link":["ActionLink", "get", {where: [["id", '=', "$id"]]}]}
})
);
.then(r => {
console.log("save result", r);
if (apiParams.id) {
var i = $scope.actionLinks.map(l => l.id).indexOf(apiParams.id);
Object.assign($scope.actionLinks[i], r[0].the_link);
}
else {
// We just added a new thing.
$scope.actionLinks.push(Object.assign({}, r[0].the_link));
// Re-sort.
$scope.actionLinks.sort( (a, b) => {
if (a.is_active < b.is_active) {
return -1;
}
if (a.is_active > b.is_active) {
return 1;
}
if (a.name > b.name) {
return 1;
}
if (a.name < b.name) {
return -1;
}
return 0;
});
}
$scope.view = 'list';
resetEditData();
}));
};
function assignUnlessNull(target, source) {
for (var k in source) {
if (source.hasOwnProperty(k)) {
if (source[k]) {
target[k] = source[k];
}
}
}
return target;
}
resetEditData();
reloadData();
});
})(angular, CRM.$, CRM._);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment