2011-08-25 04:41:39 +02:00
|
|
|
/*
|
|
|
|
* 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({
|
2011-10-04 06:16:29 +02:00
|
|
|
Implements: [Events],
|
2011-08-25 04:41:39 +02:00
|
|
|
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;
|
|
|
|
},
|
|
|
|
|
|
|
|
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;
|
|
|
|
},
|
|
|
|
|
|
|
|
filterSelectedRelations : function() {
|
|
|
|
var result = [];
|
|
|
|
for (var id in this._relationships) {
|
|
|
|
var relationship = this._relationships[id];
|
|
|
|
if (relationship.isOnFocus()) {
|
|
|
|
result.push(relationship);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
},
|
|
|
|
|
|
|
|
getObjects : function() {
|
|
|
|
var result = [].append(this._topics);
|
|
|
|
for (var id in this._relationships) {
|
|
|
|
result.push(this._relationships[id]);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
},
|
|
|
|
|
|
|
|
removeTopic : function(topic) {
|
|
|
|
$assert(topic, "topic can not be null");
|
|
|
|
this._topics.erase(topic);
|
|
|
|
},
|
|
|
|
|
|
|
|
addTopic : function(topic) {
|
|
|
|
$assert(topic, "topic can not be null");
|
|
|
|
this._topics.push(topic);
|
|
|
|
},
|
|
|
|
|
2011-10-09 22:59:16 +02:00
|
|
|
addRelationship : function(id, rel) {
|
|
|
|
$assert(rel, "rel can not be null");
|
|
|
|
$assert(id, "id can not be null");
|
|
|
|
|
|
|
|
this._relationships[id] = rel;
|
|
|
|
},
|
|
|
|
|
2011-08-25 04:41:39 +02:00
|
|
|
filterTopicsIds : function(validate, errorMsg) {
|
|
|
|
var result = [];
|
|
|
|
var topics = this.filterSelectedTopics();
|
|
|
|
|
2011-10-04 06:16:29 +02: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 {
|
2011-11-28 21:11:02 +01:00
|
|
|
$notify(errorMsg);
|
2011-08-25 04:41:39 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
},
|
|
|
|
|
|
|
|
filterRelationIds : function(validate, errorMsg) {
|
|
|
|
var result = [];
|
|
|
|
var relationships = this.filterSelectedRelations();
|
2011-10-04 06:16:29 +02:00
|
|
|
|
|
|
|
var isValid = true;
|
|
|
|
for (var j = 0; j < relationships.length; j++) {
|
|
|
|
var selectedLine = relationships[j];
|
|
|
|
isValid = true;
|
|
|
|
if ($defined(validate)) {
|
|
|
|
isValid = validate(selectedLine);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isValid) {
|
|
|
|
result.push(selectedLine.getId());
|
|
|
|
} else {
|
2011-11-28 21:11:02 +01:00
|
|
|
$notify(errorMsg);
|
2011-08-25 04:41:39 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
},
|
|
|
|
|
|
|
|
getRelationshipsById : function() {
|
|
|
|
return this._relationships;
|
2011-08-26 03:08:39 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
selectedTopic : function() {
|
|
|
|
var topics = this.filterSelectedTopics();
|
|
|
|
return (topics.length > 0) ? topics[0] : null;
|
2012-01-11 22:41:09 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
findTopicById: function(id) {
|
|
|
|
var result = null;
|
|
|
|
for (var i = 0; i < this._topics.length; i++) {
|
|
|
|
var topic = this._topics[i];
|
|
|
|
if(topic.getId()==id){
|
|
|
|
result = topic;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
2011-08-25 04:41:39 +02:00
|
|
|
|
2012-01-11 22:41:09 +01:00
|
|
|
}
|
2011-08-25 04:41:39 +02:00
|
|
|
});
|