<commit_before>// vim: ts=4:sw=4
/*global Ext */
/*global Curriki */
/*global _ */

// Some variables need to be defined before this script is loaded
//
// Set location the dialogue is being used (MyCurriki or Groups)
// Curriki.data.reorder.place = {'users', 'groups'}
//
// Set user or group to be used
// Curriki.data.reorder.which = {'XWiki.user', 'Group_spacename'}
//
// Set variable to state if a reorder has already been done
// Curriki.data.reorder.reordered = {true, false}

(function(){
Ext.ns('Curriki.module.reorder');
Ext.ns('Curriki.data.reorder');

var Reorder = Curriki.module.reorder;
var Data = Curriki.data.reorder;
var UI = Curriki.ui;

// Set message prefix depending on where the dialogue is being displayed
var msgPfx = 'mycurriki.collections.reorder.';
if (Data.place && Data.place === 'groups'){
	msgPfx = 'groups_curriculum_collections_reorder.';
}

Reorder.init = function(){
	if (!Data.place || !Data.which) {
		// Required values not passed
		return false;
	}
/*
	Reorder.store = new Ext.data.SimpleStore({
		fields: ['id', 'title']
		,data:[['1', 'one'], ['2', 'two'], ['3', 'three'], ['4', 'four']]
		,id: 0
	});
*/
	Reorder.store = new Ext.data.JsonStore({
		storeId:'CollectionsStore'
		,url: '/xwiki/curriki/'+Data.place+'/'+Data.which+'/collections'
		,fields: ['displayTitle', 'collectionPage']
		,autoLoad:true
	});

	Reorder.mainDlg = Ext.extend(UI.dialog.Messages, {
		  initComponent:function(){

			Ext.apply(this, {
				 id:'ReorderDialogueWindow'
				,title:_(msgPfx+'dialog_title')
				,cls:'reorder resource'
				,autoScroll:false
				,width:634
				,items:[{
					 xtype:'panel'
					,id:'guidingquestion-container'
					,cls:'guidingquestion-container'
					,items:[{
						 xtype:'box'
						,autoEl:{
							 tag:'div'
							,html:_(msgPfx+'guidingquestion')
							,cls:'guidingquestion'
						}
					},{
						 xtype:'box'
						,autoEl:{
							 tag:'div'
							,html:_(msgPfx+'instruction')
							,cls:'instruction'
						}
					}]
				},{
					 xtype:'panel'
					,id:'collections-list-panel'
					,cls:'collections-list'
					,bbar:['->',{
						 text:_(msgPfx+'cancel.btt')
						,id:'cancelbutton'
						,cls:'button cancel'
						,listeners:{
							click:{
								 fn: function(){
									this.close();
								}
								,scope:this
							}
						}
					},{
						 text:_(msgPfx+'next.btt')
						,id:'nextbutton'
						,cls:'button next'
						,listeners:{
							click:{
								 fn: function(){
								 	var list = [];
									Ext.getCmp('reorderCollectionsMS').store.each(function(rec){list.push(rec.data.collectionPage);});
									console.log('Reordering', list);
									//TODO: Send request to server
									//TODO: Have callback to tell user results

									Reorder.msgComplete();
									//TODO: Refresh the page
									window.location.reload();
								 }
								,scope:this
							}
						}
					}]
					,items:[{
						 xtype:'box'
						,autoEl:{
							 tag:'div'
							,html:_(msgPfx+'listheader')
							,cls:'listheader'
						}
					},{
						 xtype:'form'
						,id:'ReorderDialoguePanel'
						,formId:'ReorderDialogueForm'
						,labelWidth:25
						,autoScroll:false
						,border:false
						,defaults:{
							 labelSeparator:''
						}
						,listeners:{
						}
						,items:[{
								 xtype:'multiselect'
								,id:'reorderCollectionsMS'
								,name:'reorderCollections'
								,hideLabel:true
								,border:false
								,enableToolbar:false
								//,legend:_('sri.instructional_component2_title')
								,legend:' '
								,store:Reorder.store
								,valueField:'collectionPage'
								,displayField:'[""]}<span class="resource-CollectionComposite"><img style="width:16px; height:13px;" class="x-tree-node-icon assettype-icon" src="'+Ext.BLANK_IMAGE_URL+'" /></span> {displayTitle'
								,width:600
								,height:200
								,allowBlank:false
								,preventMark:true
								,minLength:1
								,isFormField:true

								,dragGroup:'reorderMSGroup'
								,dropGroup:'reorderMSGroup'
						}]
					}]
				}]
			});
			Reorder.mainDlg.superclass.initComponent.call(this);
		}
	});
	Ext.reg('reorderDialog', Reorder.mainDlg);

	Reorder.msgComplete = function(){
		alert(_(msgPfx+'set.confirm'));
	};

	Reorder.initialized = true;

	return true;
};

Reorder.confirmMsg = {
	first:function(){
		return confirm(msgPfx+'checkfirst.dialog');
	}

	,after:function(){
		return confirm(msgPfx+'checkafter.dialog');
	}

	,display:function(){
		if (!Data.reordered) {
			return Reorder.confirmMsg['first']();
		} else {
			return Reorder.confirmMsg['after']();
		}
	}
};

Reorder.display = function(){
	Ext.QuickTips.init();

	if (Reorder.init()) {
		UI.show('reorderDialog');
	}
};

Reorder.start = function(){
	Ext.onReady(function(){
		if (Reorder.confirmMsg.display()) {
			Reorder.display();
		}
	});
};
<commit_msg>- CURRIKI-2712  - Log pageviews for analytics<commit_after>// vim: ts=4:sw=4
/*global Ext */
/*global Curriki */
/*global _ */

// Some variables need to be defined before this script is loaded
//
// Set location the dialogue is being used (MyCurriki or Groups)
// Curriki.data.reorder.place = {'users', 'groups'}
//
// Set user or group to be used
// Curriki.data.reorder.which = {'XWiki.user', 'Group_spacename'}
//
// Set variable to state if a reorder has already been done
// Curriki.data.reorder.reordered = {true, false}

(function(){
Ext.ns('Curriki.module.reorder');
Ext.ns('Curriki.data.reorder');

var Reorder = Curriki.module.reorder;
var Data = Curriki.data.reorder;
var UI = Curriki.ui;

// Set message prefix depending on where the dialogue is being displayed
var msgPfx = 'mycurriki.collections.reorder.';
if (Data.place && Data.place === 'groups'){
	msgPfx = 'groups_curriculum_collections_reorder.';
}

Reorder.init = function(){
	if (!Data.place || !Data.which) {
		// Required values not passed
		return false;
	}
/*
	Reorder.store = new Ext.data.SimpleStore({
		fields: ['id', 'title']
		,data:[['1', 'one'], ['2', 'two'], ['3', 'three'], ['4', 'four']]
		,id: 0
	});
*/
	Reorder.store = new Ext.data.JsonStore({
		storeId:'CollectionsStore'
		,url: '/xwiki/curriki/'+Data.place+'/'+Data.which+'/collections'
		,fields: ['displayTitle', 'collectionPage']
		,autoLoad:true
	});

	Reorder.mainDlg = Ext.extend(UI.dialog.Messages, {
		  initComponent:function(){

			Ext.apply(this, {
				 id:'ReorderDialogueWindow'
				,title:_(msgPfx+'dialog_title')
				,cls:'reorder resource'
				,autoScroll:false
				,width:634
				,items:[{
					 xtype:'panel'
					,id:'guidingquestion-container'
					,cls:'guidingquestion-container'
					,items:[{
						 xtype:'box'
						,autoEl:{
							 tag:'div'
							,html:_(msgPfx+'guidingquestion')
							,cls:'guidingquestion'
						}
					},{
						 xtype:'box'
						,autoEl:{
							 tag:'div'
							,html:_(msgPfx+'instruction')
							,cls:'instruction'
						}
					}]
				},{
					 xtype:'panel'
					,id:'collections-list-panel'
					,cls:'collections-list'
					,bbar:['->',{
						 text:_(msgPfx+'cancel.btt')
						,id:'cancelbutton'
						,cls:'button cancel'
						,listeners:{
							click:{
								 fn: function(){
									this.close();
								}
								,scope:this
							}
						}
					},{
						 text:_(msgPfx+'next.btt')
						,id:'nextbutton'
						,cls:'button next'
						,listeners:{
							click:{
								 fn: function(){
								 	var list = [];
									Ext.getCmp('reorderCollectionsMS').store.each(function(rec){list.push(rec.data.collectionPage);});
									console.log('Reordering', list);
									//TODO: Send request to server
									//TODO: Have callback to tell user results

									Reorder.msgComplete();
									//TODO: Refresh the page
									window.location.reload();
								 }
								,scope:this
							}
						}
					}]
					,items:[{
						 xtype:'box'
						,autoEl:{
							 tag:'div'
							,html:_(msgPfx+'listheader')
							,cls:'listheader'
						}
					},{
						 xtype:'form'
						,id:'ReorderDialoguePanel'
						,formId:'ReorderDialogueForm'
						,labelWidth:25
						,autoScroll:false
						,border:false
						,defaults:{
							 labelSeparator:''
						}
						,listeners:{
						}
						,items:[{
								 xtype:'multiselect'
								,id:'reorderCollectionsMS'
								,name:'reorderCollections'
								,hideLabel:true
								,border:false
								,enableToolbar:false
								//,legend:_('sri.instructional_component2_title')
								,legend:' '
								,store:Reorder.store
								,valueField:'collectionPage'
								,displayField:'[""]}<span class="resource-CollectionComposite"><img style="width:16px; height:13px;" class="x-tree-node-icon assettype-icon" src="'+Ext.BLANK_IMAGE_URL+'" /></span> {displayTitle'
								,width:600
								,height:200
								,allowBlank:false
								,preventMark:true
								,minLength:1
								,isFormField:true

								,dragGroup:'reorderMSGroup'
								,dropGroup:'reorderMSGroup'
						}]
					}]
				}]
			});
			Reorder.mainDlg.superclass.initComponent.call(this);
		}
	});
	Ext.reg('reorderDialog', Reorder.mainDlg);

	Reorder.msgComplete = function(){
		Curriki.logView('/features/reorder/'+(Data.place==='groups'?'groups':'mycurriki')+'/saved');
		alert(_(msgPfx+'set.confirm'));
	};

	Reorder.initialized = true;

	return true;
};

Reorder.confirmMsg = {
	first:function(){
		return confirm(msgPfx+'checkfirst.dialog');
	}

	,after:function(){
		return confirm(msgPfx+'checkafter.dialog');
	}

	,display:function(){
		if (!Data.reordered) {
			return Reorder.confirmMsg['first']();
		} else {
			return Reorder.confirmMsg['after']();
		}
	}
};

Reorder.display = function(){
	Ext.QuickTips.init();

	if (Reorder.init()) {
		UI.show('reorderDialog');
		Curriki.logView('/features/reorder/'+(Data.place==='groups'?'groups':'mycurriki')+'/started');
	}
};

Reorder.start = function(){
	Ext.onReady(function(){
		if (Reorder.confirmMsg.display()) {
			Reorder.display();
		}
	});
};

{'fraction_non_alphanumeric': 0.17067016552280986, 'fraction_numerical': 0.005248284214775939, 'mean_word_length': 2.763387770603874, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7652240', 'n_tokens_mistral': 4609, 'n_tokens_neox': 3316, 'n_words': 559}