Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
pbansal
Test-Docker
Commits
67a2fd65
Commit
67a2fd65
authored
Sep 17, 2019
by
Ian Sillitoe
Browse files
whitespace
parent
4fb57a3b
Changes
1
Hide whitespace changes
Inline
Side-by-side
static/admin/js/actions.js
View file @
67a2fd65
/*global gettext, interpolate, ngettext*/
(
function
(
$
)
{
(
function
(
$
)
{
'
use strict
'
;
var
lastChecked
;
$
.
fn
.
actions
=
function
(
opts
)
{
$
.
fn
.
actions
=
function
(
opts
)
{
var
options
=
$
.
extend
({},
$
.
fn
.
actions
.
defaults
,
opts
);
var
actionCheckboxes
=
$
(
this
);
var
list_editable_changed
=
false
;
var
showQuestion
=
function
()
{
var
showQuestion
=
function
()
{
$
(
options
.
acrossClears
).
hide
();
$
(
options
.
acrossQuestions
).
show
();
$
(
options
.
allContainer
).
hide
();
},
showClear
=
function
()
{
$
(
options
.
acrossClears
).
show
();
$
(
options
.
acrossQuestions
).
hide
();
$
(
options
.
actionContainer
).
toggleClass
(
options
.
selectedClass
);
$
(
options
.
allContainer
).
show
();
$
(
options
.
counterContainer
).
hide
();
},
reset
=
function
()
{
$
(
options
.
acrossClears
).
hide
();
$
(
options
.
acrossQuestions
).
hide
();
$
(
options
.
allContainer
).
hide
();
$
(
options
.
counterContainer
).
show
();
},
clearAcross
=
function
()
{
reset
();
$
(
options
.
acrossInput
).
val
(
0
);
$
(
options
.
actionContainer
).
removeClass
(
options
.
selectedClass
);
},
checker
=
function
(
checked
)
{
if
(
checked
)
{
showQuestion
();
}
else
{
showClear
=
function
()
{
$
(
options
.
acrossClears
).
show
();
$
(
options
.
acrossQuestions
).
hide
();
$
(
options
.
actionContainer
).
toggleClass
(
options
.
selectedClass
);
$
(
options
.
allContainer
).
show
();
$
(
options
.
counterContainer
).
hide
();
},
reset
=
function
()
{
$
(
options
.
acrossClears
).
hide
();
$
(
options
.
acrossQuestions
).
hide
();
$
(
options
.
allContainer
).
hide
();
$
(
options
.
counterContainer
).
show
();
},
clearAcross
=
function
()
{
reset
();
}
$
(
actionCheckboxes
).
prop
(
"
checked
"
,
checked
)
.
parent
().
parent
().
toggleClass
(
options
.
selectedClass
,
checked
);
},
updateCounter
=
function
()
{
var
sel
=
$
(
actionCheckboxes
).
filter
(
"
:checked
"
).
length
;
// data-actions-icnt is defined in the generated HTML
// and contains the total amount of objects in the queryset
var
actions_icnt
=
$
(
'
.action-counter
'
).
data
(
'
actionsIcnt
'
);
$
(
options
.
counterContainer
).
html
(
interpolate
(
ngettext
(
'
%(sel)s of %(cnt)s selected
'
,
'
%(sel)s of %(cnt)s selected
'
,
sel
),
{
sel
:
sel
,
cnt
:
actions_icnt
},
true
));
$
(
options
.
allToggle
).
prop
(
"
checked
"
,
function
()
{
var
value
;
if
(
sel
===
actionCheckboxes
.
length
)
{
value
=
true
;
$
(
options
.
acrossInput
).
val
(
0
);
$
(
options
.
actionContainer
).
removeClass
(
options
.
selectedClass
);
},
checker
=
function
(
checked
)
{
if
(
checked
)
{
showQuestion
();
}
else
{
value
=
false
;
clearAcross
();
reset
();
}
return
value
;
});
};
$
(
actionCheckboxes
).
prop
(
"
checked
"
,
checked
)
.
parent
().
parent
().
toggleClass
(
options
.
selectedClass
,
checked
);
},
updateCounter
=
function
()
{
var
sel
=
$
(
actionCheckboxes
).
filter
(
"
:checked
"
).
length
;
// data-actions-icnt is defined in the generated HTML
// and contains the total amount of objects in the queryset
var
actions_icnt
=
$
(
'
.action-counter
'
).
data
(
'
actionsIcnt
'
);
$
(
options
.
counterContainer
).
html
(
interpolate
(
ngettext
(
'
%(sel)s of %(cnt)s selected
'
,
'
%(sel)s of %(cnt)s selected
'
,
sel
),
{
sel
:
sel
,
cnt
:
actions_icnt
},
true
));
$
(
options
.
allToggle
).
prop
(
"
checked
"
,
function
()
{
var
value
;
if
(
sel
===
actionCheckboxes
.
length
)
{
value
=
true
;
showQuestion
();
}
else
{
value
=
false
;
clearAcross
();
}
return
value
;
});
};
// Show counter by default
$
(
options
.
counterContainer
).
show
();
// Check state of checkboxes and reinit state if needed
$
(
this
).
filter
(
"
:checked
"
).
each
(
function
(
i
)
{
$
(
this
).
filter
(
"
:checked
"
).
each
(
function
(
i
)
{
$
(
this
).
parent
().
parent
().
toggleClass
(
options
.
selectedClass
);
updateCounter
();
if
(
$
(
options
.
acrossInput
).
val
()
===
1
)
{
showClear
();
}
});
$
(
options
.
allToggle
).
show
().
on
(
'
click
'
,
function
()
{
$
(
options
.
allToggle
).
show
().
on
(
'
click
'
,
function
()
{
checker
(
$
(
this
).
prop
(
"
checked
"
));
updateCounter
();
});
$
(
"
a
"
,
options
.
acrossQuestions
).
on
(
'
click
'
,
function
(
event
)
{
$
(
"
a
"
,
options
.
acrossQuestions
).
on
(
'
click
'
,
function
(
event
)
{
event
.
preventDefault
();
$
(
options
.
acrossInput
).
val
(
1
);
showClear
();
});
$
(
"
a
"
,
options
.
acrossClears
).
on
(
'
click
'
,
function
(
event
)
{
$
(
"
a
"
,
options
.
acrossClears
).
on
(
'
click
'
,
function
(
event
)
{
event
.
preventDefault
();
$
(
options
.
allToggle
).
prop
(
"
checked
"
,
false
);
clearAcross
();
...
...
@@ -88,14 +88,14 @@
updateCounter
();
});
lastChecked
=
null
;
$
(
actionCheckboxes
).
on
(
'
click
'
,
function
(
event
)
{
$
(
actionCheckboxes
).
on
(
'
click
'
,
function
(
event
)
{
if
(
!
event
)
{
event
=
window
.
event
;
}
var
target
=
event
.
target
?
event
.
target
:
event
.
srcElement
;
if
(
lastChecked
&&
$
.
data
(
lastChecked
)
!==
$
.
data
(
target
)
&&
event
.
shiftKey
===
true
)
{
var
inrange
=
false
;
$
(
lastChecked
).
prop
(
"
checked
"
,
target
.
checked
)
.
parent
().
parent
().
toggleClass
(
options
.
selectedClass
,
target
.
checked
);
$
(
actionCheckboxes
).
each
(
function
()
{
$
(
actionCheckboxes
).
each
(
function
()
{
if
(
$
.
data
(
this
)
===
$
.
data
(
lastChecked
)
||
$
.
data
(
this
)
===
$
.
data
(
target
))
{
inrange
=
(
inrange
)
?
false
:
true
;
}
...
...
@@ -109,17 +109,17 @@
lastChecked
=
target
;
updateCounter
();
});
$
(
'
form#changelist-form table#result_list tr
'
).
on
(
'
change
'
,
'
td:gt(0) :input
'
,
function
()
{
$
(
'
form#changelist-form table#result_list tr
'
).
on
(
'
change
'
,
'
td:gt(0) :input
'
,
function
()
{
list_editable_changed
=
true
;
});
$
(
'
form#changelist-form button[name="index"]
'
).
on
(
'
click
'
,
function
(
event
)
{
$
(
'
form#changelist-form button[name="index"]
'
).
on
(
'
click
'
,
function
(
event
)
{
if
(
list_editable_changed
)
{
return
confirm
(
gettext
(
"
You have unsaved changes on individual editable fields. If you run an action, your unsaved changes will be lost.
"
));
}
});
$
(
'
form#changelist-form input[name="_save"]
'
).
on
(
'
click
'
,
function
(
event
)
{
$
(
'
form#changelist-form input[name="_save"]
'
).
on
(
'
click
'
,
function
(
event
)
{
var
action_changed
=
false
;
$
(
'
select option:selected
'
,
options
.
actionContainer
).
each
(
function
()
{
$
(
'
select option:selected
'
,
options
.
actionContainer
).
each
(
function
()
{
if
(
$
(
this
).
val
())
{
action_changed
=
true
;
}
...
...
@@ -144,7 +144,7 @@
allToggle
:
"
#action-toggle
"
,
selectedClass
:
"
selected
"
};
$
(
document
).
ready
(
function
()
{
$
(
document
).
ready
(
function
()
{
var
$actionsEls
=
$
(
'
tr input.action-select
'
);
if
(
$actionsEls
.
length
>
0
)
{
$actionsEls
.
actions
();
...
...
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