|
@@ -26,8 +26,8 @@ define([ "require", "backbone", "hbs!tmpl/entity/CreateEntityLayoutView_tmpl", "
|
|
|
initialize: function(options) {
|
|
|
_.extend(this, _.pick(options, "guid", "callback", "showLoader", "entityDefCollection", "typeHeaders", "searchVent"));
|
|
|
var entityTitle, okLabel, that = this;
|
|
|
- this.selectStoreCollection = new Backbone.Collection(), this.collection = new VEntityList(),
|
|
|
- this.entityModel = new VEntity(), this.guid && (this.collection.modelAttrName = "createEntity"),
|
|
|
+ this.selectStoreCollection = new Backbone.Collection(), this.collection = new VEntityList(),
|
|
|
+ this.entityModel = new VEntity(), this.guid && (this.collection.modelAttrName = "createEntity"),
|
|
|
this.asyncReferEntityCounter = 0, this.required = !0, this.guid ? (entityTitle = "编辑实体",
|
|
|
okLabel = "更新") : (entityTitle = "创建实体", okLabel = "创建"), this.modal = new Modal({
|
|
|
title: entityTitle,
|
|
@@ -51,23 +51,23 @@ define([ "require", "backbone", "hbs!tmpl/entity/CreateEntityLayoutView_tmpl", "
|
|
|
}, this);
|
|
|
},
|
|
|
onRender: function() {
|
|
|
- this.bindEvents(), this.guid || this.bindRequiredField(), this.showLoader(), this.fetchCollections(),
|
|
|
+ this.bindEvents(), this.guid || this.bindRequiredField(), this.showLoader(), this.fetchCollections(),
|
|
|
this.$(".toggleRequiredSwitch").hide();
|
|
|
},
|
|
|
bindRequiredField: function() {
|
|
|
var that = this;
|
|
|
this.ui.entityInputData.on("keyup change", "textarea", function(e) {
|
|
|
var value = this.value;
|
|
|
- if (!value.length && $(this).hasClass("false")) $(this).removeClass("errorClass"),
|
|
|
+ if (!value.length && $(this).hasClass("false")) $(this).removeClass("errorClass"),
|
|
|
that.modal.$el.find("button.ok").prop("disabled", !1); else try {
|
|
|
- value && value.length && (JSON.parse(value), $(this).removeClass("errorClass"),
|
|
|
+ value && value.length && (JSON.parse(value), $(this).removeClass("errorClass"),
|
|
|
that.modal.$el.find("button.ok").prop("disabled", !1));
|
|
|
} catch (err) {
|
|
|
$(this).addClass("errorClass"), that.modal.$el.find("button.ok").prop("disabled", !0);
|
|
|
}
|
|
|
}), this.ui.entityInputData.on("keyup change", "input.true,select.true", function(e) {
|
|
|
- "" !== this.value.trim() ? ($(this).data("select2") ? $(this).data("select2").$container.find(".select2-selection").removeClass("errorClass") : $(this).removeClass("errorClass"),
|
|
|
- 0 === that.ui.entityInputData.find(".errorClass").length && that.modal.$el.find("button.ok").prop("disabled", !1)) : (that.modal.$el.find("button.ok").prop("disabled", !0),
|
|
|
+ "" !== this.value.trim() ? ($(this).data("select2") ? $(this).data("select2").$container.find(".select2-selection").removeClass("errorClass") : $(this).removeClass("errorClass"),
|
|
|
+ 0 === that.ui.entityInputData.find(".errorClass").length && that.modal.$el.find("button.ok").prop("disabled", !1)) : (that.modal.$el.find("button.ok").prop("disabled", !0),
|
|
|
$(this).data("select2") ? $(this).data("select2").$container.find(".select2-selection").addClass("errorClass") : $(this).addClass("errorClass"));
|
|
|
});
|
|
|
},
|
|
@@ -125,17 +125,17 @@ define([ "require", "backbone", "hbs!tmpl/entity/CreateEntityLayoutView_tmpl", "
|
|
|
return string.charAt(0).toUpperCase() + string.slice(1);
|
|
|
},
|
|
|
requiredAllToggle: function(checked) {
|
|
|
- checked ? (this.ui.entityInputData.addClass("all").removeClass("required"), this.ui.entityInputData.find("div.true").show(),
|
|
|
- this.ui.entityInputData.find("fieldset div.true").show(), this.ui.entityInputData.find("fieldset").show(),
|
|
|
- this.required = !1) : (this.ui.entityInputData.addClass("required").removeClass("all"),
|
|
|
+ checked ? (this.ui.entityInputData.addClass("all").removeClass("required"), this.ui.entityInputData.find("div.true").show(),
|
|
|
+ this.ui.entityInputData.find("fieldset div.true").show(), this.ui.entityInputData.find("fieldset").show(),
|
|
|
+ this.required = !1) : (this.ui.entityInputData.addClass("required").removeClass("all"),
|
|
|
this.ui.entityInputData.find("fieldset").each(function() {
|
|
|
$(this).find("div").hasClass("false") || $(this).hide();
|
|
|
- }), this.ui.entityInputData.find("div.true").hide(), this.ui.entityInputData.find("fieldset div.true").hide(),
|
|
|
+ }), this.ui.entityInputData.find("div.true").hide(), this.ui.entityInputData.find("fieldset div.true").hide(),
|
|
|
this.required = !0);
|
|
|
},
|
|
|
onEntityChange: function(e, value) {
|
|
|
var that = this, typeName = value && value.get("entity") ? value.get("entity").typeName : null;
|
|
|
- this.guid || this.showLoader(), this.ui.entityInputData.empty(), typeName ? this.collection.url = UrlLinks.entitiesDefApiUrl(typeName) : e && (this.collection.url = UrlLinks.entitiesDefApiUrl(e.target.value),
|
|
|
+ this.guid || this.showLoader(), this.ui.entityInputData.empty(), typeName ? this.collection.url = UrlLinks.entitiesDefApiUrl(typeName) : e && (this.collection.url = UrlLinks.entitiesDefApiUrl(e.target.value),
|
|
|
this.collection.modelAttrName = "attributeDefs"), this.collection.fetch({
|
|
|
success: function(model, data) {
|
|
|
that.supuertypeFlag = 0, that.subAttributeData(data);
|
|
@@ -180,16 +180,16 @@ define([ "require", "backbone", "hbs!tmpl/entity/CreateEntityLayoutView_tmpl", "
|
|
|
htmlField: relationShipAttributeHtml,
|
|
|
relationshipType: !0,
|
|
|
alloptional: isAllRelationshipAttributeOptinal
|
|
|
- })), fieldElemetHtml.length ? (that.ui.entityInputData.append(fieldElemetHtml),
|
|
|
+ })), fieldElemetHtml.length ? (that.ui.entityInputData.append(fieldElemetHtml),
|
|
|
_.each(_.keys(visitedAttr), function(key) {
|
|
|
if (null !== visitedAttr[key]) {
|
|
|
var elFound = that.ui.entityInputData.find('[data-key="' + key + '"]');
|
|
|
elFound.prop("disabled", !0), elFound.parent().prepend(visitedAttr[key]);
|
|
|
}
|
|
|
- })) : (fieldElemetHtml = "<h4 class='text-center'>Defination not found</h4>", that.ui.entityInputData.append(fieldElemetHtml))),
|
|
|
+ })) : (fieldElemetHtml = "<h4 class='text-center'>Defination not found</h4>", that.ui.entityInputData.append(fieldElemetHtml))),
|
|
|
that.ui.entityInputData.find("select[data-for-key]").select2({}).on("change", function() {
|
|
|
var forKey = $(this).data("forKey"), forKeyEl = null;
|
|
|
- forKey && forKey.length && (forKeyEl = that.ui.entityInputData.find('[data-key="' + forKey + '"]'),
|
|
|
+ forKey && forKey.length && (forKeyEl = that.ui.entityInputData.find('[data-key="' + forKey + '"]'),
|
|
|
forKeyEl && ("" == this.value ? (forKeyEl.val(null).trigger("change"), forKeyEl.prop("disabled", !0)) : forKeyEl.prop("disabled", !1)));
|
|
|
}), !1;
|
|
|
},
|
|
@@ -204,11 +204,11 @@ define([ "require", "backbone", "hbs!tmpl/entity/CreateEntityLayoutView_tmpl", "
|
|
|
if (void 0 === _.find(attributeDefs.relationshipAttributeDefs, {
|
|
|
name: obj.name
|
|
|
})) return !0;
|
|
|
- })), attributeDefs.attributeDefs.length || attributeDefs.relationshipAttributeDefs.length ? this.$(".toggleRequiredSwitch").show() : this.$(".toggleRequiredSwitch").hide(),
|
|
|
+ })), attributeDefs.attributeDefs.length || attributeDefs.relationshipAttributeDefs.length ? this.$(".toggleRequiredSwitch").show() : this.$(".toggleRequiredSwitch").hide(),
|
|
|
this.renderAttribute({
|
|
|
attributeDefs: attributeDefs
|
|
|
- }), this.required && (this.ui.entityInputData.find("fieldset div.true").hide(),
|
|
|
- this.ui.entityInputData.find("div.true").hide()), "placeholder" in HTMLInputElement.prototype || this.ui.entityInputData.find("input,select,textarea").placeholder(),
|
|
|
+ }), this.required && (this.ui.entityInputData.find("fieldset div.true").hide(),
|
|
|
+ this.ui.entityInputData.find("div.true").hide()), "placeholder" in HTMLInputElement.prototype || this.ui.entityInputData.find("input,select,textarea").placeholder(),
|
|
|
that.initilizeElements();
|
|
|
},
|
|
|
initilizeElements: function() {
|
|
@@ -221,14 +221,14 @@ define([ "require", "backbone", "hbs!tmpl/entity/CreateEntityLayoutView_tmpl", "
|
|
|
}
|
|
|
};
|
|
|
this.$('input[data-type="date"]').each(function() {
|
|
|
- $(this).data("daterangepicker") || (that.guid && this.value.length && (dateObj.startDate = new Date(Number(this.value))),
|
|
|
- "modifiedTime" === $(this).attr("name") && (dateObj.minDate = $createTime.val()),
|
|
|
+ $(this).data("daterangepicker") || (that.guid && this.value.length && (dateObj.startDate = new Date(Number(this.value))),
|
|
|
+ "modifiedTime" === $(this).attr("name") && (dateObj.minDate = $createTime.val()),
|
|
|
$(this).daterangepicker(dateObj));
|
|
|
}), modifiedDateObj = _.extend({}, dateObj), $createTime.on("apply.daterangepicker", function(ev, picker) {
|
|
|
that.modal.$el.find('input[name="modifiedTime"]').daterangepicker(_.extend(modifiedDateObj, {
|
|
|
minDate: $createTime.val()
|
|
|
}));
|
|
|
- }), this.initializeValidation(), this.ui.entityInputData.find("fieldset").length > 0 && 0 === this.ui.entityInputData.find("select.true,input.true").length && (this.requiredAllToggle(0 === this.ui.entityInputData.find("select.true,input.true").length),
|
|
|
+ }), this.initializeValidation(), this.ui.entityInputData.find("fieldset").length > 0 && 0 === this.ui.entityInputData.find("select.true,input.true").length && (this.requiredAllToggle(0 === this.ui.entityInputData.find("select.true,input.true").length),
|
|
|
this.guid || this.bindNonRequiredField()), this.$('select[data-type="boolean"]').each(function(value, key) {
|
|
|
var dataKey = $(key).data("key");
|
|
|
if (that.entityData) {
|
|
@@ -256,10 +256,10 @@ define([ "require", "backbone", "hbs!tmpl/entity/CreateEntityLayoutView_tmpl", "
|
|
|
},
|
|
|
getContainer: function(object) {
|
|
|
var value = object.value, entityLabel = this.capitalize(_.escape(value.name));
|
|
|
- return '<div class=" row ' + value.isOptional + '"><span class="col-sm-3"><label><span class="' + (value.isOptional ? "true" : "false required") + '">' + entityLabel + '</span><span class="center-block ellipsis-with-margin text-gray" title="日期类型: ' + value.typeName + '">(' + _.escape(value.typeName) + ')</span></label></span><span class="col-sm-9">' + this.getElement(object) + "</input></span></div>";
|
|
|
+ return '<div class=" row ' + value.isOptional + '"><span class="col-sm-3"><label><span class="' + (value.isOptional ? "true" : "false required") + '">' + entityLabel + '</span><span class="center-block ellipsis-with-margin text-gray" title="类型: ' + value.typeName + '">(' + _.escape(value.typeName) + ')</span></label></span><span class="col-sm-9">' + this.getElement(object) + "</input></span></div>";
|
|
|
},
|
|
|
getFieldElementContainer: function(object) {
|
|
|
- var htmlField = object.htmlField, relationshipType = (!!object.attributeType && object.attributeType,
|
|
|
+ var htmlField = object.htmlField, relationshipType = (!!object.attributeType && object.attributeType,
|
|
|
!!object.relationshipType && object.relationshipType), alloptional = object.alloptional, typeOfDefination = relationshipType ? "Relationships" : "Attributes";
|
|
|
return '<div class="attribute-dash-box ' + (alloptional ? "alloptional" : "") + ' "><span class="attribute-type-label">' + typeOfDefination + "</span>" + htmlField + "</div>";
|
|
|
},
|
|
@@ -267,7 +267,7 @@ define([ "require", "backbone", "hbs!tmpl/entity/CreateEntityLayoutView_tmpl", "
|
|
|
var value = object.value, name = _.escape(value.name), entityValue = _.escape(object.entityValue), isAttribute = object.isAttribute, isRelation = object.isRelation;
|
|
|
if ("boolean" === value.typeName) return '<select class="form-control row-margin-bottom ' + (value.isOptional === !0 ? "false" : "true") + '" data-type="' + value.typeName + '" data-attribute="' + isAttribute + '" data-relation="' + isRelation + '" data-key="' + name + '" data-id="entityInput"><option value="">--选择是或否--</option><option value="true">是</option><option value="false">否</option></select>';
|
|
|
var splitTypeName = value.typeName.split("<");
|
|
|
- return splitTypeName = splitTypeName.length > 1 ? splitTypeName[1].split(">")[0] : value.typeName,
|
|
|
+ return splitTypeName = splitTypeName.length > 1 ? splitTypeName[1].split(">")[0] : value.typeName,
|
|
|
'<select class="form-control row-margin-bottom entityInputBox ' + (value.isOptional === !0 ? "false" : "true") + '" data-type="' + value.typeName + '" data-attribute="' + isAttribute + '" data-relation="' + isRelation + '" data-key="' + name + '" data-id="entitySelectData" data-queryData="' + splitTypeName + '">' + (this.guid ? entityValue : "") + "</select>";
|
|
|
},
|
|
|
getTextArea: function(object) {
|
|
@@ -288,7 +288,7 @@ define([ "require", "backbone", "hbs!tmpl/entity/CreateEntityLayoutView_tmpl", "
|
|
|
var value = object.value, isAttribute = object.isAttribute, isRelation = object.isRelation, typeName = value.typeName, entityValue = "";
|
|
|
if (this.guid) {
|
|
|
var dataValue = this.entityData.get("entity").attributes[value.name];
|
|
|
- _.isObject(dataValue) ? entityValue = JSON.stringify(dataValue) : (dataValue && (entityValue = dataValue),
|
|
|
+ _.isObject(dataValue) ? entityValue = JSON.stringify(dataValue) : (dataValue && (entityValue = dataValue),
|
|
|
"date" === value.typeName && (entityValue = dataValue ? moment(dataValue) : Utils.formatDate({
|
|
|
zone: !1,
|
|
|
dateFormat: Globals.dateFormat
|
|
@@ -354,7 +354,7 @@ define([ "require", "backbone", "hbs!tmpl/entity/CreateEntityLayoutView_tmpl", "
|
|
|
} catch (err) {
|
|
|
throw new Error(err.message);
|
|
|
}
|
|
|
- if ($(this).hasClass("true") && ("" == value || void 0 == value)) throw $(this).data("select2") ? $(this).data("select2").$container.find(".select2-selection").addClass("errorClass") : $(this).addClass("errorClass"),
|
|
|
+ if ($(this).hasClass("true") && ("" == value || void 0 == value)) throw $(this).data("select2") ? $(this).data("select2").$container.find(".select2-selection").addClass("errorClass") : $(this).addClass("errorClass"),
|
|
|
that.hideLoader(), that.modal.$el.find("button.ok").hideButtonLoader(), new Error("Please fill the required fields");
|
|
|
var dataTypeEnitity = $(this).data("type"), datakeyEntity = $(this).data("key"), typeName = $(this).data("querydata"), attribute = "undefined" != $(this).data("attribute"), relation = "undefined" != $(this).data("relation"), typeNameCategory = that.typeHeaders.fullCollection.findWhere({
|
|
|
name: dataTypeEnitity
|
|
@@ -421,26 +421,26 @@ define([ "require", "backbone", "hbs!tmpl/entity/CreateEntityLayoutView_tmpl", "
|
|
|
},
|
|
|
hideLoader: function(options) {
|
|
|
var editVisiblityOfEntitySelectionBox = options && options.editVisiblityOfEntitySelectionBox;
|
|
|
- this.$(".entityLoader").removeClass("show"), this.$(".entityInputData").show(),
|
|
|
- (this.guid || editVisiblityOfEntitySelectionBox) && this.ui.entitySelectionBox.show(),
|
|
|
+ this.$(".entityLoader").removeClass("show"), this.$(".entityInputData").show(),
|
|
|
+ (this.guid || editVisiblityOfEntitySelectionBox) && this.ui.entitySelectionBox.show(),
|
|
|
this.ui.entityList.select2("open"), this.ui.entityList.select2("close");
|
|
|
},
|
|
|
addJsonSearchData: function() {
|
|
|
var that = this;
|
|
|
this.$('select[data-id="entitySelectData"]').each(function(value, key) {
|
|
|
- var $this = $(this), keyData = $(this).data("key"), typeData = $(this).data("type"), queryData = $(this).data("querydata"), placeholderName = ($(this).data("skip"),
|
|
|
+ var $this = $(this), keyData = $(this).data("key"), typeData = $(this).data("type"), queryData = $(this).data("querydata"), placeholderName = ($(this).data("skip"),
|
|
|
"请从以下列表中选择一个" + typeData);
|
|
|
if ($this.attr("multiple", $this.data("type").indexOf("array") !== -1), that.guid) {
|
|
|
- var dataValue = that.entityData.get("entity").attributes[keyData], relationshipType = (that.entityData.get("entity").attributes,
|
|
|
+ var dataValue = that.entityData.get("entity").attributes[keyData], relationshipType = (that.entityData.get("entity").attributes,
|
|
|
that.entityData.get("entity").relationshipAttributes ? that.entityData.get("entity").relationshipAttributes[keyData] : null), referredEntities = that.entityData.get("referredEntities"), selectedValue = [], select2Options = [];
|
|
|
- if (dataValue && (_.isObject(dataValue) && !_.isArray(dataValue) && (dataValue = [ dataValue ]),
|
|
|
+ if (dataValue && (_.isObject(dataValue) && !_.isArray(dataValue) && (dataValue = [ dataValue ]),
|
|
|
_.each(dataValue, function(obj) {
|
|
|
if (_.isObject(obj) && obj.guid && referredEntities[obj.guid]) {
|
|
|
var refEntiyFound = referredEntities[obj.guid];
|
|
|
- refEntiyFound.id = refEntiyFound.guid, Enums.entityStateReadOnly[refEntiyFound.status] || (select2Options.push(refEntiyFound),
|
|
|
+ refEntiyFound.id = refEntiyFound.guid, Enums.entityStateReadOnly[refEntiyFound.status] || (select2Options.push(refEntiyFound),
|
|
|
selectedValue.push(refEntiyFound.guid));
|
|
|
}
|
|
|
- }), _.isUndefined(relationshipType) || relationshipType && relationshipType.relationshipAttributes && relationshipType.relationshipAttributes.typeName && that.$("select[data-for-key=" + keyData + "]").val(relationshipType.relationshipAttributes.typeName).trigger("change")),
|
|
|
+ }), _.isUndefined(relationshipType) || relationshipType && relationshipType.relationshipAttributes && relationshipType.relationshipAttributes.typeName && that.$("select[data-for-key=" + keyData + "]").val(relationshipType.relationshipAttributes.typeName).trigger("change")),
|
|
|
0 === selectedValue.length && dataValue && dataValue.length && "string" === $this.data("querydata")) {
|
|
|
var str = "";
|
|
|
_.each(dataValue, function(obj) {
|
|
@@ -496,4 +496,4 @@ define([ "require", "backbone", "hbs!tmpl/entity/CreateEntityLayoutView_tmpl", "
|
|
|
}
|
|
|
});
|
|
|
return CreateEntityLayoutView;
|
|
|
-});
|
|
|
+});
|