-
Notifications
You must be signed in to change notification settings - Fork 192
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Data Configure screen, refactored Post Edit to split into sub d…
…irectives and PostEditService, added mode functionality for post edit to allow bulk data import mode
- Loading branch information
Showing
8 changed files
with
168 additions
and
186 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
module.exports = [ | ||
'_', | ||
'Util', | ||
function ( | ||
_, | ||
Util | ||
) { | ||
var PostEditService = { | ||
cleanPostValues: function (post) { | ||
_.each(post.values, function (value, key) { | ||
// Strip out empty values | ||
post.values[key] = _.filter(value); | ||
// Remove entirely if no values are left | ||
if (!post.values[key].length) { | ||
delete post.values[key]; | ||
} | ||
}); | ||
return post; | ||
}, | ||
canSavePost: function (post, form, stages, attributes) { | ||
var valid = true; | ||
if (post.status === 'published') { | ||
// first check if stages required have been marked complete | ||
var requiredStages = _.where(stages, {required: true}) ; | ||
|
||
valid = _.reduce(requiredStages, function (isValid, stage) { | ||
// if this stage isn't complete, add to errors | ||
if (_.indexOf(post.completed_stages, stage.id) === -1) { | ||
return false; | ||
} | ||
return isValid; | ||
}, valid); | ||
|
||
valid = _.reduce(post.completed_stages, function (isValid, stageId) { | ||
return this.isStageValid(stageId, form, stages, attributes) && isValid; | ||
}, valid); | ||
} | ||
|
||
return valid; | ||
}, | ||
isFirstStage: function (stages, stageId) { | ||
if (!_.isEmpty(stages)) { | ||
return stageId === stages[0].id; | ||
} | ||
return false; | ||
}, | ||
isStageValid: function (stageId, form, stages, attributes) { | ||
if (this.isFirstStage(stages, stageId)) { | ||
|
||
// The first stage is assumed to contain the title, content, and the tags | ||
// - these are not stored in attributes and do not have a 'required' field | ||
// thus, if any of these are invalid, the first stage is not ready to complete | ||
|
||
// Return if form isn't initialized yet | ||
if (!form) { | ||
return false; | ||
} | ||
|
||
if (form.title.$invalid || form.content.$invalid) { | ||
return false; | ||
} | ||
|
||
if (form.tags && form.tags.$invalid) { | ||
return false; | ||
} | ||
} | ||
// now checking all other post attributes that are required | ||
return _.chain(attributes) | ||
.where({form_stage_id : stageId, required: true}) | ||
.reduce(function (isValid, attr) { | ||
// checkbox validity needs to be handled differently | ||
// because it has multiple inputs identified via the options | ||
if (attr.input === 'checkbox') { | ||
var checkboxValidity = false; | ||
_.each(attr.options, function (option) { | ||
if (!_.isUndefined(form['values_' + attr.key + '_' + option]) && !form['values_' + attr.key + '_' + option].$invalid) { | ||
checkboxValidity = isValid; | ||
} | ||
}); | ||
return checkboxValidity; | ||
} else { | ||
if (_.isUndefined(form['values_' + attr.key]) || form['values_' + attr.key].$invalid) { | ||
return false; | ||
} | ||
return isValid; | ||
} | ||
}, true) | ||
.value(); | ||
} | ||
}; | ||
|
||
return Util.bindAllFunctionsToSelf(PostEditService); | ||
}]; |
Oops, something went wrong.