mirror of
https://github.com/AndorsTrailRelease/andors-trail.git
synced 2025-12-27 06:29:11 +01:00
Content editor: Add "previous"/"next" buttons in editors for items, monsters and actor conditions.
This commit is contained in:
@@ -3,6 +3,8 @@ var ATEditor = (function(ATEditor, model) {
|
||||
function ActorConditionController($scope, $routeParams) {
|
||||
$scope.datasource = model.actorConditions;
|
||||
$scope.obj = $scope.datasource.findById($routeParams.id);
|
||||
$scope.previous = ATEditor.navigationFunctions.editByIndexOffset($scope.datasource, $scope.obj, -1);
|
||||
$scope.next = ATEditor.navigationFunctions.editByIndexOffset($scope.datasource, $scope.obj, 1);
|
||||
};
|
||||
|
||||
ATEditor.controllers = ATEditor.controllers || {};
|
||||
|
||||
@@ -18,7 +18,7 @@ var ATEditor = (function(ATEditor, model, defaults, importExport, _) {
|
||||
if (phraseId) {
|
||||
var nextPhrase = model.dialogue.findById(phraseId);
|
||||
if (nextPhrase) {
|
||||
window.location = "#/" + model.dialogue.id + "/edit/" + phraseId;
|
||||
ATEditor.navigationFunctions.editObjId(model.dialogue, phraseId);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
@@ -31,7 +31,7 @@ var ATEditor = (function(ATEditor, model, defaults, importExport, _) {
|
||||
phraseId = newPhrase.id;
|
||||
obj[prop] = phraseId;
|
||||
|
||||
window.location = "#/" + model.dialogue.id + "/edit/" + phraseId;
|
||||
ATEditor.navigationFunctions.editObjId(model.dialogue, phraseId);
|
||||
};
|
||||
$scope.selectReply = function(reply) {
|
||||
$scope.reply = reply;
|
||||
|
||||
@@ -46,6 +46,9 @@ var ATEditor = (function(ATEditor, model, importExport, settings, ATModelFunctio
|
||||
var idx = list.indexOf(cond);
|
||||
list.splice(idx, 1);
|
||||
};
|
||||
|
||||
$scope.previous = ATEditor.navigationFunctions.editByIndexOffset(model.items, $scope.obj, -1);
|
||||
$scope.next = ATEditor.navigationFunctions.editByIndexOffset(model.items, $scope.obj, 1);
|
||||
}
|
||||
|
||||
function ItemTableController($scope, $routeParams) {
|
||||
@@ -56,7 +59,7 @@ var ATEditor = (function(ATEditor, model, importExport, settings, ATModelFunctio
|
||||
setCategoryToObject(item, model.itemCategories);
|
||||
});
|
||||
$scope.edit = function(item) {
|
||||
window.location = "#/" + section.id + "/edit/" + item.id;
|
||||
ATEditor.navigationFunctions.editObj(section, item);
|
||||
};
|
||||
$scope.addObj = function() {
|
||||
importExport.prepareObjectsForEditor(section, [ section.addNew() ]);
|
||||
|
||||
@@ -13,6 +13,8 @@ var ATEditor = (function(ATEditor, model, importExport, settings, ATModelFunctio
|
||||
var idx = list.indexOf(cond);
|
||||
list.splice(idx, 1);
|
||||
};
|
||||
$scope.previous = ATEditor.navigationFunctions.editByIndexOffset(model.monsters, $scope.obj, -1);
|
||||
$scope.next = ATEditor.navigationFunctions.editByIndexOffset(model.monsters, $scope.obj, 1);
|
||||
}
|
||||
|
||||
function MonsterTableController($scope, $routeParams) {
|
||||
@@ -20,7 +22,7 @@ var ATEditor = (function(ATEditor, model, importExport, settings, ATModelFunctio
|
||||
$scope.monsters = section.items;
|
||||
$scope.getExperience = ATModelFunctions.monsterFunctions.getMonsterExperience;
|
||||
$scope.edit = function(monster) {
|
||||
window.location = "#/" + section.id + "/edit/" + monster.id;
|
||||
ATEditor.navigationFunctions.editObj(section, monster);
|
||||
};
|
||||
$scope.addObj = function() {
|
||||
importExport.prepareObjectsForEditor(section, [ section.addNew() ]);
|
||||
|
||||
@@ -1,5 +1,20 @@
|
||||
var ATEditor = (function(ATEditor, model, importExport, exampleData) {
|
||||
|
||||
function editObjId(section, objId) {
|
||||
window.location = "#/" + section.id + "/edit/" + objId;
|
||||
}
|
||||
function editObj(section, obj) {
|
||||
editObjId(section, obj.id);
|
||||
}
|
||||
|
||||
function editByIndexOffset(section, obj, offset) {
|
||||
return function() {
|
||||
var nextObj = section.findByIndexOffset(obj, offset);
|
||||
if (!nextObj) { return; }
|
||||
editObj(section, nextObj);
|
||||
};
|
||||
}
|
||||
|
||||
function NavigationController($scope, $routeParams, $http) {
|
||||
$scope.sections = model.sections;
|
||||
$scope.previousItems = [];
|
||||
@@ -12,7 +27,7 @@ var ATEditor = (function(ATEditor, model, importExport, exampleData) {
|
||||
if ($scope.previousItems.length > 5) {
|
||||
$scope.previousItems.pop();
|
||||
}
|
||||
window.location = "#/" + section.id + "/edit/" + obj.id;
|
||||
editObj(section, obj);
|
||||
};
|
||||
$scope.addObj = function(section) {
|
||||
var item = section.addNew();
|
||||
@@ -51,6 +66,11 @@ var ATEditor = (function(ATEditor, model, importExport, exampleData) {
|
||||
|
||||
ATEditor.controllers = ATEditor.controllers || {};
|
||||
ATEditor.controllers.NavigationController = NavigationController;
|
||||
ATEditor.navigationFunctions = {
|
||||
editObj: editObj
|
||||
,editObjId: editObjId
|
||||
,editByIndexOffset: editByIndexOffset
|
||||
};
|
||||
|
||||
return ATEditor;
|
||||
})(ATEditor, ATEditor.model, ATEditor.importExport, ATEditor.exampleData);
|
||||
|
||||
@@ -83,6 +83,15 @@ var ATEditor = (function(ATEditor, _) {
|
||||
this.ensureUniqueId = function(obj) {
|
||||
obj[options.idField] = this.findFirstFreeId(obj[options.idField]);
|
||||
};
|
||||
this.findByIndexOffset = function(obj, offset) {
|
||||
if (_.isEmpty(this.items)) { return; }
|
||||
|
||||
var idx = _.indexOf(this.items, obj);
|
||||
idx = idx + offset;
|
||||
if (idx < 0) { idx = this.items.length - 1; }
|
||||
if (idx >= this.items.length) { idx = 0; }
|
||||
return this.items[idx];
|
||||
};
|
||||
};
|
||||
|
||||
return ATEditor;
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
<h3>Actor condition - {{obj.name}}</h3>
|
||||
<div class="prevNext">
|
||||
<a class="btn btn-secondary" ng-click="previous()"><i class="icon-backward"></i></a>
|
||||
<a class="btn btn-secondary" ng-click="next()"><i class="icon-forward"></i></a>
|
||||
</div>
|
||||
<fieldset>
|
||||
<legend>General</legend>
|
||||
<div class="fieldWithLabel">
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
<h3>Item - {{obj.name}}</h3>
|
||||
<div class="prevNext">
|
||||
<a class="btn btn-secondary" ng-click="previous()"><i class="icon-backward"></i></a>
|
||||
<a class="btn btn-secondary" ng-click="next()"><i class="icon-forward"></i></a>
|
||||
</div>
|
||||
<fieldset>
|
||||
<legend>General</legend>
|
||||
<div class="fieldWithLabel">
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
<h3>Monster / NPC - {{obj.name}}</h3>
|
||||
<div class="prevNext">
|
||||
<a class="btn btn-secondary" ng-click="previous()"><i class="icon-backward"></i></a>
|
||||
<a class="btn btn-secondary" ng-click="next()"><i class="icon-forward"></i></a>
|
||||
</div>
|
||||
<fieldset>
|
||||
<legend>General</legend>
|
||||
<div class="fieldWithLabel">
|
||||
|
||||
Reference in New Issue
Block a user