2015-02-20 05:14:55 +08:00
|
|
|
|
angular
|
|
|
|
|
.module("LayoutEditor")
|
|
|
|
|
.directive("orcLayoutForm", function ($compile, scopeConfigurator, environment) {
|
|
|
|
|
return {
|
|
|
|
|
restrict: "E",
|
|
|
|
|
scope: { element: "=" },
|
|
|
|
|
controller: function ($scope, $element) {
|
|
|
|
|
scopeConfigurator.configureForElement($scope, $element);
|
|
|
|
|
scopeConfigurator.configureForContainer($scope, $element);
|
|
|
|
|
$scope.sortableOptions["axis"] = "y";
|
|
|
|
|
$scope.edit = function () {
|
|
|
|
|
$scope.$root.editElement($scope.element).then(function (args) {
|
|
|
|
|
if (args.cancel)
|
|
|
|
|
return;
|
|
|
|
|
$scope.element.data = decodeURIComponent(args.element.data);
|
|
|
|
|
$scope.element.name = args.elementEditorModel.name;
|
2015-02-27 17:08:32 +08:00
|
|
|
|
$scope.element.formBindingContentType = args.elementEditorModel.formBindingContentType;
|
2015-02-20 05:14:55 +08:00
|
|
|
|
$scope.$apply();
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
templateUrl: environment.templateUrl("Form"),
|
|
|
|
|
replace: true
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
var LayoutEditor;
|
|
|
|
|
(function ($, LayoutEditor) {
|
|
|
|
|
|
|
|
|
|
LayoutEditor.Form = function (data, htmlId, htmlClass, htmlStyle, isTemplated, name, formBindingContentType, contentType, contentTypeLabel, contentTypeClass, hasEditor, children) {
|
|
|
|
|
LayoutEditor.Element.call(this, "Form", data, htmlId, htmlClass, htmlStyle, isTemplated);
|
|
|
|
|
LayoutEditor.Container.call(this, ["Grid", "Content"], children);
|
|
|
|
|
|
|
|
|
|
var self = this;
|
|
|
|
|
this.isContainable = true;
|
|
|
|
|
this.dropTargetClass = "layout-common-holder";
|
|
|
|
|
this.contentType = contentType;
|
|
|
|
|
this.contentTypeLabel = contentTypeLabel;
|
|
|
|
|
this.contentTypeClass = contentTypeClass;
|
|
|
|
|
this.name = name || "Untitled";
|
|
|
|
|
this.formBindingContentType = formBindingContentType;
|
|
|
|
|
this.hasEditor = hasEditor;
|
|
|
|
|
|
|
|
|
|
this.toObject = function () {
|
|
|
|
|
var result = this.elementToObject();
|
|
|
|
|
result.name = this.name;
|
2015-02-27 17:08:32 +08:00
|
|
|
|
result.formBindingContentType = this.formBindingContentType;
|
2015-02-20 05:14:55 +08:00
|
|
|
|
result.children = this.childrenToObject();
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var getEditorObject = this.getEditorObject;
|
|
|
|
|
this.getEditorObject = function() {
|
|
|
|
|
var dto = getEditorObject();
|
|
|
|
|
return $.extend(dto, {
|
|
|
|
|
FormName: this.name,
|
|
|
|
|
FormBindingContentType: this.formBindingContentType
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.setChildren = function (children) {
|
|
|
|
|
this.children = children;
|
|
|
|
|
_(this.children).each(function (child) {
|
|
|
|
|
child.parent = self;
|
2015-02-27 17:31:50 +08:00
|
|
|
|
self.linkChild(child);
|
2015-02-20 05:14:55 +08:00
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2015-02-27 17:31:50 +08:00
|
|
|
|
this.linkChild = function(element) {
|
|
|
|
|
var getEditorObject = element.getEditorObject;
|
|
|
|
|
element.getEditorObject = function () {
|
|
|
|
|
var dto = getEditorObject();
|
|
|
|
|
return $.extend(dto, {
|
|
|
|
|
FormBindingContentType: self.formBindingContentType
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
2015-02-20 05:14:55 +08:00
|
|
|
|
this.setChildren(children);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
LayoutEditor.Form.from = function (value) {
|
|
|
|
|
return new LayoutEditor.Form(
|
|
|
|
|
value.data,
|
|
|
|
|
value.htmlId,
|
|
|
|
|
value.htmlClass,
|
|
|
|
|
value.htmlStyle,
|
|
|
|
|
value.isTemplated,
|
|
|
|
|
value.name,
|
|
|
|
|
value.formBindingContentType,
|
|
|
|
|
value.contentType,
|
|
|
|
|
value.contentTypeLabel,
|
|
|
|
|
value.contentTypeClass,
|
|
|
|
|
value.hasEditor,
|
|
|
|
|
LayoutEditor.childrenFrom(value.children));
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
LayoutEditor.registerFactory("Form", function(value) { return LayoutEditor.Form.from(value); });
|
|
|
|
|
|
|
|
|
|
})(jQuery, LayoutEditor || (LayoutEditor = {}));
|