[open-ils-commits] r12308 - in trunk/Open-ILS/web: js/ui/default/conify/global/action js/ui/default/conify/global/action/survey templates/default/conify/global/action templates/default/conify/global/action/survey (erickson)
svn at svn.open-ils.org
svn at svn.open-ils.org
Thu Feb 26 11:06:31 EST 2009
Author: erickson
Date: 2009-02-26 11:06:29 -0500 (Thu, 26 Feb 2009)
New Revision: 12308
Added:
trunk/Open-ILS/web/js/ui/default/conify/global/action/survey.js
trunk/Open-ILS/web/js/ui/default/conify/global/action/survey/
trunk/Open-ILS/web/js/ui/default/conify/global/action/survey/edit.js
trunk/Open-ILS/web/templates/default/conify/global/action/survey.tt2
trunk/Open-ILS/web/templates/default/conify/global/action/survey/
trunk/Open-ILS/web/templates/default/conify/global/action/survey/edit.tt2
Log:
survey list and edit interface. some known issues (i18n) that will be cleanup up next
Added: trunk/Open-ILS/web/js/ui/default/conify/global/action/survey/edit.js
===================================================================
--- trunk/Open-ILS/web/js/ui/default/conify/global/action/survey/edit.js (rev 0)
+++ trunk/Open-ILS/web/js/ui/default/conify/global/action/survey/edit.js 2009-02-26 16:06:29 UTC (rev 12308)
@@ -0,0 +1,213 @@
+dojo.require('dojox.grid.DataGrid');
+dojo.require('dojox.grid.cells.dijit');
+dojo.require('dojo.data.ItemFileWriteStore');
+dojo.require('dojo.date.stamp');
+dojo.require('dijit.form.TextBox');
+dojo.require('dijit.form.Button');
+dojo.require('dijit.Dialog');
+dojo.require('dojox.widget.PlaceholderMenuItem');
+dojo.require('fieldmapper.OrgUtils');
+dojo.require('openils.widget.OrgUnitFilteringSelect');
+dojo.require('openils.PermaCrud');
+dojo.require('openils.DojoPatch');
+dojo.require('openils.widget.GridColumnPicker');
+dojo.require('openils.widget.EditPane');
+
+var surveyId;
+var startDate;
+var endDate;
+var today;
+function drawSurvey(svyId) {
+ today = new Date();
+ var surveyTable = dojo.byId('edit-pane');
+ var surveyHead = dojo.create('thead', {style: "background-color: #99CCFF", innerHTML: "Survey ID #" +svyId}, surveyTable);
+ var pcrud = new openils.PermaCrud();
+ var survey = pcrud.retrieve('asv', svyId);
+ startDate = dojo.date.stamp.fromISOString(survey.start_date());
+ endDate = dojo.date.stamp.fromISOString(survey.end_date());
+ var pane = new openils.widget.EditPane({fmObject : survey, hideActionButtons:false}, dojo.byId('edit-pane'));
+ if ( endDate > today) {
+ var buttonBody = dojo.create( 'tbody', {innerHTML: "End Survey Now"}, surveyTable);
+ var endButton = new dijit.form.Button({onClick:function() {endSurvey(survey.id())} }, buttonBody);
+ }
+ pane.fieldOrder = ['id', 'name', 'description', 'owner', 'start_date', 'end_date'];
+ pane.onCancel = cancelEdit;
+ pane.startup();
+ getQuestions(svyId, survey);
+
+}
+
+function cancelEdit(){
+ document.location.href = "/eg/conify/global/action/survey";
+}
+
+function endSurvey(svyId) {
+ var pcrud = new openils.PermaCrud();
+ var survey = pcrud.retrieve('asv', svyId);
+ var today = new Date();
+ var date = dojo.date.stamp.toISOString(today);
+ survey.end_date(date);
+ survey.ischanged(true);
+ return pcrud.update(survey);
+
+}
+
+// all functions for question manipulation
+
+function getQuestions(svyId, survey) {
+
+ surveyId = svyId;
+
+ var pcrud = new openils.PermaCrud();
+ var questions = pcrud.search('asvq', {survey:svyId});
+
+ for(var i in questions) {
+ questionId = questions[i].id();
+ var answers = pcrud.search('asva', {question:questionId});
+ if (answers)
+ drawQuestionBody(questions[i], answers, survey);
+ }
+ if ( startDate > today) newQuestionBody(surveyId);
+}
+
+function newQuestionBody(svyId) {
+ var surveyTable = dojo.byId("survey_table");
+ var surveyBody = dojo.create('tbody', {style: "background-color: #d9e8f9"}, surveyTable);
+ var questionRow = dojo.create('tr', null, surveyBody);
+ var questionLabel = dojo.create('td',{ innerHTML: "Question"}, questionRow, "first");
+ var questionTextbox = dojo.create('td', null, questionRow, "second");
+ var qInput = new dijit.form.TextBox(null, questionTextbox);
+ var questionButton = dojo.create('td', { innerHTML: "Save & Add Answers" }, questionRow);
+ var qButton = new dijit.form.Button({onClick:function() {newQuestion(svyId, qInput.getValue(), questionRow)} }, questionButton);
+
+}
+
+function drawQuestionBody(question, answers, survey){
+
+ var surveyTable = dojo.byId('survey_table');
+ var surveyBody = dojo.create( 'tbody', {quid:question.id(), id:("q" + question.id()), style: "background-color: #d9e8f9"}, surveyTable);
+ var questionRow = dojo.create('tr', {quid:question.id()}, surveyBody);
+ var questionLabel = dojo.create('td', {quid:question.id(), innerHTML: "Question"}, questionRow, "first");
+ var questionTextbox = dojo.create('td', {quid: question.id() }, questionRow, "second");
+ var qInput = new dijit.form.TextBox(null, questionTextbox);
+ qInput.attr('value', question.question());
+ if (startDate > today){
+ var questionButton = dojo.create('td', {quid: question.id(), innerHTML: "Delete Question & Answers" }, questionRow);
+ var qButton = new dijit.form.Button({onClick:function() {deleteQuestion(question.id(), surveyBody) }}, questionButton);
+ var qChangesButton = dojo.create('td', {quid: question.id(), innerHTML: "Save Changes" }, questionRow);
+ var qcButton = new dijit.form.Button({onClick:function() {changeQuestion(question.id(), qInput.attr('value')) }}, qChangesButton);
+
+ }
+ for (var i in answers) {
+ if(!answers) return'';
+ drawAnswer(answers[i], question.id(), surveyBody, survey);
+ }
+ drawNewAnswerRow(question.id(), surveyBody);
+}
+
+function newQuestion(svyId, questionText, questionRow) {
+ var pcrud = new openils.PermaCrud();
+ var question = new asvq();
+ question.survey(svyId);
+ question.question(questionText);
+ question.isnew(true);
+ pcrud.create(question,
+ {oncomplete: function(r)
+ { var q = openils.Util.readResponse(r);
+ questionRow.parentNode.removeChild(questionRow);
+ drawQuestionBody(q, null);
+ newQuestionBody(svyId);
+ }
+ }
+ );
+}
+
+function changeQuestion(quesId, questionText) {
+ var pcrud = new openils.PermaCrud();
+ var question = pcrud.retrieve('asvq', quesId);
+ question.question(questionText);
+ question.ischanged(true);
+ return pcrud.update(question);
+}
+
+function deleteQuestion(quesId, surveyBody) {
+ var pcrud = new openils.PermaCrud();
+ var delQuestion = new asvq();
+ var answers = pcrud.search('asva', {question:quesId});
+ for(var i in answers){
+ var ansId = answers[i].id();
+ deleteAnswer(ansId);
+ }
+ delQuestion.id(quesId);
+ delQuestion.isdeleted(true);
+ surveyBody.parentNode.removeChild(surveyBody);
+ return pcrud.delete(delQuestion);
+
+}
+
+// all functions for answer manipulation
+
+function drawAnswer(answer, qid, surveyBody, survey) {
+ var surveyBody = dojo.byId(("q" + qid));
+ var answerRow = dojo.create('tr', {anid: answer.id(), style: "background-color: #FFF"}, surveyBody);
+ var answerSpacer = dojo.create('td', {anid: answer.id()}, answerRow, "first");
+ var answerLabel = dojo.create('td', {anid: answer.id(), style: "float: right", innerHTML: "Answer" }, answerRow, "second");
+ var answerTextbox = dojo.create('td', {anid: answer.id() }, answerRow, "third");
+ var input = new dijit.form.TextBox(null, answerTextbox);
+ input.attr('value', answer.answer());
+ if (startDate > today){
+ var answerSpacer = dojo.create('td', {anid: answer.id()}, answerRow);
+ var delanswerButton = dojo.create('td', {anid: answer.id(), innerHTML: "Delete Answer" }, answerRow);
+ var aid = answer.id();
+ var aButton = new dijit.form.Button({onClick:function(){deleteAnswer(aid);answerRow.parentNode.removeChild(answerRow)} }, delanswerButton);
+ var aChangesButton = dojo.create('td', {anid: qid, innerHTML: "Save Changes" }, answerRow);
+ var acButton = new dijit.form.Button({onClick:function() {changeAnswer(answer.id(), input.attr('value')) }}, aChangesButton);
+ }
+}
+
+function drawNewAnswerRow(qid, surveyBody) {
+ var answerRow = dojo.create('tr', {quid: qid, style: "background-color: #FFF"}, surveyBody);
+ var answerSpacer = dojo.create('td', {quid: qid}, answerRow, "first");
+ var answerLabel = dojo.create('td', {quid: qid, innerHTML: "Answer", style: "float:right" }, answerRow, "second");
+ var answerTextbox = dojo.create('td', {quid: qid }, answerRow, "third");
+ var input = new dijit.form.TextBox(null, answerTextbox);
+ var answerButton = dojo.create('td', {anid: qid, innerHTML: "Add Answer" }, answerRow);
+ var aButton = new dijit.form.Button({onClick:function() {newAnswer(qid, input.attr('value'), answerRow, surveyBody)} }, answerButton);
+
+}
+
+
+function deleteAnswer(ansId) {
+ var pcrud = new openils.PermaCrud();
+ var delAnswer = new asva();
+ delAnswer.id(ansId);
+ delAnswer.isdeleted(true);
+ return pcrud.delete(delAnswer);
+
+}
+function newAnswer(quesId, answerText, answerRow, surveyBody) {
+ var pcrud = new openils.PermaCrud();
+ var answer = new asva();
+ answer.question(quesId);
+ answer.answer(answerText);
+ answer.isnew(true);
+ answerRow.parentNode.removeChild(answerRow);
+ drawAnswer(answer, answer.question());
+ drawNewAnswerRow(quesId, surveyBody);
+ return pcrud.create(answer);
+}
+
+
+function changeAnswer(ansId, answerText) {
+ var pcrud = new openils.PermaCrud();
+ var answer = pcrud.retrieve('asva', ansId);
+ answer.answer(answerText);
+ answer.ischanged(true);
+ return pcrud.update(answer);
+}
+
+
+
+
+
+
Added: trunk/Open-ILS/web/js/ui/default/conify/global/action/survey.js
===================================================================
--- trunk/Open-ILS/web/js/ui/default/conify/global/action/survey.js (rev 0)
+++ trunk/Open-ILS/web/js/ui/default/conify/global/action/survey.js 2009-02-26 16:06:29 UTC (rev 12308)
@@ -0,0 +1,196 @@
+dojo.require('dojox.grid.DataGrid');
+dojo.require('dojox.grid.cells.dijit');
+dojo.require('dojo.data.ItemFileWriteStore');
+dojo.require('dijit.form.TextBox');
+dojo.require('dijit.form.CurrencyTextBox');
+dojo.require('dijit.Dialog');
+dojo.require('dojox.widget.PlaceholderMenuItem');
+dojo.require('fieldmapper.OrgUtils');
+dojo.require('openils.widget.OrgUnitFilteringSelect');
+dojo.require('openils.PermaCrud');
+
+var svCache = {};
+var surveyMap;
+var svId;
+var questionId;
+
+
+/** really need to put this in a shared location... */
+function getOrgInfo(rowIndex, item) {
+ if(!item) return '';
+ var orgId = this.grid.store.getValue(item, this.field);
+ return fieldmapper.aou.findOrgUnit(orgId).shortname();
+}
+
+function getDateTimeField(rowIndex, item) {
+ if(!item) return '';
+ var data = this.grid.store.getValue(item, this.field);
+ var date = dojo.date.stamp.fromISOString(data);
+ return dojo.date.locale.format(date, {formatLength:'short'});
+}
+
+function formatBool(inDatum) {
+ switch (inDatum) {
+ case 't':
+ return "<span style='color:green;'>✓</span>";
+ case 'f':
+ return "<span style='color:red;'>✗</span>";
+ default:
+ return'';
+ }
+}
+
+function endSurvey() {
+ _endSurvey(svGrid.selection.getSelected(), 0);
+}
+
+function _endSurvey(list, idx) {
+ if(idx >= list.length) // we've made it through the list
+ return;
+
+ var item = list[idx];
+ var svId = svGrid.store.getValue(item, 'id');
+ var pcrud = new openils.PermaCrud();
+ var survey = pcrud.retrieve('asv', svId);
+ console.log(survey);
+ var today = new Date();
+ var date = dojo.date.stamp.toISOString(today);
+ survey.end_date(date);
+ survey.ischanged(true);
+ pcrud.update(survey);
+ _endSurvey(list, ++idx);
+
+}
+
+function buildSVGrid() {
+ var store = new dojo.data.ItemFileWriteStore({data:asv.initStoreData('id', {identifier:'id'})});
+ svGrid.setStore(store);
+ svGrid.render();
+ var user = new openils.User();
+ var pcrud = new openils.PermaCrud();
+ var retrieveSurveys = function(orgList) {
+ pcrud.search('asv',
+ {owner : orgList},
+ {
+ async : true,
+ streaming : true,
+ onresponse : function(r) {
+ var survey = openils.Util.readResponse(r);
+ if(!survey) return'';
+ svCache[survey.id()] = survey;
+ store.newItem(survey.toStoreItem());
+ }
+ }
+ );
+ }
+ user.getPermOrgList('ADMIN_SURVEY', retrieveSurveys, true, true);
+
+}
+
+function svPage() {
+ var pcrud = new openils.PermaCrud();
+ var survey = pcrud.retrieve('asv', surveyId);
+ dojo.byId("name").innerHTML = survey.name();
+ dojo.byId("description").innerHTML = survey.description();
+ dojo.byId("start_date").innerHTML = survey.start_date();
+ dojo.byId("end_date").innerHTML = survey.end_date();
+ dojo.byId("opac").innerHTML = survey.opac();
+ dojo.byId("poll").innerHTML = survey.poll();
+ dojo.byId("required").innerHTML = survey.required();
+ dojo.byId("usr_summary").innerHTML = survey.usr_summary();
+ dojo.byId("svQuestion").innerHTML = survey.question();
+ dojo.byId("svAnswer").innerHTML = survey.answer();
+
+}
+
+function svNewSurvey() {
+ new openils.User().buildPermOrgSelector('ADMIN_SURVEY', asvOwningOrg);
+ svSurveyDialog.show();
+
+}
+
+function svCreate(args) {
+
+ var sv = new asv();
+ sv.name(args.svName);
+ sv.owner(args.svOwner);
+ sv.description(args.svDescription);
+ sv.start_date(args.svStart_date);
+ sv.end_date(args.svEnd_date);
+ if(args.svPoll == 'on')
+ sv.poll('t')
+ else
+ sv.poll('f');
+
+ if(args.svPoll == 'on')
+ sv.poll('t')
+ else
+ sv.poll('f');
+
+ if(args.svOpac == 'on')
+ sv.opac('t')
+ else
+ sv.opac('f');
+
+ if(args.svRequired == 'on')
+ sv.required('t')
+ else
+ sv.required('f');
+
+ if(args.svUsr_summary == 'on')
+ sv.usr_summary('t')
+ else
+ sv.usr_summary('f');
+ console.log(sv.name());
+ var pcrud = new openils.PermaCrud();
+ pcrud.create(sv,
+ {
+ oncomplete: function(r) {
+ var obj = openils.Util.readResponse(r);
+ if(!obj) return console.log('no obj');
+ svGrid.store.newItem(asv.toStoreItem(obj));
+ svSurveyDialog.hide();
+ svId = obj.id();
+ document.location.href = "/eg/conify/global/action/survey/edit/"+svId;
+ //redirect(svId);
+ }
+ }
+ );
+}
+
+function redirect(svId) {
+
+}
+
+
+function deleteFromGrid() {
+ _deleteFromGrid(svGrid.selection.getSelected(), 0);
+}
+
+function _deleteFromGrid(list, idx) {
+ if(idx >= list.length) // we've made it through the list
+ return;
+
+ var item = list[idx];
+ var code = svGrid.store.getValue(item, 'id');
+
+ fieldmapper.standardRequest(
+ ['open-ils.circ', 'open-ils.circ.survey.delete.cascade'],
+ { async: true,
+ streaming: true,
+ params: [openils.User.authtoken, code],
+ onresponse: function(r) {
+ if(stat = openils.Util.readResponse(r)) {
+ console.log(stat);
+ svGrid.store.deleteItem(item);
+ // buildSVGrid();
+ }
+ _deleteFromGrid(list, ++idx);
+
+ }
+ }
+ );
+}
+openils.Util.addOnLoad(buildSVGrid);
+
+
Added: trunk/Open-ILS/web/templates/default/conify/global/action/survey/edit.tt2
===================================================================
--- trunk/Open-ILS/web/templates/default/conify/global/action/survey/edit.tt2 (rev 0)
+++ trunk/Open-ILS/web/templates/default/conify/global/action/survey/edit.tt2 2009-02-26 16:06:29 UTC (rev 12308)
@@ -0,0 +1,20 @@
+[% WRAPPER 'default/base.tt2' %]
+<script src='[% ctx.media_prefix %]/js/ui/default/conify/global/action/survey/edit.js'></script>
+
+<script type="text/javascript">
+ dojo.require('openils.Util');
+ var surveyId = [%ctx.page_args.0 %];
+ openils.Util.addOnLoad(function() { drawSurvey(surveyId) });
+
+</script>
+<!-- General survey info -->
+<div dojoType="dijit.layout.ContentPane" layoutAlign="client">
+ <div id='edit-pane'> </div>
+
+</div>
+
+<!-- question/answer table-->
+<table id='survey_table'>
+</table>
+
+[% END %]
Added: trunk/Open-ILS/web/templates/default/conify/global/action/survey.tt2
===================================================================
--- trunk/Open-ILS/web/templates/default/conify/global/action/survey.tt2 (rev 0)
+++ trunk/Open-ILS/web/templates/default/conify/global/action/survey.tt2 2009-02-26 16:06:29 UTC (rev 12308)
@@ -0,0 +1,99 @@
+[% WRAPPER default/base.tt2 %]
+<script src='[% ctx.media_prefix %]/js/ui/default/conify/global/action/survey.js'> </script>
+<h1>Survey List</h1><br/>
+
+<script>
+ function formatName(inDatum) {
+ for(var i in svCache){
+ var sv = svCache[i];
+ var id = sv.id();
+ if (inDatum == sv.name()){
+ return '<a href="[% ctx.base_uri %]/conify/global/action/survey/edit/'+id+'">'+inDatum+'</a>';
+ }
+ }
+ }
+</script>
+
+<button dojoType='dijit.form.Button' onclick='svNewSurvey();'>Add New Survey</button>
+<button dojoType='dijit.form.Button' onclick='deleteFromGrid();'>Delete Selected</button>
+<button dojoType='dijit.form.Button' onclick='endSurvey();'>End Selected Surveys</button>
+<script>dojo.require('openils.widget.GridColumnPicker');</script>
+
+<!-- column picker menu-->
+<div dojoType="openils.widget.GridColumnPicker" jsid="svGridMenu" id="svGridMenu" style="display: none;" grid='svGrid'>
+ <div dojoType="dojox.widget.PlaceholderMenuItem" label="GridColumns"></div>
+</div>
+<!-- grid -->
+<div dojoType="dijit.layout.ContentPane" layoutAlign="client" style='height:600px;'>
+ <table jsId="svGrid" dojoType="dojox.grid.DataGrid" query="{id: '*'}"
+ rowSelector='20px' columnReordering='true' headerMenu="svGridMenu">
+ <thead>
+ <tr>
+ <th field="id">Survey ID</th>
+ <th field="name" formatter='formatName' width='auto'>Name</th>
+ <th field="description" width='auto'>Description</th>
+ <th field="owner" get='getOrgInfo'>Owning Library</th>
+ <th field="start_date" width='auto' get='getDateTimeField'>Survey Start Date</th>
+ <th field="end_date" width='auto' get='getDateTimeField'>End Date</th>
+ <th field="opac" formatter='formatBool'>OPAC Survey?</th>
+ <th field="poll" formatter='formatBool' >Poll Style?</th>
+ <th field="required" formatter='formatBool'>Is Required?</th>
+ <th field="usr_summary" formatter='formatBool'>Display in User Summary?</th>
+ </tr>
+ </thead>
+ </table>
+</div>
+
+<div style='display:none;' dojoType="dijit.Dialog" jsId='svSurveyDialog' title='New Survey' execute='svCreate(arguments[0]);'>
+
+ <table id='surveyDialog'>
+ <tr>
+ <td>Name</td>
+ <td><input dojoType='dijit.form.TextBox' name='svName'/></td>
+ </tr>
+ <tr>
+ <td>Description</td>
+ <td><input dojoType='dijit.form.TextBox' name='svDescription'></td>
+ </tr>
+ <tr>
+ <td>Owning Library</td>
+ <td><select dojoType='openils.widget.OrgUnitFilteringSelect' name='svOwner' jsId='asvOwningOrg' searchAttr='shortname' labelAttr='shortname'/></td>
+ </tr>
+ <tr>
+ <td>Start Date</td>
+ <td><input dojoType='dijit.form.TextBox' name='svStart_date'></td>
+ </tr>
+ <tr>
+ <td>End Date</td>
+ <td><input dojoType='dijit.form.TextBox' name='svEnd_date'></td>
+ </tr>
+ <tr>
+ <td>OPAC Survey?</td>
+ <td><input dojoType='dijit.form.CheckBox' name='svOpac'></td>
+ </tr>
+ <tr>
+ <td>Poll Style?</td>
+ <td><input dojoType='dijit.form.CheckBox' name='svPoll'></td>
+ </tr>
+ <tr>
+ <td>Is Required?</td>
+ <td><input dojoType='dijit.form.CheckBox' name='svRequired'></td>
+ </tr>
+ <tr>
+ <td>Display in User Summary?</td>
+ <td><input dojoType='dijit.form.CheckBox' name='svUsr_summary'></td>
+ </tr>
+ <tr>
+ <td colspan='2' align='center'>
+ <button jsId='createSave' dojoType='dijit.form.Button' type='submit'>Save Changes</button>
+
+
+ </td>
+ </tr>
+
+ </table>
+</div>
+
+[% END %]
+
+
More information about the open-ils-commits
mailing list