| 49 | | var nls = dojo.i18n.getLocalization("openils.widget", "TranslatorPopup"); |
| 50 | | this.localeLabelNode.textContent = nls.locale; |
| 51 | | this.translationLabelNode.textContent = nls.translation; |
| 52 | | this.translateLabelNode.setLabel(nls.translate); |
| 53 | | this.createButtonNode.textContent = nls.create; |
| 54 | | this.updateButtonNode.textContent = nls.update; |
| 55 | | this.removeButtonNode.textContent = nls.remove; |
| | 50 | |
| | 51 | dojo.connect(this.tooltipDialog, 'onOpen', this, 'renderTranslatorPopup'); |
| | 52 | |
| | 53 | this.nls = dojo.i18n.getLocalization("openils.widget", "TranslatorPopup"); |
| | 54 | |
| | 55 | this.translateLabelNode.setLabel(this.nls.translate); |
| | 56 | |
| | 57 | this.localeLabelNode.textContent = this.nls.locale; |
| | 58 | this.translationLabelNode.textContent = this.nls.translation; |
| | 59 | |
| | 60 | this.createButtonNode.textContent = this.nls.create; |
| | 61 | this.updateButtonNode.textContent = this.nls.update; |
| | 62 | this.removeButtonNode.textContent = this.nls.remove; |
| | 63 | }, |
| | 64 | |
| | 65 | renderTranslatorPopup : function () { |
| | 66 | |
| | 67 | this._targetObject = dojox.jsonPath.query(window, '$.' + this.targetObject, {evalType:"RESULT"}); |
| | 68 | |
| | 69 | var node = dojo.byId(this.field + '_translation_' + this.unique); |
| | 70 | |
| | 71 | var trans_list = openils.I18N.getTranslations( this._targetObject, this.field ); |
| | 72 | |
| | 73 | var trans_template = dojo.query('.translation_tbody_template', node)[0]; |
| | 74 | var trans_tbody = dojo.query('.translation_tbody', node)[0]; |
| | 75 | |
| | 76 | // Empty it |
| | 77 | while (trans_tbody.lastChild) trans_tbody.removeChild( trans_tbody.lastChild ); |
| | 78 | |
| | 79 | for (var i in trans_list) { |
| | 80 | if (!trans_list[i]) continue; |
| | 81 | |
| | 82 | var trans_obj = trans_list[i]; |
| | 83 | var trans_id = trans_obj.id(); |
| | 84 | |
| | 85 | var trans_row = dojo.query('tr',trans_template)[0].cloneNode(true); |
| | 86 | trans_row.id = 'translation_row_' + trans_id; |
| | 87 | |
| | 88 | var old_dijit = dijit.byId('locale_' + trans_id); |
| | 89 | if (old_dijit) old_dijit.destroy(); |
| | 90 | |
| | 91 | old_dijit = dijit.byId('translation_' + trans_id); |
| | 92 | if (old_dijit) old_dijit.destroy(); |
| | 93 | |
| | 94 | dojo.query('.locale_combobox',trans_row).instantiate( |
| | 95 | dijit.form.ComboBox, |
| | 96 | { store:openils.I18N.localeStore, |
| | 97 | searchAttr:'locale', |
| | 98 | lowercase:true, |
| | 99 | required:true, |
| | 100 | id:'locale_' + trans_id, |
| | 101 | value: trans_obj.translation(), |
| | 102 | invalidMessage:'Specify locale as {languageCode}_{countryCode}, like en_us', |
| | 103 | regExp:'[a-z_]+' |
| | 104 | } |
| | 105 | ); |
| | 106 | |
| | 107 | dojo.query('.translation_textbox',trans_row).instantiate( |
| | 108 | dijit.form.TextBox, |
| | 109 | { required : true, |
| | 110 | id:'translation_' + trans_id, |
| | 111 | value: trans_obj.string() |
| | 112 | } |
| | 113 | ); |
| | 114 | |
| | 115 | dojo.query('.update_button',trans_row).style({ visibility : 'visible', display : 'inline'}).instantiate( |
| | 116 | dijit.form.Button, |
| | 117 | { onClick : dojo.hitch( this, 'updateTranslation') } |
| | 118 | ); |
| | 119 | |
| | 120 | dojo.query('.delete_button',trans_row).style({ visibility : 'visible', display : 'inline'}).instantiate( |
| | 121 | dijit.form.Button, |
| | 122 | { onClick : dojo.hitch( this, 'removeTranslation') } |
| | 123 | ); |
| | 124 | |
| | 125 | trans_tbody.appendChild( trans_row ); |
| | 126 | |
| | 127 | } |
| | 128 | |
| | 129 | old_dijit = dijit.byId('i18n_new_locale_' + this._targetObject.classname + '.' + this.field + this.unique); |
| | 130 | if (old_dijit) old_dijit.destroy(); |
| | 131 | |
| | 132 | old_dijit = dijit.byId('i18n_new_translation_' + this._targetObject.classname + '.' + this.field + this.unique); |
| | 133 | if (old_dijit) old_dijit.destroy(); |
| | 134 | |
| | 135 | trans_row = dojo.query('tr',trans_template)[0].cloneNode(true); |
| | 136 | |
| | 137 | dojo.query('.locale_combobox',trans_row).instantiate( |
| | 138 | dijit.form.ComboBox, |
| | 139 | { store:openils.I18N.localeStore, |
| | 140 | searchAttr:'locale', |
| | 141 | id:'i18n_new_locale_' + this._targetObject.classname + '.' + this.field + this.unique, |
| | 142 | lowercase:true, |
| | 143 | required:true, |
| | 144 | invalidMessage:'Specify locale as {languageCode}_{countryCode}, like en_us', |
| | 145 | regExp:'[a-z_]+' |
| | 146 | } |
| | 147 | ); |
| | 148 | |
| | 149 | dojo.query('.translation_textbox',trans_row).addClass('new_translation').instantiate( |
| | 150 | dijit.form.TextBox, |
| | 151 | { required : true, |
| | 152 | id:'i18n_new_translation_' + this._targetObject.classname + '.' + this.field + this.unique |
| | 153 | } |
| | 154 | ); |
| | 155 | |
| | 156 | dojo.query('.create_button',trans_row).style({ visibility : 'visible', display : 'inline'}).instantiate( |
| | 157 | dijit.form.Button, |
| | 158 | { onClick : dojo.hitch( this, 'createTranslation') } |
| | 159 | ); |
| | 160 | |
| | 161 | trans_tbody.appendChild( trans_row ); |
| | 162 | |
| | 163 | }, |
| | 164 | |
| | 165 | updateTranslation : function (t) { |
| | 166 | return this.changeTranslation('update',t); |
| | 167 | }, |
| | 168 | |
| | 169 | removeTranslation : function (t) { |
| | 170 | return changeTranslation('delete',t); |
| | 171 | }, |
| | 172 | |
| | 173 | changeTranslation : function (method, trans_id) { |
| | 174 | |
| | 175 | var trans_obj = new i18n().fromHash({ |
| | 176 | ischanged : method == 'update' ? 1 : 0, |
| | 177 | isdeleted : method == 'delete' ? 1 : 0, |
| | 178 | id : trans_id, |
| | 179 | fq_field : this._targetObject.classname + '.' + this.field, |
| | 180 | identity_value : this._targetObject.id(), |
| | 181 | translation : dijit.byId('locale_' + trans_id).getValue(), |
| | 182 | string : dijit.byId('translation_' + trans_id).getValue() |
| | 183 | }); |
| | 184 | |
| | 185 | this.writeTranslation(method, trans_obj); |
| | 186 | }, |
| | 187 | |
| | 188 | createTranslation : function () { |
| | 189 | var node = dojo.byId(this.field + '_translation_' + this.unique); |
| | 190 | |
| | 191 | var trans_obj = new i18n().fromHash({ |
| | 192 | isnew : 1, |
| | 193 | fq_field : this._targetObject.classname + '.' + this.field, |
| | 194 | identity_value : this._targetObject.id(), |
| | 195 | translation : dijit.byId('i18n_new_locale_' + this._targetObject.classname + '.' + this.field + this.unique).getValue(), |
| | 196 | string : dijit.byId('i18n_new_translation_' + this._targetObject.classname + '.' + this.field + this.unique).getValue() |
| | 197 | }); |
| | 198 | |
| | 199 | this.writeTranslation('create', trans_obj); |
| | 200 | }, |
| | 201 | |
| | 202 | writeTranslation : function (method, trans_obj) { |
| | 203 | |
| | 204 | OpenSRF.CachedClientSession('open-ils.permacrud').request({ |
| | 205 | method : 'open-ils.permacrud.' + method + '.i18n', |
| | 206 | timeout: 10, |
| | 207 | params : [ ses, trans_obj ], |
| | 208 | onerror: function (r) { |
| | 209 | //highlighter.editor_pane.red.play(); |
| | 210 | if (status_update) status_update( 'Problem saving translation for ' + this._targetObject[this.field]() ); |
| | 211 | }, |
| | 212 | oncomplete : function (r) { |
| | 213 | var res = r.recv(); |
| | 214 | if ( res && res.content() ) { |
| | 215 | //highlighter.editor_pane.green.play(); |
| | 216 | if (status_update) status_update( 'Saved changes to translation for ' + this._targetObject[this.field]() ); |
| | 217 | |
| | 218 | if (method == 'delete') { |
| | 219 | dojo.NodeList(dojo.byId('translation_row_' + trans_obj.id())).orphan(); |
| | 220 | } else if (method == 'create') { |
| | 221 | var node = dojo.byId(this.field + '_translation_' + this.unique); |
| | 222 | dijit.byId('i18n_new_locale_' + this._targetObject.classname + '.' + this.field + this.unique).setValue(null); |
| | 223 | dijit.byId('i18n_new_translation_' + this._targetObject.classname + '.' + this.field + this.unique).setValue(null); |
| | 224 | this.renderTranslatorPopup(); |
| | 225 | } |
| | 226 | |
| | 227 | } else { |
| | 228 | //highlighter.editor_pane.red.play(); |
| | 229 | if (status_update) status_update( 'Problem saving translation for ' + this._targetObject[this.field]() ); |
| | 230 | } |
| | 231 | }, |
| | 232 | }).send(); |
| 60 | | openils.widget.TranslatorPopup.renderTranslatorPopup = function (obj, field, num) { |
| 61 | | var node = dojo.byId(field + '_translation_' + num); |
| 62 | | |
| 63 | | var trans_list = openils.I18N.getTranslations( obj, field ); |
| 64 | | |
| 65 | | var trans_template = dojo.query('.translation_tbody_template', node)[0]; |
| 66 | | var trans_tbody = dojo.query('.translation_tbody', node)[0]; |
| 67 | | |
| 68 | | // Empty it |
| 69 | | while (trans_tbody.lastChild) trans_tbody.removeChild( trans_tbody.lastChild ); |
| 70 | | |
| 71 | | for (var i in trans_list) { |
| 72 | | if (!trans_list[i]) continue; |
| 73 | | |
| 74 | | var trans_obj = trans_list[i]; |
| 75 | | var trans_id = trans_obj.id(); |
| 76 | | |
| 77 | | var trans_row = dojo.query('tr',trans_template)[0].cloneNode(true); |
| 78 | | trans_row.id = 'translation_row_' + trans_id; |
| 79 | | |
| 80 | | var old_dijit = dijit.byId('locale_' + trans_id); |
| 81 | | if (old_dijit) old_dijit.destroy(); |
| 82 | | |
| 83 | | old_dijit = dijit.byId('translation_' + trans_id); |
| 84 | | if (old_dijit) old_dijit.destroy(); |
| 85 | | |
| 86 | | dojo.query('.locale_combobox',trans_row).instantiate( |
| 87 | | dijit.form.ComboBox, |
| 88 | | { store:openils.I18N.localeStore, |
| 89 | | searchAttr:'locale', |
| 90 | | lowercase:true, |
| 91 | | required:true, |
| 92 | | id:'locale_' + trans_id, |
| 93 | | value: trans_obj.translation(), |
| 94 | | invalidMessage:'Specify locale as {languageCode}_{countryCode}, like en_us', |
| 95 | | regExp:'[a-z_]+' |
| 96 | | } |
| 97 | | ); |
| 98 | | |
| 99 | | dojo.query('.translation_textbox',trans_row).instantiate( |
| 100 | | dijit.form.TextBox, |
| 101 | | { required : true, |
| 102 | | id:'translation_' + trans_id, |
| 103 | | value: trans_obj.string() |
| 104 | | } |
| 105 | | ); |
| 106 | | |
| 107 | | dojo.query('.update_button',trans_row).style({ visibility : 'visible', display : 'inline'}).instantiate( |
| 108 | | dijit.form.Button, |
| 109 | | { onClick : |
| 110 | | (function (trans_id, obj, field) { |
| 111 | | return function () { openils.widget.TranslatorPopup.updateTranslation(trans_id, obj, field, num) } |
| 112 | | })(trans_id, obj, field) |
| 113 | | } |
| 114 | | ); |
| 115 | | |
| 116 | | dojo.query('.delete_button',trans_row).style({ visibility : 'visible', display : 'inline'}).instantiate( |
| 117 | | dijit.form.Button, |
| 118 | | { onClick : |
| 119 | | (function (trans_id, obj, field) { |
| 120 | | return function () { openils.widget.TranslatorPopup.removeTranslation(trans_id, obj, field, num) } |
| 121 | | })(trans_id, obj, field) |
| 122 | | } |
| 123 | | ); |
| 124 | | |
| 125 | | trans_tbody.appendChild( trans_row ); |
| 126 | | } |
| 127 | | |
| 128 | | old_dijit = dijit.byId('i18n_new_locale_' + obj.classname + '.' + field + num); |
| 129 | | if (old_dijit) old_dijit.destroy(); |
| 130 | | |
| 131 | | old_dijit = dijit.byId('i18n_new_translation_' + obj.classname + '.' + field + num); |
| 132 | | if (old_dijit) old_dijit.destroy(); |
| 133 | | |
| 134 | | trans_row = dojo.query('tr',trans_template)[0].cloneNode(true); |
| 135 | | |
| 136 | | dojo.query('.locale_combobox',trans_row).instantiate( |
| 137 | | dijit.form.ComboBox, |
| 138 | | { store:openils.I18N.localeStore, |
| 139 | | searchAttr:'locale', |
| 140 | | id:'i18n_new_locale_' + obj.classname + '.' + field + num, |
| 141 | | lowercase:true, |
| 142 | | required:true, |
| 143 | | invalidMessage:'Specify locale as {languageCode}_{countryCode}, like en_us', |
| 144 | | regExp:'[a-z_]+' |
| 145 | | } |
| 146 | | ); |
| 147 | | |
| 148 | | dojo.query('.translation_textbox',trans_row).addClass('new_translation').instantiate( |
| 149 | | dijit.form.TextBox, |
| 150 | | { required : true, |
| 151 | | id:'i18n_new_translation_' + obj.classname + '.' + field + num |
| 152 | | } |
| 153 | | ); |
| 154 | | |
| 155 | | dojo.query('.create_button',trans_row).style({ visibility : 'visible', display : 'inline'}).instantiate( |
| 156 | | dijit.form.Button, |
| 157 | | { onClick : function () { openils.widget.TranslatorPopup.createTranslation( obj, field, num) } } |
| 158 | | ); |
| 159 | | |
| 160 | | trans_tbody.appendChild( trans_row ); |
| 161 | | } |
| 162 | | |
| 163 | | openils.widget.TranslatorPopup.updateTranslation = function (trans_id, obj, field, num) { |
| 164 | | return openils.widget.TranslatorPopup.changeTranslation('update', trans_id, obj, field, num); |
| 165 | | } |
| 166 | | |
| 167 | | openils.widget.TranslatorPopup.removeTranslation = function (trans_id, obj, field, num) { |
| 168 | | return openils.widget.TranslatorPopup.changeTranslation('delete', trans_id, obj, field, num); |
| 169 | | } |
| 170 | | |
| 171 | | openils.widget.TranslatorPopup.changeTranslation = function (method, trans_id, obj, field, num) { |
| 172 | | |
| 173 | | var trans_obj = new i18n().fromHash({ |
| 174 | | ischanged : method == 'update' ? 1 : 0, |
| 175 | | isdeleted : method == 'delete' ? 1 : 0, |
| 176 | | id : trans_id, |
| 177 | | fq_field : obj.classname + '.' + field, |
| 178 | | identity_value : obj.id(), |
| 179 | | translation : dijit.byId('locale_' + trans_id).getValue(), |
| 180 | | string : dijit.byId('translation_' + trans_id).getValue() |
| 181 | | }); |
| 182 | | |
| 183 | | openils.widget.TranslatorPopup.writeTranslation(method, trans_obj, obj, field, num); |
| 184 | | } |
| 185 | | |
| 186 | | openils.widget.TranslatorPopup.createTranslation = function (obj, field, num) { |
| 187 | | var node = dojo.byId(field + '_translation_' + num); |
| 188 | | |
| 189 | | var trans_obj = new i18n().fromHash({ |
| 190 | | isnew : 1, |
| 191 | | fq_field : obj.classname + '.' + field, |
| 192 | | identity_value : obj.id(), |
| 193 | | translation : dijit.byId('i18n_new_locale_' + obj.classname + '.' + field + num).getValue(), |
| 194 | | string : dijit.byId('i18n_new_translation_' + obj.classname + '.' + field + num).getValue() |
| 195 | | }); |
| 196 | | |
| 197 | | openils.widget.TranslatorPopup.writeTranslation('create', trans_obj, obj, field, num); |
| 198 | | } |
| 199 | | |
| 200 | | openils.widget.TranslatorPopup.writeTranslation = function (method, trans_obj, obj, field, num) { |
| 201 | | |
| 202 | | OpenSRF.CachedClientSession('open-ils.permacrud').request({ |
| 203 | | method : 'open-ils.permacrud.' + method + '.i18n', |
| 204 | | timeout: 10, |
| 205 | | params : [ ses, trans_obj ], |
| 206 | | onerror: function (r) { |
| 207 | | //highlighter.editor_pane.red.play(); |
| 208 | | if (status_update) status_update( 'Problem saving translation for ' + obj[field]() ); |
| 209 | | }, |
| 210 | | oncomplete : function (r) { |
| 211 | | var res = r.recv(); |
| 212 | | if ( res && res.content() ) { |
| 213 | | //highlighter.editor_pane.green.play(); |
| 214 | | if (status_update) status_update( 'Saved changes to translation for ' + obj[field]() ); |
| 215 | | |
| 216 | | if (method == 'delete') { |
| 217 | | dojo.NodeList(dojo.byId('translation_row_' + trans_obj.id())).orphan(); |
| 218 | | } else if (method == 'create') { |
| 219 | | var node = dojo.byId(field + '_translation_' + num); |
| 220 | | dijit.byId('i18n_new_locale_' + obj.classname + '.' + field + num).setValue(null); |
| 221 | | dijit.byId('i18n_new_translation_' + obj.classname + '.' + field + num).setValue(null); |
| 222 | | openils.widget.TranslatorPopup.renderTranslatorPopup(obj, field, num); |
| 223 | | } |
| 224 | | |
| 225 | | } else { |
| 226 | | //highlighter.editor_pane.red.play(); |
| 227 | | if (status_update) status_update( 'Problem saving translation for ' + obj[field]() ); |
| 228 | | } |
| 229 | | }, |
| 230 | | }).send(); |
| 231 | | } |
| | 239 | openils.widget.TranslatorPopup._unique = 1; |
| | 240 | |
| | 241 | |