134 lines
3.5 KiB
JavaScript
Raw Normal View History

/*
* Copyright [2011] [wisemapping]
*
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
* It is basically the Apache License, Version 2.0 (the "License") plus the
* "powered by wisemapping" text requirement on every single page;
* you may not use this file except in compliance with the License.
* You may obtain a copy of the license at
*
* http://www.wisemapping.org/license
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
mindplot.DesignerModel = new Class({
Implements:[Events],
initialize:function (options) {
this._zoom = options.zoom;
this._topics = [];
this._relationships = [];
},
getZoom:function () {
return this._zoom;
},
setZoom:function (zoom) {
this._zoom = zoom;
},
getTopics:function () {
return this._topics;
},
getRelationships:function () {
return this._relationships;
},
getCentralTopic:function () {
var topics = this.getTopics();
return topics[0];
},
filterSelectedTopics:function () {
var result = [];
for (var i = 0; i < this._topics.length; i++) {
if (this._topics[i].isOnFocus()) {
result.push(this._topics[i]);
}
}
return result;
},
filterSelectedRelationships:function () {
var result = [];
for (var i = 0; i < this._relationships.length; i++) {
if (this._relationships[i].isOnFocus()) {
result.push(this._relationships[i]);
}
}
return result;
},
getEntities:function () {
var result = [].append(this._topics);
result.append(this._relationships);
return result;
},
removeTopic:function (topic) {
$assert(topic, "topic can not be null");
this._topics.erase(topic);
},
removeRelationship:function (rel) {
$assert(rel, "rel can not be null");
this._relationships.erase(rel);
},
addTopic:function (topic) {
$assert(topic, "topic can not be null");
this._topics.push(topic);
},
addRelationship:function (rel) {
2011-10-09 17:59:16 -03:00
$assert(rel, "rel can not be null");
this._relationships.push(rel);
2011-10-09 17:59:16 -03:00
},
filterTopicsIds:function (validate, errorMsg) {
var result = [];
var topics = this.filterSelectedTopics();
2011-10-04 01:16:29 -03:00
var isValid = true;
for (var i = 0; i < topics.length; i++) {
var selectedNode = topics[i];
if ($defined(validate)) {
isValid = validate(selectedNode);
}
// Add node only if it's valid.
if (isValid) {
result.push(selectedNode.getId());
} else {
$notify(errorMsg);
}
}
return result;
},
2011-08-25 22:08:39 -03:00
selectedTopic:function () {
2011-08-25 22:08:39 -03:00
var topics = this.filterSelectedTopics();
return (topics.length > 0) ? topics[0] : null;
2012-01-11 18:41:09 -03:00
},
findTopicById:function (id) {
2012-01-11 18:41:09 -03:00
var result = null;
for (var i = 0; i < this._topics.length; i++) {
var topic = this._topics[i];
if (topic.getId() == id) {
2012-01-11 18:41:09 -03:00
result = topic;
break;
}
}
return result;
2012-01-11 18:41:09 -03:00
}
});