Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
7e6a968c
Commit
7e6a968c
authored
Nov 07, 2014
by
cahrens
Committed by
Zia Fazal
Apr 07, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Set up validation_messages so that it goes through the RequireJS optimizer.
parent
6573dbbe
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
106 additions
and
25 deletions
+106
-25
cms/static/build.js
+2
-1
cms/static/coffee/spec/main.coffee
+2
-0
cms/static/js/factories/xblock_validation.js
+15
-0
cms/static/js/spec/factories/xblock_validation_spec.js
+78
-0
cms/templates/studio_xblock_wrapper.html
+9
-24
No files found.
cms/static/build.js
View file @
7e6a968c
...
...
@@ -45,7 +45,8 @@
'js/factories/settings'
,
'js/factories/settings_advanced'
,
'js/factories/settings_graders'
,
'js/factories/textbooks'
'js/factories/textbooks'
,
'js/factories/xblock_validation'
]),
/**
* By default all the configuration for optimization happens from the command
...
...
cms/static/coffee/spec/main.coffee
View file @
7e6a968c
...
...
@@ -244,6 +244,8 @@ define([
"js/spec/views/modals/edit_xblock_spec"
,
"js/spec/views/modals/validation_error_modal_spec"
,
"js/spec/factories/xblock_validation_spec"
,
"js/spec/xblock/cms.runtime.v1_spec"
,
# these tests are run separately in the cms-squire suite, due to process
...
...
cms/static/js/factories/xblock_validation.js
0 → 100644
View file @
7e6a968c
define
([
"js/views/xblock_validation"
,
"js/models/xblock_validation"
],
function
(
XBlockValidationView
,
XBlockValidationModel
)
{
'use strict'
;
return
function
(
validationMessages
,
hasEditingUrl
,
isRoot
,
validationEle
)
{
if
(
hasEditingUrl
&&
!
isRoot
)
{
validationMessages
.
showSummaryOnly
=
true
;
}
var
model
=
new
XBlockValidationModel
(
validationMessages
,
{
parse
:
true
});
if
(
!
model
.
get
(
"empty"
))
{
new
XBlockValidationView
({
el
:
validationEle
,
model
:
model
,
root
:
isRoot
}).
render
();
}
};
});
cms/static/js/spec/factories/xblock_validation_spec.js
0 → 100644
View file @
7e6a968c
define
([
'jquery'
,
'js/factories/xblock_validation'
,
'js/common_helpers/template_helpers'
],
function
(
$
,
XBlockValidationFactory
,
TemplateHelpers
)
{
describe
(
'XBlockValidationFactory'
,
function
()
{
var
messageDiv
;
beforeEach
(
function
()
{
TemplateHelpers
.
installTemplate
(
'xblock-validation-messages'
);
appendSetFixtures
(
$
(
'<div class="messages"></div>'
));
messageDiv
=
$
(
'.messages'
);
});
it
(
'Does not attach a view if messages is empty'
,
function
()
{
XBlockValidationFactory
({
"empty"
:
true
},
false
,
false
,
messageDiv
);
expect
(
messageDiv
.
children
().
length
).
toEqual
(
0
);
});
it
(
'Does attach a view if messages are not empty'
,
function
()
{
XBlockValidationFactory
({
"empty"
:
false
},
false
,
false
,
messageDiv
);
expect
(
messageDiv
.
children
().
length
).
toEqual
(
1
);
});
it
(
'Passes through the root property to the view.'
,
function
()
{
var
noContainerContent
=
"no-container-content"
;
var
notConfiguredMessages
=
{
"empty"
:
false
,
"summary"
:
{
"text"
:
"my summary"
,
"type"
:
"not-configured"
},
"messages"
:
[],
"xblock_id"
:
"id"
};
// Root is false, will not add noContainerContent.
XBlockValidationFactory
(
notConfiguredMessages
,
true
,
false
,
messageDiv
);
expect
(
messageDiv
.
find
(
'.validation'
)).
not
.
toHaveClass
(
noContainerContent
);
// Root is true, will add noContainerContent.
XBlockValidationFactory
(
notConfiguredMessages
,
true
,
true
,
messageDiv
);
expect
(
messageDiv
.
find
(
'.validation'
)).
toHaveClass
(
noContainerContent
);
});
describe
(
'Controls display of detailed messages based on url and root property'
,
function
()
{
var
messagesWithSummary
,
checkDetailedMessages
;
beforeEach
(
function
()
{
messagesWithSummary
=
{
"empty"
:
false
,
"summary"
:
{
"text"
:
"my summary"
},
"messages"
:
[{
"text"
:
"one"
,
"type"
:
"warning"
},
{
"text"
:
"two"
,
"type"
:
"error"
}],
"xblock_id"
:
"id"
};
});
checkDetailedMessages
=
function
(
expectedDetailedMessages
)
{
expect
(
messageDiv
.
children
().
length
).
toEqual
(
1
);
expect
(
messageDiv
.
find
(
'.xblock-message-item'
).
length
).
toBe
(
expectedDetailedMessages
);
};
it
(
'Does not show details if xblock has an editing URL and it is not rendered as root'
,
function
()
{
XBlockValidationFactory
(
messagesWithSummary
,
true
,
false
,
messageDiv
);
checkDetailedMessages
(
0
);
});
it
(
'Shows details if xblock does not have its own editing URL, regardless of root value'
,
function
()
{
XBlockValidationFactory
(
messagesWithSummary
,
false
,
false
,
messageDiv
);
checkDetailedMessages
(
2
);
XBlockValidationFactory
(
messagesWithSummary
,
false
,
true
,
messageDiv
);
checkDetailedMessages
(
2
);
});
it
(
'Shows details if xblock has its own editing URL and is rendered as root'
,
function
()
{
XBlockValidationFactory
(
messagesWithSummary
,
true
,
true
,
messageDiv
);
checkDetailedMessages
(
2
);
});
});
});
}
);
cms/templates/studio_xblock_wrapper.html
View file @
7e6a968c
<
%!
from
django
.
utils
.
translation
import
ugettext
as
_
from
contentstore
.
views
.
helpers
import
xblock_studio_url
...
...
@@ -21,31 +20,17 @@ messages = json.dumps(xblock.validate().to_json())
</script>
</
%
block>
<script
type=
'text/javascript'
>
require
([
"js/views/xblock_validation"
,
"js/models/xblock_validation"
],
function
(
XBlockValidationView
,
XBlockValidationModel
)
{
var
validationMessages
=
$
{
messages
};
%
if
xblock_url
and
not
is_root
:
validationMessages
.
showSummaryOnly
=
true
;
%
endif
var
model
=
new
XBlockValidationModel
(
validationMessages
,
{
parse
:
true
});
if
(
!
model
.
get
(
"empty"
))
{
var
validationEle
=
$
(
'div.xblock-validation-messages[data-locator="${xblock.location | h}"]'
);
var
viewOptions
=
{
el
:
validationEle
,
model
:
model
};
%
if
is_root
:
viewOptions
.
root
=
true
;
%
endif
var
view
=
new
XBlockValidationView
(
viewOptions
);
view
.
render
();
}
});
<script>
require
([
"jquery"
,
"js/factories/xblock_validation"
],
function
(
$
,
XBlockValidationFactory
)
{
XBlockValidationFactory
(
$
{
messages
},
$
.
parseJSON
(
"${bool(xblock_url)}"
.
toLowerCase
()),
$
.
parseJSON
(
"${is_root == True}"
.
toLowerCase
()),
$
(
'div.xblock-validation-messages[data-locator="${xblock.location | h}"]'
)
);
});
</script>
% if not is_root:
% if is_reorderable:
<li
class=
"studio-xblock-wrapper is-draggable"
data-locator=
"${xblock.location | h}"
data-course-key=
"${xblock.location.course_key | h}"
>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment